Skip to content

Commit 447dfc2

Browse files
committed
RUM-8448 Add ios.benchmark.batch_count
1 parent f045452 commit 447dfc2

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

BenchmarkTests/Runner/BenchmarkMeter.swift

+12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ internal final class Meter: DatadogInternal.BenchmarkMeter {
6868
func gauge(metric: @autoclosure () -> String) -> DatadogInternal.BenchmarkGauge {
6969
meter.createDoubleMeasure(name: metric())
7070
}
71+
72+
func observe(metric: @autoclosure () -> String, callback: @escaping (any DatadogInternal.BenchmarkGauge) -> Void) {
73+
_ = meter.createDoubleObserver(name: metric()) { callback(DoubleObserverWrapper(observer: $0)) }
74+
}
7175
}
7276

7377
extension AnyCounterMetric<Double>: DatadogInternal.BenchmarkCounter {
@@ -81,3 +85,11 @@ extension AnyMeasureMetric<Double>: DatadogInternal.BenchmarkGauge {
8185
record(value: value, labelset: LabelSet(labels: attributes()))
8286
}
8387
}
88+
89+
private struct DoubleObserverWrapper: DatadogInternal.BenchmarkGauge {
90+
let observer: DoubleObserverMetric
91+
92+
func record(value: Double, attributes: @autoclosure () -> [String: String]) {
93+
observer.observe(value: value, labelset: LabelSet(labels: attributes()))
94+
}
95+
}

DatadogCore/Sources/Core/Storage/FilesOrchestrator.swift

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ internal class FilesOrchestrator: FilesOrchestratorType {
8080
self.dateProvider = dateProvider
8181
self.telemetry = telemetry
8282
self.metricsData = metricsData
83+
84+
#if DD_BENCHMARK
85+
bench.meter.observe(metric: "ios.benchmark.batch_count") {[weak self] gauge in
86+
if let self {
87+
let files = try? directory.files()
88+
files.map { gauge.record($0.count, attributes: ["track": self.trackName]) }
89+
}
90+
}
91+
#endif
8392
}
8493

8594
// MARK: - `WritableFile` orchestration

DatadogInternal/Sources/Benchmarks/BenchmarkProfiler.swift

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public protocol BenchmarkMeter {
5656
/// - Parameter metric: The metric name.
5757
/// - Returns: The gauge instance.
5858
func gauge(metric: @autoclosure () -> String) -> BenchmarkGauge
59+
60+
func observe(metric: @autoclosure () -> String, callback: @escaping (BenchmarkGauge) -> Void )
5961
}
6062

6163
/// The Benchmark Tracer will create and start spans in a benchmark environment.
@@ -137,6 +139,8 @@ private final class NOPBench: BenchmarkProfiler, BenchmarkTracer, BenchmarkSpan,
137139
/// no-op
138140
func gauge(metric: @autoclosure () -> String) -> BenchmarkGauge { self }
139141
/// no-op
142+
func observe(metric: @autoclosure () -> String, callback: @escaping (any BenchmarkGauge) -> Void) { }
143+
/// no-op
140144
func add(value: Double, attributes: @autoclosure () -> [String: String]) { }
141145
/// no-op
142146
func record(value: Double, attributes: @autoclosure () -> [String: String]) { }

0 commit comments

Comments
 (0)