Home » Android » android – What does "I/ActivityManager: Displayed…activity…+850ms" comprised of?

android – What does "I/ActivityManager: Displayed…activity…+850ms" comprised of?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m trying to improve display time of my app’s activity.
I’m using logcat to track my activity display time.

Here is an example of a logcat output:

I/ActivityManager( 1097): Displayed com.example.myapp/com.example.myapp.activity.TutorialActivity: +850ms (total +1s503ms)

Can someone tell me how does the activity manager concludes this is the time takes to diplay the activity?
What happens during this time and what does this time takes into account?
And what is the difference between the “normal time” and “total time”?

I tried to find materials on the matter but no success..

Thank’s in advance!

How to&Answers:

This line is printed in com.android.server.am.ActivityRecord.reportLaunchTimeLocked:

private void reportLaunchTimeLocked(final long curTime) {
    final ActivityStack stack = task.stack;
    final long thisTime = curTime - displayStartTime;
    final long totalTime = stack.mLaunchStartTime != 0
            ? (curTime - stack.mLaunchStartTime) : thisTime;
    if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
        Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
        EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
                userId, System.identityHashCode(this), shortComponentName,
                thisTime, totalTime);
        StringBuilder sb = service.mStringBuilder;
        sb.setLength(0);
        sb.append("Displayed ");
        sb.append(shortComponentName);
        sb.append(": ");
        TimeUtils.formatDuration(thisTime, sb);
        if (thisTime != totalTime) {
            sb.append(" (total ");
            TimeUtils.formatDuration(totalTime, sb);
            sb.append(")");
        }
        Log.i(ActivityManagerService.TAG, sb.toString());
    }
    mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
    if (totalTime > 0) {
        //service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
    }
    displayStartTime = 0;
    stack.mLaunchStartTime = 0;
}

“normal time” is basically the time spent between the Activity is about to be launched and the content view of the Activity is drawn (includes drawing time).

“total time” includes “normal time” and also takes into account the time spent to launch previous Activitys.

Normally, “normal time” is identical to “total time”. You can see from the source code

if (thisTime != totalTime) {
       sb.append(" (total ");
       TimeUtils.formatDuration(totalTime, sb);
       sb.append(")");
 }

the “total time” will be printed only when it is different from “normal time”. Usually, If Activity B is launched in onCreate of Activity A, the “normal time” of Activity B will be different from “total time”.