-
Notifications
You must be signed in to change notification settings - Fork 1
+poc,instruments PoC of an Instruments.app instrument "tracing" (naive) #97
Conversation
@@ -36,7 +36,7 @@ public protocol Span { | |||
var endTimestamp: Timestamp? { get } | |||
|
|||
/// The read-only `BaggageContext` of this `Span`, set when starting this `Span`. | |||
var baggage: BaggageContext { get } | |||
var context: BaggageContext { get } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO these should be context because span.context rather than span.baggage.
The baggage word is only to be used to disambiguate in cases like context.context so this isn't one of those cases IMO. (rules we arrived at https://github.com/slashmo/gsoc-swift-baggage-context#existing-context-argument )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requires major version bump ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project was never tagged so we're not even a 0.0.0, a major bump from nothing still is nothing 😉
// ==== ---------------------------------------------------------------------------------------------------------------- | ||
// MARK: OSSignpost Tracing | ||
|
||
@available(OSX 10.14, *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since signposts are only available since then.
(I may have gotten the availability wrong on other OSes)
import Instrumentation | ||
import Foundation // string conversion for os_log seems to live here | ||
|
||
#if os(macOS) || os(tvOS) || os(iOS) || os(watchOS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an apple platforms only thing
@available(watchOS 3.0, *) | ||
enum OSSignpostTracingKeys { | ||
enum TraceParentIDs: BaggageContextKey { | ||
typealias Value = [OSSignpostID] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not "really" used and I don't think there's a good way to make use of this info in instruments... though I may have to learn more about it. Not a huge goal of this PoC anyway.
<name>Konrad `ktoso` Malawski</name> | ||
</owner> | ||
|
||
<!-- Instruments Developer Help: https://help.apple.com/instruments/developer/mac/current/ --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see here for docs how this format works, and also WWDC sessions on custom instruments:
</os-signpost-interval-schema> | ||
|
||
<!-- MARK: Instrument Definitions --> | ||
<instrument> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a simple instrument that shows each span (grouped by operation name) as it's own row.
This is obviously would not scale all that well in reality, but it's good for the PoC.
Can this be merged, it's just another showcase -- wdyt @slashmo ? I'll rebase after review. |
I think this would be very useful with NIO channels, to see in Xcode when exactly - including the order- each job is run. |
public func startSpan( | ||
named operationName: String, | ||
context: BaggageContext, | ||
ofKind kind: SpanKind, | ||
at timestamp: Timestamp? | ||
) -> Span { | ||
OSSignpostSpan( | ||
log: self.log, | ||
named: operationName, | ||
signpostName: self.signpostName, | ||
context: context | ||
// , kind ignored | ||
// , timestamp ignored, we capture it automatically | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that some tracer may choose not to expose setting the timestamp explicitly by user.
this is the case with XRay tracer as well, at the moment (I dont really see a use case for that);
arguably its easier to change XRay tracer than OSSignpostSpan
;-)
BTW this is not required by OT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job with this. I just ran the Instrument and it looks very nice already 👍
...tsAppTracingInstrpkg/SpansExampleInstrument/SpansExampleInstrument.xcodeproj/project.pbxproj
Show resolved
Hide resolved
@ktoso Yep, sorry for the delay |
Thanks folks, just another fun example to include in the suite, merged then |
Since I had a moment over the holidays here I picked up a PoC i wanted to sanity check since a while.
Context: Since a few years Instruments allows for building custom instruments (yeah all the words are terribly overloaded here but I don't think we can do much about that to be honest). See session: https://developer.apple.com/wwdc18/410 Creating Custom Instruments - WWDC 2018
PoC / "Use Case" of using the tracing instruments API with signposts and collecting in instruments.
This is by no means super end to end perfect, but showcases somewhat the shape and how compatible (or not) the APIs are.
It's fairly okey, the fact that spans are classes means we can easily use them in signpost IDs which is good.
Some comments inline.
❗ THIS IS JUST A POC, NOT END GOAL OR "VERY REAL" TRACER ❗
Result: