@@ -43,7 +43,6 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
4343 private let cpuUsageProvider : ( ) -> Double ?
4444 private let batchSize : Int
4545 private let samplingInterval : TimeInterval
46- private let collectInBackground : Bool
4746 private let featureScope : FeatureScope
4847 private let totalRAM : Double
4948 private let ciTest : RUMCITest ?
@@ -71,7 +70,6 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
7170 featureScope: FeatureScope ,
7271 batchSize: Int = 120 ,
7372 samplingInterval: TimeInterval = 1 ,
74- collectInBackground: Bool = false ,
7573 cpuUsageProvider: ( ( ) -> Double ? ) ? = nil ,
7674 totalRAM: Double = Double ( ProcessInfo . processInfo. physicalMemory) ,
7775 ciTest: RUMCITest ? = nil ,
@@ -81,7 +79,6 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
8179 self . memoryReader = memoryReader
8280 self . batchSize = max ( 2 , batchSize)
8381 self . samplingInterval = samplingInterval
84- self . collectInBackground = collectInBackground
8582 self . featureScope = featureScope
8683 self . totalRAM = totalRAM
8784 self . ciTest = ciTest
@@ -90,6 +87,10 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
9087 self . cpuUsageProvider = cpuUsageProvider ?? { TimeseriesSessionCollector . processCPU ( ) }
9188 }
9289
90+ deinit {
91+ timer? . cancel ( )
92+ }
93+
9394 /// Per-process CPU as a percentage (0–100+), summed across all app threads.
9495 /// Separated into a static so it can be called from the init closure without capturing self.
9596 private static func processCPU( ) -> Double ? {
@@ -121,7 +122,7 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
121122 var info = thread_basic_info ( )
122123 var infoCount = mach_msg_type_number_t ( THREAD_INFO_MAX)
123124 let kr = withUnsafeMutablePointer ( to: & info) {
124- $0. withMemoryRebound ( to: integer_t. self, capacity: 1 ) {
125+ $0. withMemoryRebound ( to: integer_t. self, capacity: Int ( infoCount ) ) {
125126 thread_info ( threadsList [ Int ( i) ] , thread_flavor_t ( THREAD_BASIC_INFO) , $0, & infoCount)
126127 }
127128 }
@@ -130,7 +131,7 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
130131 }
131132 total += Double ( info. cpu_usage) / Double( TH_USAGE_SCALE) * 100.0
132133 }
133- return total
134+ return min ( total, 100.0 )
134135 #endif
135136 }
136137
@@ -155,13 +156,12 @@ internal class TimeseriesSessionCollector: TimeseriesCollecting {
155156 }
156157
157158 /// Suspends sampling and flushes buffered data. Session state is preserved for `resume()`. Idempotent.
158- /// No-op when `collectInBackground` is `true`.
159159 func pause( ) {
160160 queue. async { [ weak self] in
161161 guard let self = self else {
162162 return
163163 }
164- if self . collectInBackground || self . isPaused || self . timer == nil {
164+ if self . isPaused || self . timer == nil {
165165 return
166166 }
167167 self . timer? . cancel ( )
0 commit comments