Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Timer.measure methods #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add Timer.measure methods #140

wants to merge 1 commit into from

Conversation

FranzBusch
Copy link
Member

Motivation

This PR supersedes #135. The goal is to make it easier to measure asynchronous code when using Metrics.

Modification

This PR does:

  • Deprecate the current static method for measuring synchronous code
  • Add a new instance method to measure synchronous code
  • Add a new instance method to measure asynchronous code

@FranzBusch
Copy link
Member Author

@swift-server-bot test this please

@Lukasa
Copy link
Contributor

Lukasa commented Apr 22, 2024

@swift-server-bot add to allowlist

Copy link
Contributor

@gjcairo gjcairo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a nit about docs.

return try body()
}

/// Convenience for measuring duration of a closure with a provided clock.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the doc for this method and the non-async version don't match. Maybe remove the last bit to match that one, since we're defaulting the clock param anyways?

Suggested change
/// Convenience for measuring duration of a closure with a provided clock.
/// Convenience for measuring duration of a closure.

@FranzBusch
Copy link
Member Author

@swift-server-bot test this please

@FranzBusch FranzBusch enabled auto-merge (squash) May 9, 2024 09:57
@FranzBusch FranzBusch force-pushed the fb-timer-measure branch 2 times, most recently from b541236 to 8cc9d38 Compare March 8, 2025 11:27
# Motivation

This PR supersedes #135. The goal is to make it easier to measure asynchronous code when using `Metrics`.

# Modification

This PR does:
- Deprecate the current static method for measuring synchronous code
- Add a new instance method to measure synchronous code
- Add a new instance method to measure asynchronous code

# Result

It is now easier to measure asynchronous code.
@FranzBusch FranzBusch added the 🆕 semver/minor Adds new public API. label Mar 8, 2025
@FranzBusch FranzBusch disabled auto-merge March 8, 2025 11:46
@FranzBusch
Copy link
Member Author

@fabianfett @simonjbeaumont @czechboy0 I dusted off this PR again and brought up to the latest Swift standards. If you could take another look that would be great.

@@ -24,6 +24,9 @@ extension Timer {
/// - label: The label for the Timer.
/// - dimensions: The dimensions for the Timer.
/// - body: Closure to run & record.
#if compiler(>=6.0)
Copy link
Contributor

@czechboy0 czechboy0 Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we think it's okay to have a deprecation based on a compiler version? What's the experience for an adopter who supports the same 3 Swift versions as us, do they also have to provide two solutions?

Also, the new API has an OS requirement, so we should make sure we don't put any adopters into a situation where they can't fix this warning without bumping their OS requirement (which today requires a major bump).

/// - clock: The clock used for measuring the duration. Defaults to the continuous clock.
/// - body: The closure to record the duration of.
@inlinable
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the recommendation for adopters who aren't yet on these OS versions as deployment targets?

Should we consider offering a variant if this method without the bumped OS requirements, which use pre-Clock way to measure time, for packages with older OS deployment targets? Or do we just recommend they write their own?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants