@@ -66,9 +66,6 @@ public final class GaugeManagerTest extends FirebasePerformanceTestBase {
66
66
private static final long DEFAULT_MEMORY_GAUGE_COLLECTION_FREQUENCY_BG_MS = 120 ;
67
67
private static final long DEFAULT_MEMORY_GAUGE_COLLECTION_FREQUENCY_FG_MS = 60 ;
68
68
69
- // See [com.google.firebase.perf.session.gauges.GaugeCounter].
70
- private static long MAX_GAUGE_COUNTER_BEFORE_LOGGING = 50 ;
71
-
72
69
private GaugeManager testGaugeManager = null ;
73
70
private FakeScheduledExecutorService fakeScheduledExecutorService = null ;
74
71
private TransportManager mockTransportManager = null ;
@@ -343,7 +340,8 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
343
340
// There's no job to log the gauges.
344
341
assertThat (fakeScheduledExecutorService .isEmpty ()).isTrue ();
345
342
346
- generateMetricsAndIncrementCounter (MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10 );
343
+ // Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
344
+ generateMetricsAndIncrementCounter (20 );
347
345
348
346
// There's still no job to log the gauges.
349
347
assertThat (fakeScheduledExecutorService .isEmpty ()).isTrue ();
@@ -368,7 +366,7 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
368
366
int recordedGaugeMetricsCount =
369
367
recordedGaugeMetric .getAndroidMemoryReadingsCount ()
370
368
+ recordedGaugeMetric .getCpuMetricReadingsCount ();
371
- assertThat (recordedGaugeMetricsCount ).isEqualTo (MAX_GAUGE_COUNTER_BEFORE_LOGGING );
369
+ assertThat (recordedGaugeMetricsCount ).isEqualTo (30 );
372
370
373
371
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (1 ));
374
372
}
@@ -385,7 +383,8 @@ public void testGaugeCounterIsDecrementedWhenLogged() {
385
383
// There's no job to log the gauges.
386
384
assertThat (fakeScheduledExecutorService .isEmpty ()).isTrue ();
387
385
388
- generateMetricsAndIncrementCounter (MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10 );
386
+ // Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
387
+ generateMetricsAndIncrementCounter (20 );
389
388
390
389
// There's still no job to log the gauges.
391
390
assertThat (fakeScheduledExecutorService .isEmpty ()).isTrue ();
@@ -396,8 +395,7 @@ public void testGaugeCounterIsDecrementedWhenLogged() {
396
395
assertThat (fakeScheduledExecutorService .getDelayToNextTask (TimeUnit .MILLISECONDS ))
397
396
.isEqualTo (TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS );
398
397
399
- assertThat (GaugeCounter .count ())
400
- .isEqualTo (priorGaugeCounter + MAX_GAUGE_COUNTER_BEFORE_LOGGING );
398
+ assertThat (GaugeCounter .count ()).isEqualTo (priorGaugeCounter + 30 );
401
399
fakeScheduledExecutorService .simulateSleepExecutingAtMostOneTask ();
402
400
403
401
assertThat (GaugeCounter .count ()).isEqualTo (priorGaugeCounter );
@@ -412,7 +410,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
412
410
GaugeCounter .setGaugeManager (testGaugeManager );
413
411
414
412
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
415
- generateMetricsAndIncrementCounter (MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10 );
413
+ generateMetricsAndIncrementCounter (10 );
416
414
417
415
// There's no job to log the gauges.
418
416
assertThat (fakeScheduledExecutorService .isEmpty ()).isTrue ();
@@ -427,7 +425,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
427
425
shadowOf (Looper .getMainLooper ()).idle ();
428
426
429
427
// Generate additional metrics in the new app state.
430
- generateMetricsAndIncrementCounter (MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1 );
428
+ generateMetricsAndIncrementCounter (26 );
431
429
432
430
GaugeMetric recordedGaugeMetric =
433
431
getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
@@ -436,7 +434,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
436
434
int recordedGaugeMetricsCount =
437
435
recordedGaugeMetric .getAndroidMemoryReadingsCount ()
438
436
+ recordedGaugeMetric .getCpuMetricReadingsCount ();
439
- assertThat (recordedGaugeMetricsCount ).isEqualTo (MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10 );
437
+ assertThat (recordedGaugeMetricsCount ).isEqualTo (10 );
440
438
441
439
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (1 ));
442
440
@@ -450,7 +448,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
450
448
recordedGaugeMetricsCount =
451
449
recordedGaugeMetric .getAndroidMemoryReadingsCount ()
452
450
+ recordedGaugeMetric .getCpuMetricReadingsCount ();
453
- assertThat (recordedGaugeMetricsCount ).isEqualTo (MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1 );
451
+ assertThat (recordedGaugeMetricsCount ).isEqualTo (26 );
454
452
455
453
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (1 ));
456
454
}
@@ -464,7 +462,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
464
462
GaugeCounter .setGaugeManager (testGaugeManager );
465
463
466
464
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
467
- generateMetricsAndIncrementCounter (MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10 );
465
+ generateMetricsAndIncrementCounter (10 );
468
466
469
467
PerfSession updatedPerfSession = createTestSession (2 );
470
468
updatedPerfSession .setGaugeAndEventCollectionEnabled (true );
@@ -481,7 +479,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
481
479
shadowOf (Looper .getMainLooper ()).idle ();
482
480
483
481
// Generate metrics for the new session.
484
- generateMetricsAndIncrementCounter (MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1 );
482
+ generateMetricsAndIncrementCounter (26 );
485
483
486
484
GaugeMetric recordedGaugeMetric =
487
485
getLastRecordedGaugeMetric (ApplicationProcessState .BACKGROUND );
@@ -490,7 +488,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
490
488
int recordedGaugeMetricsCount =
491
489
recordedGaugeMetric .getAndroidMemoryReadingsCount ()
492
490
+ recordedGaugeMetric .getCpuMetricReadingsCount ();
493
- assertThat (recordedGaugeMetricsCount ).isEqualTo (MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10 );
491
+ assertThat (recordedGaugeMetricsCount ).isEqualTo (10 );
494
492
495
493
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (1 ));
496
494
@@ -504,7 +502,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
504
502
recordedGaugeMetricsCount =
505
503
recordedGaugeMetric .getAndroidMemoryReadingsCount ()
506
504
+ recordedGaugeMetric .getCpuMetricReadingsCount ();
507
- assertThat (recordedGaugeMetricsCount ).isEqualTo (MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1 );
505
+ assertThat (recordedGaugeMetricsCount ).isEqualTo (26 );
508
506
509
507
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (2 ));
510
508
}
@@ -561,7 +559,7 @@ public void testLogGaugeMetadataSendDataToTransport() {
561
559
when (fakeGaugeMetadataManager .getMaxAppJavaHeapMemoryKb ()).thenReturn (1000 );
562
560
when (fakeGaugeMetadataManager .getMaxEncouragedAppJavaHeapMemoryKb ()).thenReturn (800 );
563
561
564
- testGaugeManager .logGaugeMetadata (testSessionId (1 ));
562
+ testGaugeManager .logGaugeMetadata (testSessionId (1 ), ApplicationProcessState . FOREGROUND );
565
563
566
564
GaugeMetric recordedGaugeMetric =
567
565
getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
@@ -588,7 +586,9 @@ public void testLogGaugeMetadataDoesNotLogWhenGaugeMetadataManagerNotAvailable()
588
586
new Lazy <>(() -> fakeCpuGaugeCollector ),
589
587
new Lazy <>(() -> fakeMemoryGaugeCollector ));
590
588
591
- assertThat (testGaugeManager .logGaugeMetadata (testSessionId (1 ))).isFalse ();
589
+ assertThat (
590
+ testGaugeManager .logGaugeMetadata (testSessionId (1 ), ApplicationProcessState .FOREGROUND ))
591
+ .isFalse ();
592
592
}
593
593
594
594
@ Test
@@ -603,10 +603,14 @@ public void testLogGaugeMetadataLogsAfterApplicationContextIsSet() {
603
603
new Lazy <>(() -> fakeCpuGaugeCollector ),
604
604
new Lazy <>(() -> fakeMemoryGaugeCollector ));
605
605
606
- assertThat (testGaugeManager .logGaugeMetadata (testSessionId (1 ))).isFalse ();
606
+ assertThat (
607
+ testGaugeManager .logGaugeMetadata (testSessionId (1 ), ApplicationProcessState .FOREGROUND ))
608
+ .isFalse ();
607
609
608
610
testGaugeManager .initializeGaugeMetadataManager (ApplicationProvider .getApplicationContext ());
609
- assertThat (testGaugeManager .logGaugeMetadata (testSessionId (1 ))).isTrue ();
611
+ assertThat (
612
+ testGaugeManager .logGaugeMetadata (testSessionId (1 ), ApplicationProcessState .FOREGROUND ))
613
+ .isTrue ();
610
614
611
615
GaugeMetric recordedGaugeMetric =
612
616
getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
@@ -634,7 +638,7 @@ private long getMinimumBackgroundCollectionFrequency() {
634
638
}
635
639
636
640
// Simulates the behavior of Cpu and Memory Gauge collector.
637
- private void generateMetricsAndIncrementCounter (long count ) {
641
+ private void generateMetricsAndIncrementCounter (int count ) {
638
642
// TODO(b/394127311): Explore actually collecting metrics using the fake Cpu and Memory
639
643
// metric collectors.
640
644
Random random = new Random ();
0 commit comments