Skip to content

Commit cbe7176

Browse files
Incorporate comments
1 parent d3167a5 commit cbe7176

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

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

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.android.gms.common.util.VisibleForTesting;
2626
import com.google.firebase.perf.logging.AndroidLogger;
2727
import com.google.firebase.perf.provider.FirebasePerfProvider;
28+
import com.google.firebase.perf.session.PerfSession;
2829
import com.google.firebase.perf.session.SessionManager;
2930
import com.google.firebase.perf.transport.TransportManager;
3031
import com.google.firebase.perf.util.Clock;
@@ -65,6 +66,33 @@ public class AppStartTrace implements ActivityLifecycleCallbacks {
6566
private static volatile AppStartTrace instance;
6667
private static ExecutorService executorService;
6768

69+
private boolean isRegisteredForLifecycleCallbacks = false;
70+
private final TransportManager transportManager;
71+
private final Clock clock;
72+
private Context appContext;
73+
/**
74+
* The first time onCreate() of any activity is called, the activity is saved as launchActivity.
75+
*/
76+
private WeakReference<Activity> launchActivity;
77+
/**
78+
* The first time onResume() of any activity is called, the activity is saved as appStartActivity
79+
*/
80+
private WeakReference<Activity> appStartActivity;
81+
82+
/**
83+
* If the time difference between app starts and creation of any Activity is larger than
84+
* MAX_LATENCY_BEFORE_UI_INIT, set mTooLateToInitUI to true and we don't send AppStart Trace.
85+
*/
86+
private boolean isTooLateToInitUI = false;
87+
88+
private Timer appStartTime = null;
89+
private Timer onCreateTime = null;
90+
private Timer onStartTime = null;
91+
private Timer onResumeTime = null;
92+
93+
private PerfSession startSession;
94+
private boolean isStartedFromBackground = false;
95+
6896
/**
6997
* Called from onCreate() method of an activity by instrumented byte code.
7098
*
@@ -118,32 +146,6 @@ static AppStartTrace getInstance(TransportManager transportManager, Clock clock)
118146
return instance;
119147
}
120148

121-
private boolean isRegisteredForLifecycleCallbacks = false;
122-
private final TransportManager transportManager;
123-
private final Clock clock;
124-
private Context appContext;
125-
/**
126-
* The first time onCreate() of any activity is called, the activity is saved as launchActivity.
127-
*/
128-
private WeakReference<Activity> launchActivity;
129-
/**
130-
* The first time onResume() of any activity is called, the activity is saved as appStartActivity
131-
*/
132-
private WeakReference<Activity> appStartActivity;
133-
134-
/**
135-
* If the time difference between app starts and creation of any Activity is larger than
136-
* MAX_LATENCY_BEFORE_UI_INIT, set mTooLateToInitUI to true and we don't send AppStart Trace.
137-
*/
138-
private boolean isTooLateToInitUI = false;
139-
140-
private Timer appStartTime = null;
141-
private Timer onCreateTime = null;
142-
private Timer onStartTime = null;
143-
private Timer onResumeTime = null;
144-
145-
private boolean isStartedFromBackground = false;
146-
147149
AppStartTrace(
148150
@NonNull TransportManager transportManager,
149151
@NonNull Clock clock,
@@ -214,6 +216,7 @@ public synchronized void onActivityResumed(Activity activity) {
214216

215217
onResumeTime = clock.getTime();
216218
this.appStartTime = FirebasePerfProvider.getAppStartTime();
219+
this.startSession = SessionManager.getInstance().perfSession();
217220
AndroidLogger.getInstance()
218221
.debug(
219222
"onResume(): "
@@ -260,9 +263,7 @@ private void logAppStartTrace() {
260263
.setDurationUs(onStartTime.getDurationMicros(onResumeTime));
261264
subtraces.add(traceMetricBuilder.build());
262265

263-
metric
264-
.addAllSubtraces(subtraces)
265-
.addPerfSessions(SessionManager.getInstance().perfSession().build());
266+
metric.addAllSubtraces(subtraces).addPerfSessions(this.startSession.build());
266267

267268
transportManager.log(metric.build(), ApplicationProcessState.FOREGROUND_BACKGROUND);
268269
}

0 commit comments

Comments
 (0)