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

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

Merge "Use elapsedTime for binder/looper debug entries"

parents 882d8fe7 28109b57
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -80,7 +80,8 @@ public class BinderCallsStats implements BinderInternal.Observer {
    private final Queue<CallSession> mCallSessionsPool = new ConcurrentLinkedQueue<>();
    private final Queue<CallSession> mCallSessionsPool = new ConcurrentLinkedQueue<>();
    private final Object mLock = new Object();
    private final Object mLock = new Object();
    private final Random mRandom;
    private final Random mRandom;
    private long mStartTime = System.currentTimeMillis();
    private long mStartCurrentTime = System.currentTimeMillis();
    private long mStartElapsedTime = SystemClock.elapsedRealtime();
    private long mCallStatsCount = 0;
    private long mCallStatsCount = 0;
    private boolean mAddDebugEntries = false;
    private boolean mAddDebugEntries = false;


@@ -329,8 +330,8 @@ public class BinderCallsStats implements BinderInternal.Observer {


        // Debug entries added to help validate the data.
        // Debug entries added to help validate the data.
        if (mAddDebugEntries && mBatteryStopwatch != null) {
        if (mAddDebugEntries && mBatteryStopwatch != null) {
            resultCallStats.add(createDebugEntry("start_time_millis", mStartTime));
            resultCallStats.add(createDebugEntry("start_time_millis", mStartElapsedTime));
            resultCallStats.add(createDebugEntry("end_time_millis", System.currentTimeMillis()));
            resultCallStats.add(createDebugEntry("end_time_millis", SystemClock.elapsedRealtime()));
            resultCallStats.add(
            resultCallStats.add(
                    createDebugEntry("battery_time_millis", mBatteryStopwatch.getMillis()));
                    createDebugEntry("battery_time_millis", mBatteryStopwatch.getMillis()));
        }
        }
@@ -370,7 +371,7 @@ public class BinderCallsStats implements BinderInternal.Observer {
        long totalRecordedCallsCount = 0;
        long totalRecordedCallsCount = 0;
        long totalCpuTime = 0;
        long totalCpuTime = 0;
        pw.print("Start time: ");
        pw.print("Start time: ");
        pw.println(DateFormat.format("yyyy-MM-dd HH:mm:ss", mStartTime));
        pw.println(DateFormat.format("yyyy-MM-dd HH:mm:ss", mStartCurrentTime));
        pw.print("On battery time (ms): ");
        pw.print("On battery time (ms): ");
        pw.println(mBatteryStopwatch != null ? mBatteryStopwatch.getMillis() : 0);
        pw.println(mBatteryStopwatch != null ? mBatteryStopwatch.getMillis() : 0);
        pw.println("Sampling interval period: " + mPeriodicSamplingInterval);
        pw.println("Sampling interval period: " + mPeriodicSamplingInterval);
@@ -520,7 +521,8 @@ public class BinderCallsStats implements BinderInternal.Observer {
            mCallStatsCount = 0;
            mCallStatsCount = 0;
            mUidEntries.clear();
            mUidEntries.clear();
            mExceptionCounts.clear();
            mExceptionCounts.clear();
            mStartTime = System.currentTimeMillis();
            mStartCurrentTime = System.currentTimeMillis();
            mStartElapsedTime = SystemClock.elapsedRealtime();
            if (mBatteryStopwatch != null) {
            if (mBatteryStopwatch != null) {
                mBatteryStopwatch.reset();
                mBatteryStopwatch.reset();
            }
            }
+11 −5
Original line number Original line Diff line number Diff line
@@ -50,7 +50,8 @@ public class LooperStats implements Looper.Observer {
    private int mSamplingInterval;
    private int mSamplingInterval;
    private CachedDeviceState.Readonly mDeviceState;
    private CachedDeviceState.Readonly mDeviceState;
    private CachedDeviceState.TimeInStateStopwatch mBatteryStopwatch;
    private CachedDeviceState.TimeInStateStopwatch mBatteryStopwatch;
    private long mStartTime = System.currentTimeMillis();
    private long mStartCurrentTime = System.currentTimeMillis();
    private long mStartElapsedTime = SystemClock.elapsedRealtime();
    private boolean mAddDebugEntries = false;
    private boolean mAddDebugEntries = false;


    public LooperStats(int samplingInterval, int entriesSizeCap) {
    public LooperStats(int samplingInterval, int entriesSizeCap) {
@@ -155,8 +156,8 @@ public class LooperStats implements Looper.Observer {
        maybeAddSpecialEntry(exportedEntries, mHashCollisionEntry);
        maybeAddSpecialEntry(exportedEntries, mHashCollisionEntry);
        // Debug entries added to help validate the data.
        // Debug entries added to help validate the data.
        if (mAddDebugEntries && mBatteryStopwatch != null) {
        if (mAddDebugEntries && mBatteryStopwatch != null) {
            exportedEntries.add(createDebugEntry("start_time_millis", mStartTime));
            exportedEntries.add(createDebugEntry("start_time_millis", mStartElapsedTime));
            exportedEntries.add(createDebugEntry("end_time_millis", System.currentTimeMillis()));
            exportedEntries.add(createDebugEntry("end_time_millis", SystemClock.elapsedRealtime()));
            exportedEntries.add(
            exportedEntries.add(
                    createDebugEntry("battery_time_millis", mBatteryStopwatch.getMillis()));
                    createDebugEntry("battery_time_millis", mBatteryStopwatch.getMillis()));
        }
        }
@@ -173,7 +174,11 @@ public class LooperStats implements Looper.Observer {


    /** Returns a timestamp indicating when the statistics were last reset. */
    /** Returns a timestamp indicating when the statistics were last reset. */
    public long getStartTimeMillis() {
    public long getStartTimeMillis() {
        return mStartTime;
        return mStartCurrentTime;
    }

    public long getStartElapsedTimeMillis() {
        return mStartElapsedTime;
    }
    }


    public long getBatteryTimeMillis() {
    public long getBatteryTimeMillis() {
@@ -199,7 +204,8 @@ public class LooperStats implements Looper.Observer {
        synchronized (mOverflowEntry) {
        synchronized (mOverflowEntry) {
            mOverflowEntry.reset();
            mOverflowEntry.reset();
        }
        }
        mStartTime = System.currentTimeMillis();
        mStartCurrentTime = System.currentTimeMillis();
        mStartElapsedTime = SystemClock.elapsedRealtime();
        if (mBatteryStopwatch != null) {
        if (mBatteryStopwatch != null) {
            mBatteryStopwatch.reset();
            mBatteryStopwatch.reset();
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;


import android.os.Binder;
import android.os.Binder;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.runner.AndroidJUnit4;
@@ -637,7 +638,7 @@ public class BinderCallsStatsTest {


    @Test
    @Test
    public void testAddsDebugEntries() {
    public void testAddsDebugEntries() {
        long startTime = System.currentTimeMillis();
        long startTime = SystemClock.elapsedRealtime();
        TestBinderCallsStats bcs = new TestBinderCallsStats();
        TestBinderCallsStats bcs = new TestBinderCallsStats();
        bcs.setAddDebugEntries(true);
        bcs.setAddDebugEntries(true);
        ArrayList<BinderCallsStats.ExportedCallStat> callStats = bcs.getExportedCallStats();
        ArrayList<BinderCallsStats.ExportedCallStat> callStats = bcs.getExportedCallStats();
+4 −2
Original line number Original line Diff line number Diff line
@@ -442,11 +442,13 @@ public final class LooperStatsTest {
        LooperStats.ExportedEntry debugEntry1 = entries.get(1);
        LooperStats.ExportedEntry debugEntry1 = entries.get(1);
        assertThat(debugEntry1.handlerClassName).isEqualTo("");
        assertThat(debugEntry1.handlerClassName).isEqualTo("");
        assertThat(debugEntry1.messageName).isEqualTo("__DEBUG_start_time_millis");
        assertThat(debugEntry1.messageName).isEqualTo("__DEBUG_start_time_millis");
        assertThat(debugEntry1.totalLatencyMicros).isEqualTo(looperStats.getStartTimeMillis());
        assertThat(debugEntry1.totalLatencyMicros).isEqualTo(
                looperStats.getStartElapsedTimeMillis());
        LooperStats.ExportedEntry debugEntry2 = entries.get(2);
        LooperStats.ExportedEntry debugEntry2 = entries.get(2);
        assertThat(debugEntry2.handlerClassName).isEqualTo("");
        assertThat(debugEntry2.handlerClassName).isEqualTo("");
        assertThat(debugEntry2.messageName).isEqualTo("__DEBUG_end_time_millis");
        assertThat(debugEntry2.messageName).isEqualTo("__DEBUG_end_time_millis");
        assertThat(debugEntry2.totalLatencyMicros).isAtLeast(looperStats.getStartTimeMillis());
        assertThat(debugEntry2.totalLatencyMicros).isAtLeast(
                looperStats.getStartElapsedTimeMillis());
        LooperStats.ExportedEntry debugEntry3 = entries.get(3);
        LooperStats.ExportedEntry debugEntry3 = entries.get(3);
        assertThat(debugEntry3.handlerClassName).isEqualTo("");
        assertThat(debugEntry3.handlerClassName).isEqualTo("");
        assertThat(debugEntry3.messageName).isEqualTo("__DEBUG_battery_time_millis");
        assertThat(debugEntry3.messageName).isEqualTo("__DEBUG_battery_time_millis");