@@ -663,11 +663,13 @@ package final class BuildOperation: BuildSystemOperation {
663
663
}
664
664
}
665
665
666
+ let aggregatedCounters = await adaptor. getAggregatedCounters ( )
667
+ let aggregatedTaskCounters = await adaptor. getAggregatedTaskCounters ( )
666
668
do {
667
- let swiftCacheHits = self . delegate . aggregatedCounters [ . swiftCacheHits, default: 0 ]
668
- let swiftCacheMisses = self . delegate . aggregatedCounters [ . swiftCacheMisses, default: 0 ]
669
- let clangCacheHits = self . delegate . aggregatedCounters [ . clangCacheHits, default: 0 ]
670
- let clangCacheMisses = self . delegate . aggregatedCounters [ . clangCacheMisses, default: 0 ]
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 ]
671
673
if swiftCacheHits + swiftCacheMisses > 0 || clangCacheHits + clangCacheMisses > 0 {
672
674
adaptor. withActivity ( ruleInfo: " CompilationCacheMetrics " , executionDescription: " Report compilation cache metrics " , signature: " compilation_cache_metrics " , target: nil , parentActivity: nil ) { activity in
673
675
func getSummary( hits: Int , misses: Int ) -> String {
@@ -693,10 +695,10 @@ package final class BuildOperation: BuildSystemOperation {
693
695
var tasks : [ String : [ String : Double ] ] = [ : ]
694
696
}
695
697
var serializedCounters = AllCounters ( )
696
- for (key, value) in self . delegate . aggregatedCounters {
698
+ for (key, value) in aggregatedCounters {
697
699
serializedCounters. global [ key. rawValue] = Double ( value)
698
700
}
699
- for (taskId, taskCounters) in self . delegate . aggregatedTaskCounters {
701
+ for (taskId, taskCounters) in aggregatedTaskCounters {
700
702
var serialTaskCounters : [ String : Double ] = [ : ]
701
703
for (counterKey, counterValue) in taskCounters {
702
704
serialTaskCounters [ counterKey. rawValue] = Double ( counterValue)
@@ -732,10 +734,10 @@ package final class BuildOperation: BuildSystemOperation {
732
734
var tasks : [ String : [ String : Double ] ] = [ : ]
733
735
}
734
736
var serializedCounters = AllCounters ( )
735
- for (key, value) in self . delegate . aggregatedCounters {
737
+ for (key, value) in aggregatedCounters {
736
738
serializedCounters. global [ key. rawValue] = Double ( value)
737
739
}
738
- for (taskId, taskCounters) in self . delegate . aggregatedTaskCounters {
740
+ for (taskId, taskCounters) in aggregatedTaskCounters {
739
741
var serialTaskCounters : [ String : Double ] = [ : ]
740
742
for (counterKey, counterValue) in taskCounters {
741
743
serialTaskCounters [ counterKey. rawValue] = Double ( counterValue)
@@ -801,7 +803,7 @@ package final class BuildOperation: BuildSystemOperation {
801
803
}
802
804
803
805
// `buildComplete()` should not run within `queue`, otherwise there can be a deadlock during cancelling.
804
- return delegate. buildComplete ( self , status: effectiveStatus, delegate: buildOutputDelegate, metrics: . init( counters: delegate . aggregatedCounters) )
806
+ return delegate. buildComplete ( self , status: effectiveStatus, delegate: buildOutputDelegate, metrics: . init( counters: aggregatedCounters) )
805
807
}
806
808
807
809
func prepareForBuilding( ) -> ( [ String ] , [ String ] ) ? {
@@ -1384,6 +1386,16 @@ internal final class OperationSystemAdaptor: SWBLLBuild.BuildSystemDelegate, Act
1384
1386
1385
1387
fileprivate let dynamicOperationContext : DynamicTaskOperationContext
1386
1388
1389
+ /// Returns the delegate's `aggregatedCounters` in a thread-safe manner.
1390
+ func getAggregatedCounters( ) async -> [ BuildOperationMetrics . Counter : Int ] {
1391
+ return await queue. sync { self . operation. delegate. aggregatedCounters }
1392
+ }
1393
+
1394
+ /// Returns the delegate's `aggregatedTaskCounters` in a thread-safe manner.
1395
+ func getAggregatedTaskCounters( ) async -> [ String : [ BuildOperationMetrics . TaskCounter : Int ] ] {
1396
+ return await queue. sync { self . operation. delegate. aggregatedTaskCounters }
1397
+ }
1398
+
1387
1399
init ( operation: BuildOperation , buildOutputDelegate: any BuildOutputDelegate , core: Core ) {
1388
1400
self . operation = operation
1389
1401
self . buildOutputDelegate = buildOutputDelegate
0 commit comments