@@ -37,7 +37,7 @@ @interface FPRGaugeManager () <FPRCPUGaugeCollectorDelegate, FPRMemoryGaugeColle
37
37
@property (nonatomic ) NSMutableArray *gaugeData;
38
38
39
39
/* * @brief Currently active sessionID. */
40
- @property (nonatomic , readwrite ) NSString *currentSessionId;
40
+ @property (nonatomic , readwrite , copy ) NSString *currentSessionId;
41
41
42
42
@end
43
43
@@ -117,7 +117,8 @@ - (BOOL)gaugeCollectionEnabled {
117
117
}
118
118
119
119
- (void )startCollectingGauges : (FPRGauges)gauges forSessionId : (NSString *)sessionId {
120
- [self prepareAndDispatchGaugeData ];
120
+ // Dispatch the already available gauge data with old sessionId.
121
+ [self prepareAndDispatchCollectedGaugeDataWithSessionId: self .currentSessionId];
121
122
122
123
self.currentSessionId = sessionId;
123
124
if (self.gaugeCollectionEnabled ) {
@@ -143,7 +144,8 @@ - (void)stopCollectingGauges:(FPRGauges)gauges {
143
144
144
145
self.activeGauges = self.activeGauges & ~(gauges);
145
146
146
- [self prepareAndDispatchGaugeData ];
147
+ // Flush out all the already collected gauge metrics
148
+ [self prepareAndDispatchCollectedGaugeDataWithSessionId: self .currentSessionId];
147
149
}
148
150
149
151
- (void )collectAllGauges {
@@ -172,31 +174,33 @@ - (void)dispatchMetric:(id)gaugeMetric {
172
174
173
175
#pragma mark - Utils
174
176
175
- - (void )prepareAndDispatchGaugeData {
176
- NSArray *currentBatch = self.gaugeData ;
177
- NSString *currentSessionId = self.currentSessionId ;
178
- self.gaugeData = [[NSMutableArray alloc ] init ];
179
- dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
180
- if (currentBatch.count > 0 ) {
181
- [[FPRClient sharedInstance ] logGaugeMetric: currentBatch forSessionId: currentSessionId];
182
- FPRLogDebug (kFPRGaugeManagerDataCollected , @" Logging %lu gauge metrics." ,
183
- (unsigned long )currentBatch.count );
184
- }
177
+ - (void )prepareAndDispatchCollectedGaugeDataWithSessionId : (nullable NSString *)sessionId {
178
+ dispatch_async (self.gaugeDataProtectionQueue , ^{
179
+ NSArray *dispatchGauges = [self .gaugeData copy ];
180
+ self.gaugeData = [[NSMutableArray alloc ] init ];
181
+
182
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
183
+ if (dispatchGauges.count > 0 && sessionId != nil ) {
184
+ [[FPRClient sharedInstance ] logGaugeMetric: dispatchGauges forSessionId: sessionId];
185
+ FPRLogDebug (kFPRGaugeManagerDataCollected , @" Logging %lu gauge metrics." ,
186
+ (unsigned long )dispatchGauges.count );
187
+ }
188
+ });
185
189
});
186
190
}
187
191
188
192
/* *
189
193
* Adds the gauge to the batch and decide on when to dispatch the events to Google Data Transport.
190
194
*
191
- * @param gaugeData Gauge data received from the collectors.
195
+ * @param gauge Gauge data received from the collectors.
192
196
*/
193
- - (void )addGaugeData : (id )gaugeData {
197
+ - (void )addGaugeData : (id )gauge {
194
198
dispatch_async (self.gaugeDataProtectionQueue , ^{
195
- if (gaugeData ) {
196
- [self .gaugeData addObject: gaugeData ];
199
+ if (gauge ) {
200
+ [self .gaugeData addObject: gauge ];
197
201
198
202
if (self.gaugeData .count >= kGaugeDataBatchSize ) {
199
- [self prepareAndDispatchGaugeData ];
203
+ [self prepareAndDispatchCollectedGaugeDataWithSessionId: self .currentSessionId ];
200
204
}
201
205
}
202
206
});
0 commit comments