Skip to content

Commit bfe3896

Browse files
committed
Reword MAX_GAUGE_COUNTER
1 parent 6500dad commit bfe3896

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeCounter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import androidx.annotation.VisibleForTesting
1818
import java.util.concurrent.atomic.AtomicInteger
1919

2020
/**
21-
* [GaugeCounter] is a thread-safe counter for gauge metrics. If the metrics count exceeds
22-
* [MAX_METRIC_COUNT], it attempts to log the metrics to Firelog.
21+
* [GaugeCounter] is a thread-safe counter for gauge metrics. If the metrics count reaches or
22+
* exceeds [MAX_METRIC_COUNT], it attempts to log the metrics to Firelog.
2323
*/
2424
object GaugeCounter {
2525
private const val MAX_METRIC_COUNT = 50

firebase-perf/src/test/java/com/google/firebase/perf/session/gauges/GaugeManagerTest.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public final class GaugeManagerTest extends FirebasePerformanceTestBase {
6767
private static final long DEFAULT_MEMORY_GAUGE_COLLECTION_FREQUENCY_FG_MS = 60;
6868

6969
// See [com.google.firebase.perf.session.gauges.GaugeCounter].
70-
private static long MAX_GAUGE_COUNTER_BEFORE_LOGGING = 50;
70+
private static final long MAX_GAUGE_COUNTER_LIMIT = 50;
7171

7272
private GaugeManager testGaugeManager = null;
7373
private FakeScheduledExecutorService fakeScheduledExecutorService = null;
@@ -343,7 +343,7 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
343343
// There's no job to log the gauges.
344344
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
345345

346-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10);
346+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT - 10);
347347

348348
// There's still no job to log the gauges.
349349
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
@@ -368,7 +368,7 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
368368
int recordedGaugeMetricsCount =
369369
recordedGaugeMetric.getAndroidMemoryReadingsCount()
370370
+ recordedGaugeMetric.getCpuMetricReadingsCount();
371-
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_BEFORE_LOGGING);
371+
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_LIMIT);
372372

373373
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
374374
}
@@ -385,7 +385,7 @@ public void testGaugeCounterIsDecrementedWhenLogged() {
385385
// There's no job to log the gauges.
386386
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
387387

388-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10);
388+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT - 10);
389389

390390
// There's still no job to log the gauges.
391391
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
@@ -396,8 +396,7 @@ public void testGaugeCounterIsDecrementedWhenLogged() {
396396
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS))
397397
.isEqualTo(TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS);
398398

399-
assertThat(GaugeCounter.count())
400-
.isEqualTo(priorGaugeCounter + MAX_GAUGE_COUNTER_BEFORE_LOGGING);
399+
assertThat(GaugeCounter.count()).isEqualTo(priorGaugeCounter + MAX_GAUGE_COUNTER_LIMIT);
401400
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
402401

403402
assertThat(GaugeCounter.count()).isEqualTo(priorGaugeCounter);
@@ -414,12 +413,12 @@ public void testDuplicateGaugeLoggingIsAvoided() {
414413
// There's no job to log the gauges.
415414
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
416415

417-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 20);
416+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT - 20);
418417

419418
// There's still no job to log the gauges.
420419
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
421420

422-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING);
421+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT);
423422

424423
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
425424
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS))
@@ -435,7 +434,7 @@ public void testDuplicateGaugeLoggingIsAvoided() {
435434
int recordedGaugeMetricsCount =
436435
recordedGaugeMetric.getAndroidMemoryReadingsCount()
437436
+ recordedGaugeMetric.getCpuMetricReadingsCount();
438-
assertThat(recordedGaugeMetricsCount).isEqualTo(2 * MAX_GAUGE_COUNTER_BEFORE_LOGGING - 20);
437+
assertThat(recordedGaugeMetricsCount).isEqualTo(2 * MAX_GAUGE_COUNTER_LIMIT - 20);
439438

440439
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
441440
assertThat(GaugeCounter.count()).isEqualTo(priorGaugeCounter);
@@ -450,7 +449,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
450449
GaugeCounter.setGaugeManager(testGaugeManager);
451450

452451
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
453-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10);
452+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT - 10);
454453

455454
// There's no job to log the gauges.
456455
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
@@ -465,7 +464,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
465464
shadowOf(Looper.getMainLooper()).idle();
466465

467466
// Generate additional metrics in the new app state.
468-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1);
467+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT + 1);
469468

470469
GaugeMetric recordedGaugeMetric =
471470
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND);
@@ -474,7 +473,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
474473
int recordedGaugeMetricsCount =
475474
recordedGaugeMetric.getAndroidMemoryReadingsCount()
476475
+ recordedGaugeMetric.getCpuMetricReadingsCount();
477-
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10);
476+
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_LIMIT - 10);
478477

479478
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
480479

@@ -488,7 +487,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
488487
recordedGaugeMetricsCount =
489488
recordedGaugeMetric.getAndroidMemoryReadingsCount()
490489
+ recordedGaugeMetric.getCpuMetricReadingsCount();
491-
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1);
490+
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_LIMIT + 1);
492491

493492
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
494493
}
@@ -502,7 +501,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
502501
GaugeCounter.setGaugeManager(testGaugeManager);
503502

504503
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
505-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10);
504+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT - 10);
506505

507506
PerfSession updatedPerfSession = createTestSession(2);
508507
updatedPerfSession.setGaugeAndEventCollectionEnabled(true);
@@ -519,7 +518,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
519518
shadowOf(Looper.getMainLooper()).idle();
520519

521520
// Generate metrics for the new session.
522-
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1);
521+
generateMetricsAndIncrementCounter(MAX_GAUGE_COUNTER_LIMIT + 1);
523522

524523
GaugeMetric recordedGaugeMetric =
525524
getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND);
@@ -528,7 +527,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
528527
int recordedGaugeMetricsCount =
529528
recordedGaugeMetric.getAndroidMemoryReadingsCount()
530529
+ recordedGaugeMetric.getCpuMetricReadingsCount();
531-
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_BEFORE_LOGGING - 10);
530+
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_LIMIT - 10);
532531

533532
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
534533

@@ -542,7 +541,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
542541
recordedGaugeMetricsCount =
543542
recordedGaugeMetric.getAndroidMemoryReadingsCount()
544543
+ recordedGaugeMetric.getCpuMetricReadingsCount();
545-
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_BEFORE_LOGGING + 1);
544+
assertThat(recordedGaugeMetricsCount).isEqualTo(MAX_GAUGE_COUNTER_LIMIT + 1);
546545

547546
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(2));
548547
}

0 commit comments

Comments
 (0)