Skip to content

Commit 45f6252

Browse files
committed
Switch AQS ID to an always known ID
1 parent 51f5648 commit 45f6252

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfEarly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.firebase.perf.config.ConfigResolver;
2323
import com.google.firebase.perf.metrics.AppStartTrace;
2424
import com.google.firebase.perf.session.SessionManager;
25-
2625
import java.util.concurrent.Executor;
2726

2827
/**
@@ -55,6 +54,7 @@ public FirebasePerfEarly(
5554
// In the case of cold start, we create a session and start collecting gauges as early as
5655
// possible.
5756
// Uploading the gauges however only starts once AQS is initialized.
57+
// TODO(b/394127311): Update this to use changes in AQS initialization,
5858
SessionManager.getInstance().initializeGaugeCollection();
5959
}
6060
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.firebase.perf.session
1818

1919
import com.google.firebase.perf.session.gauges.GaugeManager
20+
import com.google.firebase.perf.util.Constants
2021
import com.google.firebase.perf.v1.ApplicationProcessState
2122
import com.google.firebase.sessions.api.SessionSubscriber
2223
import java.util.UUID
@@ -32,18 +33,19 @@ class FirebasePerformanceSessionSubscriber(override val isDataCollectionEnabled:
3233
val gaugeManager = GaugeManager.getInstance()
3334

3435
// A [PerfSession] was created before a session was started.
35-
if (currentPerfSession.aqsSessionId() == null) {
36+
if (currentPerfSession.aqsSessionId().equals(Constants.UNDEFINED_AQS_ID)) {
3637
currentPerfSession.setAQSId(sessionDetails)
37-
gaugeManager
38-
.logGaugeMetadata(currentPerfSession.aqsSessionId(), ApplicationProcessState.FOREGROUND)
38+
gaugeManager.logGaugeMetadata(
39+
currentPerfSession.aqsSessionId(),
40+
ApplicationProcessState.FOREGROUND
41+
)
3942
gaugeManager.updateGaugeCollection(ApplicationProcessState.FOREGROUND)
4043
return
4144
}
4245

4346
val updatedSession = PerfSession.createWithId(UUID.randomUUID().toString())
4447
updatedSession.setAQSId(sessionDetails)
4548
sessionManager.updatePerfSession(updatedSession)
46-
gaugeManager
47-
.logGaugeMetadata(updatedSession.aqsSessionId(), ApplicationProcessState.FOREGROUND)
49+
gaugeManager.logGaugeMetadata(updatedSession.aqsSessionId(), ApplicationProcessState.FOREGROUND)
4850
}
4951
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import androidx.annotation.VisibleForTesting;
2222
import com.google.firebase.perf.config.ConfigResolver;
2323
import com.google.firebase.perf.util.Clock;
24+
import com.google.firebase.perf.util.Constants;
2425
import com.google.firebase.perf.util.Timer;
2526
import com.google.firebase.perf.v1.SessionVerbosity;
2627
import com.google.firebase.sessions.api.SessionSubscriber;
@@ -32,7 +33,8 @@ public class PerfSession implements Parcelable {
3233

3334
private final String sessionId;
3435
private final Timer creationTime;
35-
@Nullable private String aqsSessionId;
36+
// TODO(b/394127311): Remove this once this isn't needed.
37+
private String aqsSessionId = Constants.UNDEFINED_AQS_ID;
3638

3739
private boolean isGaugeAndEventCollectionEnabled = false;
3840

@@ -67,14 +69,13 @@ public String sessionId() {
6769
}
6870

6971
/** Returns the AQS sessionId for the given session. */
70-
@Nullable
7172
public String aqsSessionId() {
7273
return aqsSessionId;
7374
}
7475

7576
/** Sets the AQS sessionId for the given session. */
7677
public void setAQSId(SessionSubscriber.SessionDetails aqs) {
77-
if (aqsSessionId == null) {
78+
if (aqsSessionId.equals(Constants.UNDEFINED_AQS_ID)) {
7879
aqsSessionId = aqs.getSessionId();
7980
}
8081
}

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
@@ -24,6 +24,7 @@
2424
import com.google.firebase.perf.logging.AndroidLogger;
2525
import com.google.firebase.perf.session.PerfSession;
2626
import com.google.firebase.perf.transport.TransportManager;
27+
import com.google.firebase.perf.util.Constants;
2728
import com.google.firebase.perf.util.Timer;
2829
import com.google.firebase.perf.v1.AndroidMemoryReading;
2930
import com.google.firebase.perf.v1.ApplicationProcessState;
@@ -112,7 +113,7 @@ public void updateGaugeCollection(ApplicationProcessState applicationProcessStat
112113

113114
if (session == null
114115
|| !session.isGaugeAndEventCollectionEnabled()
115-
|| session.aqsSessionId() == null) {
116+
|| session.aqsSessionId().equals(Constants.UNDEFINED_AQS_ID)) {
116117
logger.warn("Not starting gauge collection.");
117118
stopCollectingGauges();
118119
return;
@@ -124,7 +125,6 @@ public void updateGaugeCollection(ApplicationProcessState applicationProcessStat
124125
getMemoryGaugeCollectionFrequencyMs(applicationProcessState));
125126
String sessionIdForScheduledTask = session.aqsSessionId();
126127

127-
// TODO(b/394127311): Switch to using AQS.
128128
try {
129129
gaugeManagerDataCollectionJob =
130130
gaugeManagerExecutor
@@ -272,7 +272,6 @@ private void syncFlush(String sessionId, ApplicationProcessState appState) {
272272
}
273273

274274
// Adding Session ID info.
275-
// TODO(b/394127311): Switch to using AQS.
276275
gaugeMetricBuilder.setSessionId(sessionId);
277276

278277
transportManager.log(gaugeMetricBuilder.build(), appState);

firebase-perf/src/main/java/com/google/firebase/perf/util/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Constants {
2222
public static final String PREFS_NAME = "FirebasePerfSharedPrefs";
2323
public static final String ENABLE_DISABLE = "isEnabled";
2424

25+
public static final String UNDEFINED_AQS_ID = "_uaqsid";
26+
2527
public static final double MIN_SAMPLING_RATE = 0.0;
2628
public static final double MAX_SAMPLING_RATE = 1.0;
2729

0 commit comments

Comments
 (0)