Skip to content

Commit b942120

Browse files
committed
Attempt to simplify AQS session usage
1 parent 9731146 commit b942120

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
/** Details of a session including a unique Id and related information. */
3131
public class PerfSession implements Parcelable {
3232

33+
private static final String SESSION_ID_PREFIX = "fireperf-session";
3334
private final String sessionId;
3435
private final Timer creationTime;
3536

@@ -39,16 +40,9 @@ public class PerfSession implements Parcelable {
3940
* Creates a PerfSession object and decides what metrics to collect.
4041
*/
4142
public static PerfSession createNewSession() {
42-
String prunedSessionId = UUID.randomUUID().toString().replace("-", "");
43+
String prunedSessionId = SESSION_ID_PREFIX + UUID.randomUUID().toString().replace("-", "");
4344
PerfSession session = new PerfSession(prunedSessionId, new Clock());
4445
session.setGaugeAndEventCollectionEnabled(shouldCollectGaugesAndEvents());
45-
46-
// Every time a PerfSession is created, it sets the AQS to null. Once an AQS is received,
47-
// SessionManagerKt verifies if this is an active session, and sets the AQS session ID.
48-
// The assumption is that new PerfSessions *should* be limited to either App Start, or through
49-
// AQS.
50-
FirebasePerformanceSessionSubscriber.Companion.getInstance().reportPerfSession(prunedSessionId);
51-
5246
return session;
5347
}
5448

@@ -57,6 +51,11 @@ public static PerfSession createNewSession() {
5751
public PerfSession(String sessionId, Clock clock) {
5852
this.sessionId = sessionId;
5953
creationTime = clock.getTime();
54+
// Every time a PerfSession is created, it sets the AQS to null. Once an AQS is received,
55+
// SessionManagerKt verifies if this is an active session, and sets the AQS session ID.
56+
// The assumption is that new PerfSessions *should* be limited to either App Start, or through
57+
// AQS.
58+
FirebasePerformanceSessionSubscriber.Companion.getInstance().reportPerfSession(sessionId);
6059
}
6160

6261
private PerfSession(@NonNull Parcel in) {
@@ -71,6 +70,11 @@ public String sessionId() {
7170
return this.sessionId;
7271
}
7372

73+
private String aqsSessionId() {
74+
return FirebasePerformanceSessionSubscriber.Companion.getInstance()
75+
.getAqsMappedToPerfSession(this.sessionId);
76+
}
77+
7478
/**
7579
* Returns a timer object that has been seeded with the system time at which the session began.
7680
*/
@@ -121,7 +125,7 @@ public boolean isSessionRunningTooLong() {
121125
/** Creates and returns the proto object for PerfSession object. */
122126
public com.google.firebase.perf.v1.PerfSession build() {
123127
com.google.firebase.perf.v1.PerfSession.Builder sessionMetric =
124-
com.google.firebase.perf.v1.PerfSession.newBuilder().setSessionId(sessionId());
128+
com.google.firebase.perf.v1.PerfSession.newBuilder().setSessionId(aqsSessionId());
125129

126130
// If gauge collection is enabled, enable gauge collection verbosity.
127131
if (isGaugeAndEventCollectionEnabled) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ public void stopGaugeCollectionIfSessionRunningTooLong() {
113113
*/
114114
public void updatePerfSession(PerfSession perfSession) {
115115
// Do not update the perf session if it is the exact same sessionId.
116-
if (Objects.equals(
117-
perfSession.sessionId(), this.perfSession.sessionId())) {
116+
if (Objects.equals(perfSession.sessionId(), this.perfSession.sessionId())) {
118117
return;
119118
}
120119

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.firebase.components.Lazy;
2323
import com.google.firebase.perf.config.ConfigResolver;
2424
import com.google.firebase.perf.logging.AndroidLogger;
25+
import com.google.firebase.perf.session.FirebasePerformanceSessionSubscriber;
2526
import com.google.firebase.perf.session.PerfSession;
2627
import com.google.firebase.perf.transport.TransportManager;
2728
import com.google.firebase.perf.util.Timer;
@@ -242,7 +243,10 @@ private void syncFlush(String sessionId, ApplicationProcessState appState) {
242243
}
243244

244245
// Adding Session ID info.
245-
gaugeMetricBuilder.setSessionId(sessionId);
246+
String aqsSessionId =
247+
FirebasePerformanceSessionSubscriber.Companion.getInstance()
248+
.getAqsMappedToPerfSession(sessionId);
249+
gaugeMetricBuilder.setSessionId(aqsSessionId);
246250

247251
transportManager.log(gaugeMetricBuilder.build(), appState);
248252
}
@@ -256,10 +260,13 @@ private void syncFlush(String sessionId, ApplicationProcessState appState) {
256260
* @return true if GaugeMetadata was logged, false otherwise.
257261
*/
258262
public boolean logGaugeMetadata(String sessionId, ApplicationProcessState appState) {
263+
String aqsSessionId =
264+
FirebasePerformanceSessionSubscriber.Companion.getInstance()
265+
.getAqsMappedToPerfSession(sessionId);
259266
if (gaugeMetadataManager != null) {
260267
GaugeMetric gaugeMetric =
261268
GaugeMetric.newBuilder()
262-
.setSessionId(sessionId)
269+
.setSessionId(aqsSessionId)
263270
.setGaugeMetadata(getGaugeMetadata())
264271
.build();
265272
transportManager.log(gaugeMetric, appState);

0 commit comments

Comments
 (0)