Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ extension TimeAmount {
return "\(fullNS)ns"
}
}

/// Returns a human-readable string representation of the time amount,
/// automatically choosing the best unit (s, ms, µs) with decimal precision.
var formattedString: String {
let fullNS = self.nanoseconds
guard fullNS != 0 else {
return "0ns"
}

let nsAsDouble = Double(fullNS)

if fullNS >= 1_000_000_000 {
let seconds = nsAsDouble / 1_000_000_000.0
return String(format: "%.3fs", seconds)
} else if fullNS >= 1_000_000 {
let milliseconds = nsAsDouble / 1_000_000.0
return String(format: "%.0fms", milliseconds)
} else if fullNS >= 1_000 {
let microseconds = nsAsDouble / 1_000.0
return String(format: "%.0fus", microseconds)
} else {
return "\(fullNS)ns"
}
}
}

struct TimeAmountConversionError: Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ extension ProfileRecorderSampler {
}

logger.info("requesting raw samples")
let sampleStart = NIODeadline.now()
try await self.requestSamples(
outputFilePath: rawSamplesPath.string,
failIfFileExists: true,
count: sampleCount,
timeBetweenSamples: timeBetweenSamples
)
logger.info("raw samples complete")
let sampleDuration = NIODeadline.now() - sampleStart
logger.info("raw samples complete", metadata: ["duration": "\(sampleDuration.formattedString)"])
switch format {
case .perfSymbolized, .pprofSymbolized, .flamegraphCollapsedSymbolized:
let renderer: any ProfileRecorderSampleConversionOutputRenderer
Expand All @@ -85,13 +87,15 @@ extension ProfileRecorderSampler {
renderer: renderer,
symbolizer: symbolizer
)
let convertStart = NIODeadline.now()
try await converter.convert(
inputRawProfileRecorderFormatPath: rawSamplesPath.string,
outputPath: symbolisedSamplesPath.string,
format: .perfSymbolized,
logger: logger
)
logger.info("samples symbolicated")
let convertDuration = NIODeadline.now() - convertStart
logger.info("samples symbolicated", metadata: ["duration": "\(convertDuration.formattedString)"])
return try await body(symbolisedSamplesPath.string)
case .raw:
return try await body(rawSamplesPath.string)
Expand Down
Loading