@@ -21,26 +21,17 @@ import Darwin
21
21
@_exported import Instrumentation
22
22
@_exported import InstrumentationBaggage
23
23
24
- public protocol SwiftDistributedTracingDurationProtocol : Comparable , AdditiveArithmetic , Sendable {
25
- static func / ( _ lhs: Self , _ rhs: Int ) -> Self
26
- static func /= ( _ lhs: inout Self , _ rhs: Int )
27
- static func * ( _ lhs: Self , _ rhs: Int ) -> Self
28
- static func *= ( _ lhs: inout Self , _ rhs: Int )
29
-
30
- static func / ( _ lhs: Self , _ rhs: Self ) -> Double
31
- }
32
-
33
- extension SwiftDistributedTracingDurationProtocol {
34
- public static func /= ( _ lhs: inout Self , _ rhs: Int ) {
35
- lhs = lhs / rhs
36
- }
24
+ public protocol TracerInstantProtocol : Comparable , Hashable , Sendable {
25
+ /// Representation of this instant as the number of nanoseconds since UNIX Epoch (January 1st 1970)
26
+ var nanosecondsSinceEpoch : UInt64 { get }
37
27
}
38
28
39
- public protocol SwiftDistributedTracingInstantProtocol : Comparable , Hashable , Sendable { }
40
-
41
- public protocol TracerInstantProtocol : SwiftDistributedTracingInstantProtocol {
29
+ extension TracerInstantProtocol {
42
30
/// Representation of this instant as the number of milliseconds since UNIX Epoch (January 1st 1970)
43
- var millisecondsSinceEpoch : UInt64 { get }
31
+ @inlinable
32
+ public var millisecondsSinceEpoch : UInt64 {
33
+ self . nanosecondsSinceEpoch / 1_000_000
34
+ }
44
35
}
45
36
46
37
/// A specialized clock protocol for purposes of tracing.
@@ -69,23 +60,22 @@ public struct DefaultTracerClock: TracerClock {
69
60
}
70
61
71
62
public struct Timestamp : TracerInstantProtocol {
72
- /// Milliseconds since January 1st, 1970, also known as "unix epoch".
73
- public var millisecondsSinceEpoch : UInt64
63
+ public let nanosecondsSinceEpoch : UInt64
74
64
75
- internal init ( millisecondsSinceEpoch : UInt64 ) {
76
- self . millisecondsSinceEpoch = millisecondsSinceEpoch
65
+ public init ( nanosecondsSinceEpoch : UInt64 ) {
66
+ self . nanosecondsSinceEpoch = nanosecondsSinceEpoch
77
67
}
78
68
79
69
public static func < ( lhs: Instant , rhs: Instant ) -> Bool {
80
- lhs. millisecondsSinceEpoch < rhs. millisecondsSinceEpoch
70
+ lhs. nanosecondsSinceEpoch < rhs. nanosecondsSinceEpoch
81
71
}
82
72
83
73
public static func == ( lhs: Instant , rhs: Instant ) -> Bool {
84
- lhs. millisecondsSinceEpoch == rhs. millisecondsSinceEpoch
74
+ lhs. nanosecondsSinceEpoch == rhs. nanosecondsSinceEpoch
85
75
}
86
76
87
77
public func hash( into hasher: inout Hasher ) {
88
- self . millisecondsSinceEpoch . hash ( into: & hasher)
78
+ self . nanosecondsSinceEpoch . hash ( into: & hasher)
89
79
}
90
80
}
91
81
@@ -100,8 +90,7 @@ public struct DefaultTracerClock: TracerClock {
100
90
/// and the odds that this code will still be running 530 years from now is very, very low,
101
91
/// so as a practical matter this will never overflow.
102
92
let nowNanos = UInt64 ( ts. tv_sec) &* 1_000_000_000 &+ UInt64 ( ts. tv_nsec)
103
- let nowMillis = UInt64 ( nowNanos / 1_000_000 ) // nanos to millis
104
93
105
- return Instant ( millisecondsSinceEpoch : nowMillis )
94
+ return Instant ( nanosecondsSinceEpoch : nowNanos )
106
95
}
107
96
}
0 commit comments