Skip to content

Commit e3d7a65

Browse files
committed
better name and comments
1 parent 39269a5 commit e3d7a65

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

firebase-perf/dev-app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
android:name="fragment_sampling_percentage"
4040
android:value="100.0" />
4141
<meta-data
42-
android:name="experiment_as_ttid"
42+
android:name="experiment_app_start_ttid"
4343
android:value="true" />
4444

4545
<receiver

firebase-perf/src/main/java/com/google/firebase/perf/config/ConfigResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ public float getFragmentSamplingRate() {
768768
return config.getDefault();
769769
}
770770

771-
/** Returns if _experiment_as_ttid should be captured. */
771+
/** Returns if _experiment_app_start_ttid should be captured. */
772772
public boolean getIsExperimentTTIDEnabled() {
773773
// Order of precedence is:
774774
// 1. If the value exists in Android Manifest, return this value.

firebase-perf/src/main/java/com/google/firebase/perf/config/ConfigurationConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ protected Boolean getDefault() {
683683

684684
@Override
685685
protected String getRemoteConfigFlag() {
686-
return "fpr_experiment_as_ttid";
686+
return "fpr_experiment_app_start_ttid";
687687
}
688688

689689
@Override
@@ -693,7 +693,7 @@ protected String getDeviceCacheFlag() {
693693

694694
@Override
695695
protected String getMetadataFlag() {
696-
return "experiment_as_ttid";
696+
return "experiment_app_start_ttid";
697697
}
698698
}
699699
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ public synchronized void onActivityResumed(Activity activity) {
248248
}
249249

250250
// Shadow-launch experiment of new app start time
251-
if (configResolver.getIsExperimentTTIDEnabled()) {
251+
final boolean isExperimentTTIDEnabled = configResolver.getIsExperimentTTIDEnabled();
252+
if (isExperimentTTIDEnabled) {
252253
View rootView = activity.findViewById(android.R.id.content);
253254
FirstDrawDoneListener.registerForNextDraw(rootView, this::recordFirstDrawDone);
254255
}
@@ -272,12 +273,17 @@ public synchronized void onActivityResumed(Activity activity) {
272273

273274
// Log the app start trace in a non-main thread.
274275
executorService.execute(this::logAppStartTrace);
276+
277+
if (!isExperimentTTIDEnabled && isRegisteredForLifecycleCallbacks) {
278+
// After AppStart trace is logged, we can unregister this callback.
279+
unregisterActivityLifecycleCallbacks();
280+
}
275281
}
276282

277283
private void logColdStart(Timer start, Timer end, PerfSession session) {
278284
TraceMetric.Builder metric =
279285
TraceMetric.newBuilder()
280-
.setName("_experiment_as_ttid")
286+
.setName("_experiment_app_start_ttid")
281287
.setClientStartTimeUs(start.getMicros())
282288
.setDurationUs(start.getDurationMicros(end));
283289

firebase-perf/src/test/java/com/google/firebase/perf/metrics/AppStartTraceTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,16 @@ public void testFirebasePerfProviderOnAttachInfo_initializesGaugeCollection() {
283283
@Test
284284
@Config(sdk = 26)
285285
public void timeToInitialDisplay_isLogged() {
286+
// Test setup
286287
when(clock.getTime()).thenCallRealMethod(); // Use robolectric shadows to manipulate time
287-
long appStartTime = TimeUnit.MILLISECONDS.toMicros(Process.getStartElapsedRealtime());
288288
View testView = new View(ApplicationProvider.getApplicationContext());
289289
when(activity1.findViewById(android.R.id.content)).thenReturn(testView);
290290
when(configResolver.getIsExperimentTTIDEnabled()).thenReturn(true);
291291
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
292292
AppStartTrace trace =
293293
new AppStartTrace(transportManager, clock, configResolver, fakeExecutorService);
294294

295+
// Simulate resume and manually stepping time forward
295296
ShadowSystemClock.advanceBy(Duration.ofMillis(1000));
296297
long resumeTime = TimeUnit.NANOSECONDS.toMicros(SystemClock.elapsedRealtimeNanos());
297298
trace.onActivityCreated(activity1, bundle);
@@ -300,6 +301,8 @@ public void timeToInitialDisplay_isLogged() {
300301
fakeExecutorService.runAll();
301302
verify(transportManager, times(1))
302303
.log(isA(TraceMetric.class), isA(ApplicationProcessState.class));
304+
305+
// Simulate draw and manually stepping time forward
303306
ShadowSystemClock.advanceBy(Duration.ofMillis(1000));
304307
long drawTime = TimeUnit.NANOSECONDS.toMicros(SystemClock.elapsedRealtimeNanos());
305308
testView.getViewTreeObserver().dispatchOnDraw();
@@ -308,8 +311,10 @@ public void timeToInitialDisplay_isLogged() {
308311
verify(transportManager, times(2))
309312
.log(traceArgumentCaptor.capture(), isA(ApplicationProcessState.class));
310313

314+
// Verify ttid trace is being logged
311315
TraceMetric ttid = traceArgumentCaptor.getValue();
312-
assertThat(ttid.getName()).isEqualTo("_experiment_as_ttid");
316+
long appStartTime = TimeUnit.MILLISECONDS.toMicros(Process.getStartElapsedRealtime());
317+
assertThat(ttid.getName()).isEqualTo("_experiment_app_start_ttid");
313318
assertThat(ttid.getDurationUs()).isNotEqualTo(resumeTime - appStartTime);
314319
assertThat(ttid.getDurationUs()).isEqualTo(drawTime - appStartTime);
315320
}

0 commit comments

Comments
 (0)