Skip to content

Commit 35f7753

Browse files
committed
Remove the identical methods in PerfSession
1 parent 4767a34 commit 35f7753

File tree

7 files changed

+22
-32
lines changed

7 files changed

+22
-32
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/metrics/NetworkRequestMetricBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public NetworkRequestMetricBuilder setCustomAttributes(Map<String, String> attri
224224
* point depending upon the current {@link PerfSession} verbosity.
225225
*
226226
* @see GaugeManager#collectGaugeMetricOnce(Timer)
227-
* @see PerfSession#isGaugeAndEventCollectionEnabled()
227+
* @see PerfSession#isVerbose()
228228
*/
229229
public NetworkRequestMetricBuilder setRequestStartTimeMicros(long time) {
230230
SessionManager sessionManager = SessionManager.getInstance();
@@ -234,7 +234,7 @@ public NetworkRequestMetricBuilder setRequestStartTimeMicros(long time) {
234234
builder.setClientStartTimeUs(time);
235235
updateSession(perfSession);
236236

237-
if (perfSession.isGaugeAndEventCollectionEnabled()) {
237+
if (perfSession.isVerbose()) {
238238
gaugeManager.collectGaugeMetricOnce(perfSession.getTimer());
239239
}
240240

@@ -265,12 +265,12 @@ public long getTimeToResponseInitiatedMicros() {
265265
* point depending upon the current {@link PerfSession} Verbosity.
266266
*
267267
* @see GaugeManager#collectGaugeMetricOnce(Timer)
268-
* @see PerfSession#isGaugeAndEventCollectionEnabled()
268+
* @see PerfSession#isVerbose()
269269
*/
270270
public NetworkRequestMetricBuilder setTimeToResponseCompletedMicros(long time) {
271271
builder.setTimeToResponseCompletedUs(time);
272272

273-
if (SessionManager.getInstance().perfSession().isGaugeAndEventCollectionEnabled()) {
273+
if (SessionManager.getInstance().perfSession().isVerbose()) {
274274
gaugeManager.collectGaugeMetricOnce(SessionManager.getInstance().perfSession().getTimer());
275275
}
276276

firebase-perf/src/main/java/com/google/firebase/perf/metrics/Trace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public void start() {
233233

234234
updateSession(perfSession);
235235

236-
if (perfSession.isGaugeAndEventCollectionEnabled()) {
236+
if (perfSession.isVerbose()) {
237237
gaugeManager.collectGaugeMetricOnce(perfSession.getTimer());
238238
}
239239
}
@@ -259,7 +259,7 @@ public void stop() {
259259
if (!name.isEmpty()) {
260260
transportManager.log(new TraceMetricBuilder(this).build(), getAppState());
261261

262-
if (SessionManager.getInstance().perfSession().isGaugeAndEventCollectionEnabled()) {
262+
if (SessionManager.getInstance().perfSession().isVerbose()) {
263263
gaugeManager.collectGaugeMetricOnce(
264264
SessionManager.getInstance().perfSession().getTimer());
265265
}

firebase-perf/src/main/java/com/google/firebase/perf/session/PerfSession.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,10 @@ public Timer getTimer() {
7676
* Enables/Disables the gauge and event collection for the system.
7777
*/
7878
public void setGaugeAndEventCollectionEnabled(boolean enabled) {
79+
// TODO(b/394127311): Explore deleting this method.
7980
isGaugeAndEventCollectionEnabled = enabled;
8081
}
8182

82-
/*
83-
* Returns if gauge and event collection is enabled for the system.
84-
*/
85-
public boolean isGaugeAndEventCollectionEnabled() {
86-
return isGaugeAndEventCollectionEnabled;
87-
}
88-
8983
/** Returns if the current session is verbose or not. */
9084
public boolean isVerbose() {
9185
return isGaugeAndEventCollectionEnabled;

firebase-perf/src/main/java/com/google/firebase/perf/session/SessionManager.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.firebase.perf.application.AppStateMonitor;
2222
import com.google.firebase.perf.logging.FirebaseSessionsEnforcementCheck;
2323
import com.google.firebase.perf.session.gauges.GaugeManager;
24-
import com.google.firebase.perf.v1.ApplicationProcessState;
2524
import com.google.firebase.perf.v1.GaugeMetadata;
2625
import com.google.firebase.perf.v1.GaugeMetric;
2726
import java.lang.ref.WeakReference;
@@ -37,7 +36,6 @@ public class SessionManager {
3736
private static final SessionManager instance = new SessionManager();
3837

3938
private final GaugeManager gaugeManager;
40-
private final AppStateMonitor appStateMonitor;
4139
private final Set<WeakReference<SessionAwareObject>> clients = new HashSet<>();
4240

4341
private PerfSession perfSession;
@@ -50,22 +48,21 @@ public static SessionManager getInstance() {
5048
/** Returns the currently active PerfSession. */
5149
public final PerfSession perfSession() {
5250
FirebaseSessionsEnforcementCheck.checkSession(
53-
perfSession, "Access perf session from manger without aqs ready");
51+
perfSession, "PerfSession.perfSession()");
5452

5553
return perfSession;
5654
}
5755

5856
private SessionManager() {
5957
// session should quickly updated by session subscriber.
60-
this(GaugeManager.getInstance(), PerfSession.createWithId(null), AppStateMonitor.getInstance());
58+
this(GaugeManager.getInstance(), PerfSession.createWithId(null));
6159
}
6260

6361
@VisibleForTesting
6462
public SessionManager(
65-
GaugeManager gaugeManager, PerfSession perfSession, AppStateMonitor appStateMonitor) {
63+
GaugeManager gaugeManager, PerfSession perfSession) {
6664
this.gaugeManager = gaugeManager;
6765
this.perfSession = perfSession;
68-
this.appStateMonitor = appStateMonitor;
6966
}
7067

7168
/**
@@ -84,7 +81,7 @@ public void setApplicationContext(final Context appContext) {
8481
public void stopGaugeCollectionIfSessionRunningTooLong() {
8582
FirebaseSessionsEnforcementCheck.checkSession(
8683
perfSession,
87-
"Session is not ready while trying to stopGaugeCollectionIfSessionRunningTooLong");
84+
"SessionManager.stopGaugeCollectionIfSessionRunningTooLong");
8885

8986
if (perfSession.isSessionRunningTooLong()) {
9087
gaugeManager.stopCollectingGauges();
@@ -123,7 +120,7 @@ public void updatePerfSession(PerfSession perfSession) {
123120
}
124121

125122
// Start of stop the gauge data collection.
126-
startOrStopCollectingGauges(appStateMonitor.getAppState());
123+
startOrStopCollectingGauges();
127124
}
128125

129126
/**
@@ -133,7 +130,7 @@ public void updatePerfSession(PerfSession perfSession) {
133130
* this does not reset the perfSession.
134131
*/
135132
public void initializeGaugeCollection() {
136-
startOrStopCollectingGauges(ApplicationProcessState.FOREGROUND);
133+
startOrStopCollectingGauges();
137134
}
138135

139136
/**
@@ -160,11 +157,11 @@ public void unregisterForSessionUpdates(WeakReference<SessionAwareObject> client
160157
}
161158
}
162159

163-
private void startOrStopCollectingGauges(ApplicationProcessState appState) {
160+
private void startOrStopCollectingGauges() {
164161
FirebaseSessionsEnforcementCheck.checkSession(
165-
perfSession, "Session is not ready while trying to startOrStopCollectingGauges");
162+
perfSession, "startOrStopCollectingGauges");
166163

167-
if (perfSession.isGaugeAndEventCollectionEnabled()) {
164+
if (perfSession.isVerbose()) {
168165
gaugeManager.startCollectingGauges(perfSession);
169166
} else {
170167
gaugeManager.stopCollectingGauges();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ public void initializeGaugeMetadataManager(Context appContext) {
102102
public void onUpdateAppState(ApplicationProcessState applicationProcessState) {
103103
this.applicationProcessState = applicationProcessState;
104104

105-
if (session == null) {
106-
// If the session is null, it means there's no gauges being collected.
105+
if (session == null || !session.isVerbose()) {
107106
return;
108107
}
109108

110-
stopCollectingGauges();
109+
// If it's a verbose session, start collecting gauges for the new app state.
111110
startCollectingGauges(this.applicationProcessState, session.getTimer());
112111
}
113112

firebase-perf/src/test/java/com/google/firebase/perf/session/PerfSessionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,21 @@ public void testPerfSessionConversionWithoutVerbosity() {
178178
public void testPerfSessionsCreateDisabledGaugeCollectionWhenVerboseSessionForceDisabled() {
179179
forceNonVerboseSession();
180180
PerfSession testPerfSession = createTestSession(1);
181-
assertThat(testPerfSession.isGaugeAndEventCollectionEnabled()).isFalse();
181+
assertThat(testPerfSession.isVerbose()).isFalse();
182182
}
183183

184184
@Test
185185
public void testPerfSessionsCreateDisabledGaugeCollectionWhenSessionsFeatureDisabled() {
186186
forceSessionsFeatureDisabled();
187187
PerfSession testPerfSession = createTestSession(1);
188-
assertThat(testPerfSession.isGaugeAndEventCollectionEnabled()).isFalse();
188+
assertThat(testPerfSession.isVerbose()).isFalse();
189189
}
190190

191191
@Test
192192
public void testPerfSessionsCreateEnablesGaugeCollectionWhenVerboseSessionForceEnabled() {
193193
forceVerboseSession();
194194
PerfSession testPerfSession = PerfSession.createWithId(testSessionId(1));
195-
assertThat(testPerfSession.isGaugeAndEventCollectionEnabled()).isTrue();
195+
assertThat(testPerfSession.isVerbose()).isTrue();
196196
}
197197

198198
@Test

firebase-perf/src/test/java/com/google/firebase/perf/session/SessionManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testInstanceCreation() {
7373
@Test
7474
public void setApplicationContext_initializeGaugeMetadataManager()
7575
throws ExecutionException, InterruptedException {
76-
when(mockPerfSession.isGaugeAndEventCollectionEnabled()).thenReturn(true);
76+
when(mockPerfSession.isVerbose()).thenReturn(true);
7777
InOrder inOrder = Mockito.inOrder(mockGaugeManager);
7878
SessionManager testSessionManager =
7979
new SessionManager(mockGaugeManager, mockPerfSession, mockAppStateMonitor);

0 commit comments

Comments
 (0)