Skip to content

Commit de925c6

Browse files
committed
[BuildOperation] Change the summary about the cache hit/miss metrics to combine all hits/misses
Separating by compiler is not that useful, this is intended for a high-level overview. A couple of changes * Report the combined cache hits/misses * Report the summary as a diagnostic note to make it more visible
1 parent 172235d commit de925c6

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

Sources/SWBBuildSystem/BuildOperation.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,22 +666,24 @@ package final class BuildOperation: BuildSystemOperation {
666666
let aggregatedCounters = await adaptor.getAggregatedCounters()
667667
let aggregatedTaskCounters = await adaptor.getAggregatedTaskCounters()
668668
do {
669-
let swiftCacheHits = aggregatedCounters[.swiftCacheHits, default: 0]
670-
let swiftCacheMisses = aggregatedCounters[.swiftCacheMisses, default: 0]
671-
let clangCacheHits = aggregatedCounters[.clangCacheHits, default: 0]
672-
let clangCacheMisses = aggregatedCounters[.clangCacheMisses, default: 0]
673-
if swiftCacheHits + swiftCacheMisses > 0 || clangCacheHits + clangCacheMisses > 0 {
674-
adaptor.withActivity(ruleInfo: "CompilationCacheMetrics", executionDescription: "Report compilation cache metrics", signature: "compilation_cache_metrics", target: nil, parentActivity: nil) { activity in
669+
let cacheHits: Int
670+
let cacheMisses: Int
671+
do {
672+
let swiftCacheHits = aggregatedCounters[.swiftCacheHits, default: 0]
673+
let swiftCacheMisses = aggregatedCounters[.swiftCacheMisses, default: 0]
674+
let clangCacheHits = aggregatedCounters[.clangCacheHits, default: 0]
675+
let clangCacheMisses = aggregatedCounters[.clangCacheMisses, default: 0]
676+
cacheHits = swiftCacheHits + clangCacheHits
677+
cacheMisses = swiftCacheMisses + clangCacheMisses
678+
}
679+
if cacheHits + cacheMisses > 0 {
680+
let signature = ByteString(encodingAsUTF8: "compilation_cache_metrics")
681+
adaptor.withActivity(ruleInfo: "CompilationCacheMetrics", executionDescription: "Report compilation cache metrics", signature: signature, target: nil, parentActivity: nil) { activity in
675682
func getSummary(hits: Int, misses: Int) -> String {
676683
let hitPercent = Int((Double(hits) / Double(hits + misses) * 100).rounded())
677684
return "\(hits) hit\(hits == 1 ? "" : "s") (\(hitPercent)%), \(misses) miss\(misses == 1 ? "" : "es")"
678685
}
679-
if swiftCacheHits + swiftCacheMisses > 0 {
680-
delegate.emit(data: ByteString(encodingAsUTF8: "Swift compiler: \(getSummary(hits: swiftCacheHits, misses: swiftCacheMisses))").bytes, for: activity, signature: "compilation_cache_metrics")
681-
}
682-
if clangCacheHits + clangCacheMisses > 0 {
683-
delegate.emit(data: ByteString(encodingAsUTF8: "Clang compiler: \(getSummary(hits: clangCacheHits, misses: clangCacheMisses))").bytes, for: activity, signature: "compilation_cache_metrics")
684-
}
686+
delegate.emit(diagnostic: Diagnostic(behavior: .note, location: .unknown, data: DiagnosticData(getSummary(hits: cacheHits, misses: cacheMisses))), for: activity, signature: signature)
685687
return .succeeded
686688
}
687689

Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
234234
// Make sure scanning happens before compilation...
235235
results.check(event: .taskHadEvent(scanTask, event: .completed), precedes: .taskHadEvent(compileTask, event: .started))
236236

237-
results.check(contains: .activityEmittedData(ruleInfo: "CompilationCacheMetrics", ByteString(encodingAsUTF8: "Clang compiler: 0 hits (0%), 1 miss").bytes))
237+
results.checkNote("0 hits (0%), 1 miss")
238238
results.checkCompileCacheMiss(compileTask)
239239
results.checkNoDiagnostics()
240240
}
@@ -262,7 +262,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
262262
// Make sure scanning happens before compilation.
263263
results.check(event: .taskHadEvent(scanTask, event: .completed), precedes: .taskHadEvent(compileTask, event: .started))
264264

265-
results.check(contains: .activityEmittedData(ruleInfo: "CompilationCacheMetrics", ByteString(encodingAsUTF8: "Clang compiler: 1 hit (100%), 0 misses").bytes))
265+
results.checkNote("1 hit (100%), 0 misses")
266266
results.checkCompileCacheHit(compileTask)
267267
}
268268
results.checkNoDiagnostics()

Tests/SWBBuildSystemTests/SwiftCompilationCachingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fileprivate struct SwiftCompilationCachingTests: CoreBasedTests {
109109
numCompile += tasks.count
110110
}
111111

112-
results.check(contains: .activityEmittedData(ruleInfo: "CompilationCacheMetrics", ByteString(encodingAsUTF8: "Swift compiler: 0 hits (0%), 4 misses").bytes))
112+
results.checkNote("0 hits (0%), 4 misses")
113113

114114
results.checkNoTask()
115115
}
@@ -121,7 +121,7 @@ fileprivate struct SwiftCompilationCachingTests: CoreBasedTests {
121121

122122
tester.userInfo = rawUserInfo.withAdditionalEnvironment(environment: metricsEnv("two"))
123123
try await tester.checkBuild(runDestination: .anyiOSDevice, persistent: true) { results in
124-
results.check(contains: .activityEmittedData(ruleInfo: "CompilationCacheMetrics", ByteString(encodingAsUTF8: "Swift compiler: 4 hits (100%), 0 misses").bytes))
124+
results.checkNote("4 hits (100%), 0 misses")
125125
}
126126
#expect(try readMetrics("two").contains("\"swiftCacheHits\":\(numCompile),\"swiftCacheMisses\":0"))
127127
}

0 commit comments

Comments
 (0)