26
26
import com .google .android .gms .common .util .VisibleForTesting ;
27
27
import com .google .firebase .perf .config .ConfigResolver ;
28
28
import com .google .firebase .perf .logging .AndroidLogger ;
29
+ import com .google .firebase .perf .metrics .FrameMetricsCalculator ;
30
+ import com .google .firebase .perf .metrics .FrameMetricsCalculator .FrameMetrics ;
29
31
import com .google .firebase .perf .metrics .Trace ;
30
32
import com .google .firebase .perf .session .SessionManager ;
31
33
import com .google .firebase .perf .transport .TransportManager ;
@@ -336,9 +338,6 @@ private void sendScreenTrace(Activity activity) {
336
338
}
337
339
activityToScreenTraceMap .remove (activity );
338
340
339
- int totalFrames = 0 ;
340
- int slowFrames = 0 ;
341
- int frozenFrames = 0 ;
342
341
/**
343
342
* Resets the metrics data and returns the currently-collected metrics. Note that {@link
344
343
* FrameMetricsAggregator#reset()} will not stop recording for the activity. The reason of using
@@ -352,48 +351,37 @@ private void sendScreenTrace(Activity activity) {
352
351
logger .debug ("View not hardware accelerated. Unable to collect screen trace." );
353
352
}
354
353
SparseIntArray [] arr = frameMetricsAggregator .reset ();
355
- if (arr != null ) {
356
- SparseIntArray frameTimes = arr [FrameMetricsAggregator .TOTAL_INDEX ];
357
- if (frameTimes != null ) {
358
- for (int i = 0 ; i < frameTimes .size (); i ++) {
359
- int frameTime = frameTimes .keyAt (i );
360
- int numFrames = frameTimes .valueAt (i );
361
- totalFrames += numFrames ;
362
- if (frameTime > Constants .FROZEN_FRAME_TIME ) {
363
- // Frozen frames mean the app appear frozen. The recommended thresholds is 700ms
364
- frozenFrames += numFrames ;
365
- }
366
- if (frameTime > Constants .SLOW_FRAME_TIME ) {
367
- // Slow frames are anything above 16ms (i.e. 60 frames/second)
368
- slowFrames += numFrames ;
369
- }
370
- }
371
- }
372
- }
373
- if (totalFrames == 0 && slowFrames == 0 && frozenFrames == 0 ) {
354
+ FrameMetrics frameMetrics = FrameMetricsCalculator .calculateFrameMetrics (arr );
355
+
356
+ if (frameMetrics .getTotalFrames () == 0
357
+ && frameMetrics .getSlowFrames () == 0
358
+ && frameMetrics .getFrozenFrames () == 0 ) {
374
359
// All metrics are zero, no need to send screen trace.
375
- // return;
360
+ return ;
376
361
}
377
- // Only incrementMetric if corresponding metric is non-zero.
378
- if (totalFrames > 0 ) {
379
- screenTrace .putMetric (Constants .CounterNames .FRAMES_TOTAL .toString (), totalFrames );
362
+ // Only putMetric if corresponding metric is non-zero.
363
+ if (frameMetrics .getTotalFrames () > 0 ) {
364
+ screenTrace .putMetric (
365
+ Constants .CounterNames .FRAMES_TOTAL .toString (), frameMetrics .getTotalFrames ());
380
366
}
381
- if (slowFrames > 0 ) {
382
- screenTrace .putMetric (Constants .CounterNames .FRAMES_SLOW .toString (), slowFrames );
367
+ if (frameMetrics .getSlowFrames () > 0 ) {
368
+ screenTrace .putMetric (
369
+ Constants .CounterNames .FRAMES_SLOW .toString (), frameMetrics .getSlowFrames ());
383
370
}
384
- if (frozenFrames > 0 ) {
385
- screenTrace .putMetric (Constants .CounterNames .FRAMES_FROZEN .toString (), frozenFrames );
371
+ if (frameMetrics .getFrozenFrames () > 0 ) {
372
+ screenTrace .putMetric (
373
+ Constants .CounterNames .FRAMES_FROZEN .toString (), frameMetrics .getFrozenFrames ());
386
374
}
387
375
if (Utils .isDebugLoggingEnabled (activity .getApplicationContext ())) {
388
376
logger .debug (
389
377
"sendScreenTrace name:"
390
378
+ getScreenTraceName (activity )
391
379
+ " _fr_tot:"
392
- + totalFrames
380
+ + frameMetrics . getTotalFrames ()
393
381
+ " _fr_slo:"
394
- + slowFrames
382
+ + frameMetrics . getSlowFrames ()
395
383
+ " _fr_fzn:"
396
- + frozenFrames );
384
+ + frameMetrics . getFrozenFrames () );
397
385
}
398
386
// Stop and record trace
399
387
screenTrace .stop ();
0 commit comments