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

Commit c218f650 authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Use clock monotonic for AppStartInfo timestamps

Currently timestamps are a mix, need to pick one

Why clock montonic:
- This is what's documented, used of elapsed time is really a bug.
- This is what's used across most of logging, enabling us to be consistent and use available timestmaps (as we already are) more easily.

Also stop using and remove tracker single timestamp methods in favor of using broader one with key specified.

Test: check timestamps via shell command
Bug: 338637327
Flag: EXEMPT - day-to-day bugfix
Change-Id: Id3f242cf717c967d94e813ef3ee63ede2a374068
parent 7f879f8e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -4778,7 +4778,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            checkTime(startTime, "attachApplicationLocked: immediately before bindApplication");
            bindApplicationTimeMillis = SystemClock.uptimeMillis();
            bindApplicationTimeNanos = SystemClock.elapsedRealtimeNanos();
            bindApplicationTimeNanos = SystemClock.uptimeNanos();
            mAtmInternal.preBindApplication(app.getWindowProcessController());
            final ActiveInstrumentation instr2 = app.getActiveInstrumentation();
            if (mPlatformCompat != null) {
@@ -4848,7 +4848,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            app.setBindApplicationTime(bindApplicationTimeMillis);
            mProcessList.getAppStartInfoTracker()
                    .reportBindApplicationTimeNanos(app, bindApplicationTimeNanos);
                    .addTimestampToStart(app, bindApplicationTimeNanos,
                            ApplicationStartInfo.START_TIMESTAMP_BIND_APPLICATION);
            // Make app active after binding application or client may be running requests (e.g
            // starting activities) before it is ready.
@@ -14314,7 +14315,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    // activity manager to announce its creation.
    public boolean bindBackupAgent(String packageName, int backupMode, int targetUserId,
            @BackupDestination int backupDestination) {
        long startTimeNs = SystemClock.elapsedRealtimeNanos();
        long startTimeNs = SystemClock.uptimeNanos();
        if (DEBUG_BACKUP) {
            Slog.v(TAG, "bindBackupAgent: app=" + packageName + " mode=" + backupMode
                    + " targetUserId=" + targetUserId + " callingUid = " + Binder.getCallingUid()
@@ -19413,7 +19414,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                    // If the process is known as top app, set a hint so when the process is
                    // started, the top priority can be applied immediately to avoid cpu being
                    // preempted by other processes before attaching the process of top app.
                    final long startTimeNs = SystemClock.elapsedRealtimeNanos();
                    HostingRecord hostingRecord =
                            new HostingRecord(hostingType, hostingName, isTop);
                    ProcessRecord rec = getProcessRecordLocked(processName, info.uid);
+3 −38
Original line number Diff line number Diff line
@@ -424,14 +424,6 @@ public final class AppStartInfoTracker {
        }
    }

    void reportApplicationOnCreateTimeNanos(ProcessRecord app, long timeNs) {
        if (!mEnabled) {
            return;
        }
        addTimestampToStart(app, timeNs,
                ApplicationStartInfo.START_TIMESTAMP_APPLICATION_ONCREATE);
    }

    /**
     * Helper functions for monitoring shell command.
     * > adb shell am start-info-detailed-monitoring [package-name]
@@ -466,41 +458,14 @@ public final class AppStartInfoTracker {
        }
    }

    /** Report a bind application timestamp to add to {@link ApplicationStartInfo}. */
    public void reportBindApplicationTimeNanos(ProcessRecord app, long timeNs) {
        addTimestampToStart(app, timeNs,
                ApplicationStartInfo.START_TIMESTAMP_BIND_APPLICATION);
    }

    void reportFirstFrameTimeNanos(ProcessRecord app, long timeNs) {
        if (!mEnabled) {
            return;
        }
        addTimestampToStart(app, timeNs,
                ApplicationStartInfo.START_TIMESTAMP_FIRST_FRAME);
    }

    void reportFullyDrawnTimeNanos(ProcessRecord app, long timeNs) {
        if (!mEnabled) {
            return;
        }
        addTimestampToStart(app, timeNs,
                ApplicationStartInfo.START_TIMESTAMP_FULLY_DRAWN);
    void addTimestampToStart(ProcessRecord app, long timeNs, int key) {
        addTimestampToStart(app.info.packageName, app.uid, timeNs, key);
    }

    void reportFullyDrawnTimeNanos(String processName, int uid, long timeNs) {
    void addTimestampToStart(String packageName, int uid, long timeNs, int key) {
        if (!mEnabled) {
            return;
        }
        addTimestampToStart(processName, uid, timeNs,
                ApplicationStartInfo.START_TIMESTAMP_FULLY_DRAWN);
    }

    private void addTimestampToStart(ProcessRecord app, long timeNs, int key) {
        addTimestampToStart(app.info.packageName, app.uid, timeNs, key);
    }

    void addTimestampToStart(String packageName, int uid, long timeNs, int key) {
        synchronized (mLock) {
            AppStartInfoContainer container = mData.get(packageName, uid);
            if (container == null) {
+2 −2
Original line number Diff line number Diff line
@@ -1021,6 +1021,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        final boolean allowWhileBooting = (r.intent.getFlags()
                & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0;

        long startTimeNs = SystemClock.uptimeNanos();
        if (DEBUG_BROADCAST) logv("Scheduling " + r + " to cold " + queue);
        queue.app = mService.startProcessLocked(queue.processName, info, true, intentFlags,
                hostingRecord, zygotePolicyFlags, allowWhileBooting, false);
@@ -1032,8 +1033,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        }
        // TODO: b/335420031 - cache receiver intent to avoid multiple calls to getReceiverIntent.
        mService.mProcessList.getAppStartInfoTracker().handleProcessBroadcastStart(
                SystemClock.elapsedRealtimeNanos(), queue.app, r.getReceiverIntent(receiver),
                r.alarm /* isAlarm */);
                startTimeNs, queue.app, r.getReceiverIntent(receiver), r.alarm /* isAlarm */);
        return false;
    }

+2 −2
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ public class ContentProviderHelper {
        final int expectedUserId = userId;
        synchronized (mService) {
            long startTime = SystemClock.uptimeMillis();
            long startElapsedTimeNs = SystemClock.elapsedRealtimeNanos();
            long startTimeNs = SystemClock.uptimeNanos();

            ProcessRecord r = null;
            if (caller != null) {
@@ -587,7 +587,7 @@ public class ContentProviderHelper {
                                    firstLaunch,
                                    0L /* TODO: stoppedDuration */);
                            mService.mProcessList.getAppStartInfoTracker()
                                    .handleProcessContentProviderStart(startElapsedTimeNs, proc);
                                    .handleProcessContentProviderStart(startTimeNs, proc);
                        }
                        cpr.launchingApp = proc;
                        mLaunchingProviders.add(cpr);