Skip to content

Commit 2c531e3

Browse files
committed
Code review
1 parent f991f17 commit 2c531e3

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private synchronized void scheduleCpuMetricCollectionWithRate(
166166
CpuMetricReading currCpuReading = syncCollectCpuMetric(referenceTime);
167167
if (currCpuReading != null) {
168168
cpuMetricReadings.add(currCpuReading);
169-
GaugeCounter.Companion.getInstance().incrementCounter();
169+
GaugeCounter.INSTANCE.incrementCounter();
170170
}
171171
},
172172
/* initialDelay */ 0,

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ package com.google.firebase.perf.session.gauges
1717
import java.util.concurrent.atomic.AtomicInteger
1818

1919
/**
20-
* [GaugeCounter] is a threadsafe counter for gauge metrics. If the metrics count exceeds
20+
* [GaugeCounter] is a thread-safe counter for gauge metrics. If the metrics count exceeds
2121
* [MAX_METRIC_COUNT], it attempts to log the metrics to Firelog.
2222
*/
23-
class GaugeCounter private constructor() {
23+
object GaugeCounter {
24+
private const val MAX_METRIC_COUNT = 25
2425
private val counter = AtomicInteger(0)
2526
private val gaugeManager: GaugeManager = GaugeManager.getInstance()
2627

@@ -35,9 +36,4 @@ class GaugeCounter private constructor() {
3536
fun decrementCounter() {
3637
counter.decrementAndGet()
3738
}
38-
39-
companion object {
40-
val instance: GaugeCounter by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { GaugeCounter() }
41-
const val MAX_METRIC_COUNT = 25
42-
}
4339
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private void logExistingGaugeMetrics(
243243
*/
244244
private void syncFlush(String sessionId, ApplicationProcessState appState) {
245245
GaugeMetric.Builder gaugeMetricBuilder = GaugeMetric.newBuilder();
246-
GaugeCounter gaugeCounter = GaugeCounter.Companion.getInstance();
246+
GaugeCounter gaugeCounter = GaugeCounter.INSTANCE;
247247

248248
// Adding CPU metric readings.
249249
while (!cpuGaugeCollector.get().cpuMetricReadings.isEmpty()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private synchronized void scheduleMemoryMetricCollectionWithRate(
129129
AndroidMemoryReading memoryReading = syncCollectMemoryMetric(referenceTime);
130130
if (memoryReading != null) {
131131
memoryMetricReadings.add(memoryReading);
132-
GaugeCounter.Companion.getInstance().incrementCounter();
132+
GaugeCounter.INSTANCE.incrementCounter();
133133
}
134134
},
135135
/* initialDelay */ 0,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ public void testStartCollectingGaugesStartsCollectingMetricsInForegroundState()
159159
testStartCollectingGaugesStartCollectingMetricsWithUnknownApplicationProcessStateInForegroundState() {
160160
PerfSession fakeSession = createTestSession(1);
161161
testGaugeManager.startCollectingGauges(fakeSession);
162-
// @see
163-
// com.google.firebase.perf.config.ConfigurationConstants.SessionsCpuCaptureFrequencyForegroundMs
164162
verify(fakeCpuGaugeCollector, never())
165-
.startCollecting(ArgumentMatchers.eq(100L), ArgumentMatchers.nullable(Timer.class));
163+
.startCollecting(
164+
eq(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_FG_MS),
165+
ArgumentMatchers.nullable(Timer.class));
166166
verify(fakeMemoryGaugeCollector, never())
167-
.startCollecting(ArgumentMatchers.eq(100L), ArgumentMatchers.nullable(Timer.class));
167+
.startCollecting(
168+
eq(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_FG_MS),
169+
ArgumentMatchers.nullable(Timer.class));
168170
}
169171

170172
@Test

0 commit comments

Comments
 (0)