withIntervalSignpost(_:id:around:)
Measures the execution of the specified closure.
Declaration
func withIntervalSignpost<T>(_ name: StaticString, id: OSSignpostID = .exclusive, around task: () throws -> T) rethrows -> TParameters
- name:
The signpost’s name.
- id:
The signpost’s ID. The default value is Exclusive.
- task:
The closure around which to create the signposted interval.
Discussion
The signposter uses a signpost ID to pair the beginning and the end of a signposted interval, which is necessary because multiple intervals with the same configuration and scope can be in-flight simultaneously. If only one interval with a specific configuration can execute at any particular time, pass exclusive as the id parameter. Otherwise, use the makeSignpostID() and makeSignpostID(from:) methods to generate a signpost identifier, as the following example shows:
// Create a signposter using the default subsystem.
let signposter = OSSignposter()
// Generate a signpost ID to associate with the signpost.
let signpostID = signposter.makeSignpostID()
// Signpost the interval of a closure that encapsulates
// one or more related tasks.
signposter.withIntervalSignpost("Example Signpost", id: signpostID) {
// Perform one or more related tasks.
}