Skip to content

Fireperf: start screen trace in onResume #3532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,7 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
public void onActivityDestroyed(Activity activity) {}

@Override
public synchronized void onActivityStarted(Activity activity) {
if (isScreenTraceSupported(activity) && configResolver.isPerformanceMonitoringEnabled()) {
// Starts recording frame metrics for this activity.
/**
* TODO: Only add activities that are hardware acceleration enabled so that calling {@link
* FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
*/
frameMetricsAggregator.add(activity);
// Start the Trace
Trace screenTrace = new Trace(getScreenTraceName(activity), transportManager, clock, this);
screenTrace.start();
activityToScreenTraceMap.put(activity, screenTrace);
}
}
public synchronized void onActivityStarted(Activity activity) {}

@Override
public synchronized void onActivityStopped(Activity activity) {
Expand All @@ -181,7 +168,8 @@ public synchronized void onActivityResumed(Activity activity) {
// cases:
// 1. At app startup, first activity comes to foreground.
// 2. app switch from background to foreground.
// 3. app already in foreground, current activity is replaced by another activity.
// 3. app already in foreground, current activity is replaced by another activity, or the
// current activity was paused then resumed without onStop, for example by an AlertDialog
if (activityToResumedMap.isEmpty()) {
// The first resumed activity means app comes to foreground.
resumeTime = clock.getTime();
Expand All @@ -198,9 +186,24 @@ public synchronized void onActivityResumed(Activity activity) {
updateAppState(ApplicationProcessState.FOREGROUND);
}
} else {
// case 3: app already in foreground, current activity is replaced by another activity.
// case 3: app already in foreground, current activity is replaced by another activity, or the
// current activity was paused then resumed without onStop, for example by an AlertDialog
activityToResumedMap.put(activity, true);
}

// Screen trace is after session update so the sessionId is not added twice to the Trace
if (isScreenTraceSupported(activity) && configResolver.isPerformanceMonitoringEnabled()) {
// Starts recording frame metrics for this activity.
/**
* TODO: Only add activities that are hardware acceleration enabled so that calling {@link
* FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
*/
frameMetricsAggregator.add(activity);
// Start the Trace
Trace screenTrace = new Trace(getScreenTraceName(activity), transportManager, clock, this);
screenTrace.start();
activityToScreenTraceMap.put(activity, screenTrace);
}
}

/** Returns if this is the cold start of the app. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public void screenTrace_twoActivities_traceStartedAndStoppedWithActivityLifecycl
int startTime = i * 100;
int endTime = startTime + 10;
currentTime = startTime;
monitor.onActivityStarted(activity);
monitor.onActivityResumed(activity);
assertThat(monitor.getActivity2ScreenTrace()).hasSize(1);
currentTime = endTime;
monitor.onActivityPostPaused(activity);
Expand Down Expand Up @@ -418,7 +418,7 @@ public void screenTrace_perfMonEnabledSwitchAtRuntime_traceCreationDependsOnRunt

// Assert that screen trace has been created.
currentTime = 100;
monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
monitor.onActivityResumed(activityWithNonHardwareAcceleratedView);
assertThat(monitor.getActivity2ScreenTrace()).hasSize(1);
currentTime = 200;
monitor.onActivityPostPaused(activityWithNonHardwareAcceleratedView);
Expand Down