File tree 5 files changed +12
-14
lines changed
main/java/com/google/firebase/perf/session/gauges
test/java/com/google/firebase/perf/session/gauges
5 files changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ private synchronized void scheduleCpuMetricCollectionWithRate(
166
166
CpuMetricReading currCpuReading = syncCollectCpuMetric (referenceTime );
167
167
if (currCpuReading != null ) {
168
168
cpuMetricReadings .add (currCpuReading );
169
- GaugeCounter .Companion . getInstance () .incrementCounter ();
169
+ GaugeCounter .INSTANCE .incrementCounter ();
170
170
}
171
171
},
172
172
/* initialDelay */ 0 ,
Original file line number Diff line number Diff line change @@ -17,10 +17,11 @@ package com.google.firebase.perf.session.gauges
17
17
import java.util.concurrent.atomic.AtomicInteger
18
18
19
19
/* *
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
21
21
* [MAX_METRIC_COUNT], it attempts to log the metrics to Firelog.
22
22
*/
23
- class GaugeCounter private constructor() {
23
+ object GaugeCounter {
24
+ private const val MAX_METRIC_COUNT = 25
24
25
private val counter = AtomicInteger (0 )
25
26
private val gaugeManager: GaugeManager = GaugeManager .getInstance()
26
27
@@ -35,9 +36,4 @@ class GaugeCounter private constructor() {
35
36
fun decrementCounter () {
36
37
counter.decrementAndGet()
37
38
}
38
-
39
- companion object {
40
- val instance: GaugeCounter by lazy(LazyThreadSafetyMode .SYNCHRONIZED ) { GaugeCounter () }
41
- const val MAX_METRIC_COUNT = 25
42
- }
43
39
}
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ private void logExistingGaugeMetrics(
243
243
*/
244
244
private void syncFlush (String sessionId , ApplicationProcessState appState ) {
245
245
GaugeMetric .Builder gaugeMetricBuilder = GaugeMetric .newBuilder ();
246
- GaugeCounter gaugeCounter = GaugeCounter .Companion . getInstance () ;
246
+ GaugeCounter gaugeCounter = GaugeCounter .INSTANCE ;
247
247
248
248
// Adding CPU metric readings.
249
249
while (!cpuGaugeCollector .get ().cpuMetricReadings .isEmpty ()) {
Original file line number Diff line number Diff line change @@ -129,7 +129,7 @@ private synchronized void scheduleMemoryMetricCollectionWithRate(
129
129
AndroidMemoryReading memoryReading = syncCollectMemoryMetric (referenceTime );
130
130
if (memoryReading != null ) {
131
131
memoryMetricReadings .add (memoryReading );
132
- GaugeCounter .Companion . getInstance () .incrementCounter ();
132
+ GaugeCounter .INSTANCE .incrementCounter ();
133
133
}
134
134
},
135
135
/* initialDelay */ 0 ,
Original file line number Diff line number Diff line change @@ -159,12 +159,14 @@ public void testStartCollectingGaugesStartsCollectingMetricsInForegroundState()
159
159
testStartCollectingGaugesStartCollectingMetricsWithUnknownApplicationProcessStateInForegroundState () {
160
160
PerfSession fakeSession = createTestSession (1 );
161
161
testGaugeManager .startCollectingGauges (fakeSession );
162
- // @see
163
- // com.google.firebase.perf.config.ConfigurationConstants.SessionsCpuCaptureFrequencyForegroundMs
164
162
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 ));
166
166
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 ));
168
170
}
169
171
170
172
@ Test
You can’t perform that action at this time.
0 commit comments