Skip to content

Commit 2e3da3a

Browse files
committed
RUM-8448 Add ios.benchmark.bytes_deleted metric
1 parent 2f3d244 commit 2e3da3a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

DatadogCore/Sources/Core/Storage/Files/File.swift

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ internal protocol ReadableFile {
3535
/// Name of this file.
3636
var name: String { get }
3737

38+
/// Current size of this file.
39+
func size() throws -> UInt64
40+
3841
/// Creates InputStream for reading the available data from this file.
3942
func stream() throws -> InputStream
4043

DatadogCore/Sources/Core/Storage/FilesOrchestrator.swift

+6
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ internal class FilesOrchestrator: FilesOrchestratorType {
211211

212212
func delete(readableFile: ReadableFile, deletionReason: BatchDeletedMetric.RemovalReason) {
213213
do {
214+
#if DD_BENCHMARK
215+
if case .intakeCode = deletionReason {
216+
try bench.meter.counter(metric: "ios.benchmark.bytes_deleted")
217+
.increment(by: readableFile.size(), attributes: ["track": trackName])
218+
}
219+
#endif
214220
try readableFile.delete()
215221
// Decrement pending batches at each batch deletion
216222
_pendingBatches.mutate { $0 -= 1 }

DatadogInternal/Sources/Benchmarks/BenchmarkProfiler.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public protocol BenchmarkCounter {
8787
}
8888

8989
extension BenchmarkCounter {
90+
/// Increment the counter by one.
91+
public func increment(attributes: @autoclosure () -> [String: String] = [:]) {
92+
add(value: 1, attributes: attributes())
93+
}
94+
9095
/// Increment the counter.
9196
///
9297
/// - parameters:
@@ -99,7 +104,7 @@ extension BenchmarkCounter {
99104
///
100105
/// - parameters:
101106
/// - by: Amount to increment by.
102-
public func increment<Integer>(by amount: Integer = 1, attributes: @autoclosure () -> [String: String] = [:]) where Integer: BinaryInteger {
107+
public func increment<Integer>(by amount: Integer, attributes: @autoclosure () -> [String: String] = [:]) where Integer: BinaryInteger {
103108
add(value: Double(amount), attributes: attributes())
104109
}
105110
}

0 commit comments

Comments
 (0)