Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7907f456 authored by Olivier Gaillard's avatar Olivier Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Add atoms for app startup time."

parents 345d957f aed7f12d
Loading
Loading
Loading
Loading
+97 −0
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@ message Atom {
        DropboxErrorChanged dropbox_error_changed = 45;
        AnomalyDetected anomaly_detected = 46;
        AppHook app_hook = 47;
        AppStartChanged app_start_changed = 48;
        AppStartCancelChanged app_start_cancel_changed = 49;
        AppStartFullyDrawnChanged app_start_fully_drawn_changed = 50;
        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }

@@ -855,6 +858,100 @@ message AnomalyDetected {
    optional int64 alert_id = 3;
}

message AppStartChanged {
    // The uid if available. -1 means not available.
    optional int32 uid = 1;

    // The app package name.
    optional string pkg_name = 2;

    enum TransitionType {
        APP_START_TRANSITION_TYPE_UNKNOWN = 0;
        WARM = 1;
        HOT = 2;
        COLD = 3;
    }
    // The transition type.
    optional TransitionType type = 3;

    // The activity name.
    optional string activity_name = 4;

    // The name of the calling app. Empty if not set.
    optional string calling_pkg_name = 5;

    // Whether the app is an instant app.
    optional bool is_instant_app = 6;

    // Device uptime when activity started.
    optional int64 activity_start_msec = 7;

    // TODO: Update android/app/ActivityManagerInternal.java constants to depend on our proto enum.
    enum TransitionReason {
        APP_START_TRANSITION_REASON_UNKNOWN = 0;
        SPLASH_SCREEN = 1;
        WINDOWS_DRAWN = 2;
        TIMEOUT = 3;
        SNAPSHOT = 4;
    }
    optional TransitionReason reason = 8;

    optional int32 transition_delay_msec = 9;
    // -1 if not set.
    optional int32 starting_window_delay_msec = 10;
    // -1 if not set.
    optional int32 bind_application_delay_msec = 11;
    optional int32 windows_drawn_delay_msec = 12;

    // Empty if not set.
    optional string launch_token = 13;

}

message AppStartCancelChanged {
    // The uid if available. -1 means not available.
    optional int32 uid = 1;

    // The app package name.
    optional string pkg_name = 2;

    enum TransitionType {
        APP_START_TRANSITION_TYPE_UNKNOWN = 0;
        WARM = 1;
        HOT = 2;
        COLD = 3;
    }
    // The transition type.
    optional TransitionType type = 3;

    // The activity name.
    optional string activity_name = 4;
}

message AppStartFullyDrawnChanged {
    // The uid if available. -1 means not available.
    optional int32 uid = 1;

    // The app package name.
    optional string pkg_name = 2;

    enum TransitionType {
        APP_START_TRANSITION_TYPE_UNKNOWN = 0;
        WITH_BUNDLE = 1;
        WITHOUT_BUNDLE = 2;
    }
    // The transition type.
    optional TransitionType type = 3;

    // The activity name.
    optional string activity_name = 4;

    optional bool transition_process_running = 5;

    // App startup time (until call to Activity#reportFullyDrawn()).
    optional int64 app_startup_time_ms = 6;
}

/**
 * Pulls bytes transferred via wifi (Sum of foreground and background usage).
 *
+50 −5
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.os.SystemClock;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.StatsLog;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.os.SomeArgs;
@@ -431,6 +432,12 @@ class ActivityMetricsLogger {
        builder.setType(type);
        builder.addTaggedData(FIELD_CLASS_NAME, info.launchedActivity.info.name);
        mMetricsLogger.write(builder);
        StatsLog.write(
                StatsLog.APP_START_CANCEL_CHANGED,
                info.launchedActivity.appInfo.uid,
                info.launchedActivity.packageName,
                convertAppStartTransitionType(type),
                info.launchedActivity.info.name);
    }

    private void logAppTransitionMultiEvents() {
@@ -450,9 +457,9 @@ class ActivityMetricsLogger {
                builder.addTaggedData(APP_TRANSITION_CALLING_PACKAGE_NAME,
                        info.launchedActivity.launchedFromPackage);
            }
            if (info.launchedActivity.info.launchToken != null) {
                builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN,
                        info.launchedActivity.info.launchToken);
            String launchToken = info.launchedActivity.info.launchToken;
            if (launchToken != null) {
                builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN, launchToken);
                info.launchedActivity.info.launchToken = null;
            }
            builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, isInstantApp ? 1 : 0);
@@ -470,9 +477,37 @@ class ActivityMetricsLogger {
            }
            builder.addTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS, info.windowsDrawnDelayMs);
            mMetricsLogger.write(builder);
            StatsLog.write(
                    StatsLog.APP_START_CHANGED,
                    info.launchedActivity.appInfo.uid,
                    info.launchedActivity.packageName,
                    convertAppStartTransitionType(type),
                    info.launchedActivity.info.name,
                    info.launchedActivity.launchedFromPackage,
                    isInstantApp,
                    mCurrentTransitionDeviceUptime * 1000,
                    info.reason,
                    mCurrentTransitionDelayMs,
                    info.startingWindowDelayMs,
                    info.bindApplicationDelayMs,
                    info.windowsDrawnDelayMs,
                    launchToken);
        }
    }

    private int convertAppStartTransitionType(int tronType) {
        if (tronType == TYPE_TRANSITION_COLD_LAUNCH) {
            return StatsLog.APP_START_CHANGED__TYPE__COLD;
        }
        if (tronType == TYPE_TRANSITION_WARM_LAUNCH) {
            return StatsLog.APP_START_CHANGED__TYPE__WARM;
        }
        if (tronType == TYPE_TRANSITION_HOT_LAUNCH) {
            return StatsLog.APP_START_CHANGED__TYPE__HOT;
        }
        return StatsLog.APP_START_CHANGED__TYPE__APP_START_TRANSITION_TYPE_UNKNOWN;
     }

    void logAppTransitionReportedDrawn(ActivityRecord r, boolean restoredFromBundle) {
        final StackTransitionInfo info = mLastStackTransitionInfo.get(r.getStackId());
        if (info == null) {
@@ -481,14 +516,24 @@ class ActivityMetricsLogger {
        final LogMaker builder = new LogMaker(APP_TRANSITION_REPORTED_DRAWN);
        builder.setPackageName(r.packageName);
        builder.addTaggedData(FIELD_CLASS_NAME, r.info.name);
        builder.addTaggedData(APP_TRANSITION_REPORTED_DRAWN_MS,
                SystemClock.uptimeMillis() - mLastTransitionStartTime);
        long startupTimeMs = SystemClock.uptimeMillis() - mLastTransitionStartTime;
        builder.addTaggedData(APP_TRANSITION_REPORTED_DRAWN_MS, startupTimeMs);
        builder.setType(restoredFromBundle
                ? TYPE_TRANSITION_REPORTED_DRAWN_WITH_BUNDLE
                : TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE);
        builder.addTaggedData(APP_TRANSITION_PROCESS_RUNNING,
                info.currentTransitionProcessRunning ? 1 : 0);
        mMetricsLogger.write(builder);
        StatsLog.write(
                StatsLog.APP_START_FULLY_DRAWN_CHANGED,
                info.launchedActivity.appInfo.uid,
                info.launchedActivity.packageName,
                restoredFromBundle
                        ? StatsLog.APP_START_FULLY_DRAWN_CHANGED__TYPE__WITH_BUNDLE
                        : StatsLog.APP_START_FULLY_DRAWN_CHANGED__TYPE__WITHOUT_BUNDLE,
                info.launchedActivity.info.name,
                info.currentTransitionProcessRunning,
                startupTimeMs);
    }

    private int getTransitionType(StackTransitionInfo info) {