Skip to content

Remove some unused/untested dead code #100

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

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions Sources/Tracing/TracingTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public protocol SwiftDistributedTracingInstantProtocol: Comparable, Hashable, Se

public protocol TracerInstantProtocol: SwiftDistributedTracingInstantProtocol {
/// Representation of this instant as the number of milliseconds since UNIX Epoch (January 1st 1970)
@inlinable
var millisecondsSinceEpoch: UInt64 { get }
}

Expand All @@ -64,7 +63,6 @@ public protocol TracerClock {
/// A basic "timestamp clock" implementation that is able to five the current time as an unix timestamp.
public struct DefaultTracerClock: TracerClock {
public typealias Instant = Timestamp
internal typealias TimeInterval = Double

public init() {
// empty
Expand Down Expand Up @@ -107,78 +105,3 @@ public struct DefaultTracerClock: TracerClock {
return Instant(millisecondsSinceEpoch: nowMillis)
}
}

#if swift(>=5.7.0)
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension Duration {
typealias Value = Int64

var nanoseconds: Value {
let (seconds, attoseconds) = self.components
let sNanos = seconds * Value(1_000_000_000)
let asNanos = attoseconds / Value(1_000_000_000)
let (totalNanos, overflow) = sNanos.addingReportingOverflow(asNanos)
return overflow ? .max : totalNanos
}

/// The microseconds representation of the `TimeAmount`.
var microseconds: Value {
self.nanoseconds / TimeUnit.microseconds.rawValue
}

/// The milliseconds representation of the `TimeAmount`.
var milliseconds: Value {
self.nanoseconds / TimeUnit.milliseconds.rawValue
}

/// The seconds representation of the `TimeAmount`.
var seconds: Value {
self.nanoseconds / TimeUnit.seconds.rawValue
}

var isEffectivelyInfinite: Bool {
self.nanoseconds == .max
}
}

@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
extension Duration {
private func chooseUnit(_ ns: Value) -> TimeUnit {
if ns / TimeUnit.seconds.rawValue > 0 {
return TimeUnit.seconds
} else if ns / TimeUnit.milliseconds.rawValue > 0 {
return TimeUnit.milliseconds
} else if ns / TimeUnit.microseconds.rawValue > 0 {
return TimeUnit.microseconds
} else {
return TimeUnit.nanoseconds
}
}

/// Represents number of nanoseconds within given time unit
enum TimeUnit: Value {
case seconds = 1_000_000_000
case milliseconds = 1_000_000
case microseconds = 1000
case nanoseconds = 1

var abbreviated: String {
switch self {
case .nanoseconds: return "ns"
case .microseconds: return "μs"
case .milliseconds: return "ms"
case .seconds: return "s"
}
}

func duration(_ duration: Int) -> Duration {
switch self {
case .nanoseconds: return .nanoseconds(Value(duration))
case .microseconds: return .microseconds(Value(duration))
case .milliseconds: return .milliseconds(Value(duration))
case .seconds: return .seconds(Value(duration))
}
}
}
}
#endif