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

Commit aeda457c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use System.nanoTime instead of SystemClock for benchmarks" into main

parents a7cb2966 bf161c04
Loading
Loading
Loading
Loading
+16 −18
Original line number Original line Diff line number Diff line
@@ -249,9 +249,9 @@ public class VibratorPerfTest {
        long elapsedTimeNs = 0;
        long elapsedTimeNs = 0;
        ManualBenchmarkState state = mStatusReporter.getBenchmarkState();
        ManualBenchmarkState state = mStatusReporter.getBenchmarkState();
        while (state.keepRunning(elapsedTimeNs)) {
        while (state.keepRunning(elapsedTimeNs)) {
            long startTimeNs = SystemClock.elapsedRealtimeNanos();
            long startTimeNs = System.nanoTime();
            mVibrator.areEffectsSupported(effects);
            mVibrator.areEffectsSupported(effects);
            elapsedTimeNs = SystemClock.elapsedRealtimeNanos() - startTimeNs;
            elapsedTimeNs = System.nanoTime() - startTimeNs;
        }
        }
    }
    }


@@ -263,9 +263,9 @@ public class VibratorPerfTest {
        long elapsedTimeNs = 0;
        long elapsedTimeNs = 0;
        ManualBenchmarkState state = mStatusReporter.getBenchmarkState();
        ManualBenchmarkState state = mStatusReporter.getBenchmarkState();
        while (state.keepRunning(elapsedTimeNs)) {
        while (state.keepRunning(elapsedTimeNs)) {
            long startTimeNs = SystemClock.elapsedRealtimeNanos();
            long startTimeNs = System.nanoTime();
            mVibrator.arePrimitivesSupported(primitives);
            mVibrator.arePrimitivesSupported(primitives);
            elapsedTimeNs = SystemClock.elapsedRealtimeNanos() - startTimeNs;
            elapsedTimeNs = System.nanoTime() - startTimeNs;
        }
        }
    }
    }


@@ -274,9 +274,9 @@ public class VibratorPerfTest {
        long elapsedTimeNs = 0;
        long elapsedTimeNs = 0;
        ManualBenchmarkState state = mStatusReporter.getBenchmarkState();
        ManualBenchmarkState state = mStatusReporter.getBenchmarkState();
        while (state.keepRunning(elapsedTimeNs)) {
        while (state.keepRunning(elapsedTimeNs)) {
            long startTimeNs = SystemClock.elapsedRealtimeNanos();
            long startTimeNs = System.nanoTime();
            mVibrator.cancel();
            mVibrator.cancel();
            elapsedTimeNs = SystemClock.elapsedRealtimeNanos() - startTimeNs;
            elapsedTimeNs = System.nanoTime() - startTimeNs;
        }
        }
    }
    }


@@ -293,9 +293,9 @@ public class VibratorPerfTest {
            mVibrator.vibrate(effect);
            mVibrator.vibrate(effect);
            SystemClock.sleep(SERVICE_DELAY_MS);
            SystemClock.sleep(SERVICE_DELAY_MS);


            long startTimeNs = SystemClock.elapsedRealtimeNanos();
            long startTimeNs = System.nanoTime();
            mVibrator.cancel();
            mVibrator.cancel();
            elapsedTimeNs = SystemClock.elapsedRealtimeNanos() - startTimeNs;
            elapsedTimeNs = System.nanoTime() - startTimeNs;
        }
        }
    }
    }


@@ -358,9 +358,9 @@ public class VibratorPerfTest {
     * become idle before next iteration.
     * become idle before next iteration.
     */
     */
    private long measureVibrate(VibrationEffect effect) {
    private long measureVibrate(VibrationEffect effect) {
        long startTimeNs = SystemClock.elapsedRealtimeNanos();
        long startTimeNs = System.nanoTime();
        mVibrator.vibrate(effect);
        mVibrator.vibrate(effect);
        long latencyNs = SystemClock.elapsedRealtimeNanos() - startTimeNs;
        long latencyNs = System.nanoTime() - startTimeNs;


        // Rate-limiting, stop vibration and wait for service to become idle.
        // Rate-limiting, stop vibration and wait for service to become idle.
        mVibrator.cancel();
        mVibrator.cancel();
@@ -376,9 +376,9 @@ public class VibratorPerfTest {
     * to become idle before next iteration.
     * to become idle before next iteration.
     */
     */
    private long measureVibrateWithTraces(VibrationEffect effect) throws InterruptedException {
    private long measureVibrateWithTraces(VibrationEffect effect) throws InterruptedException {
        long startTimeNs = SystemClock.elapsedRealtimeNanos();
        long startTimeNs = System.nanoTime();
        mVibrator.vibrate(effect);
        mVibrator.vibrate(effect);
        long latencyNs = SystemClock.elapsedRealtimeNanos() - startTimeNs;
        long latencyNs = System.nanoTime() - startTimeNs;


        mStateListener.awaitVibrating(5, SECONDS);
        mStateListener.awaitVibrating(5, SECONDS);
        mStateListener.awaitIdle(5, SECONDS);
        mStateListener.awaitIdle(5, SECONDS);
@@ -398,14 +398,12 @@ public class VibratorPerfTest {
     */
     */
    private long measureVibrateWithStateChangeLatency(ManualBenchmarkState state,
    private long measureVibrateWithStateChangeLatency(ManualBenchmarkState state,
            VibrationEffect effect, long durationMs) throws InterruptedException {
            VibrationEffect effect, long durationMs) throws InterruptedException {
        long vibrateTimeNs = SystemClock.elapsedRealtimeNanos();
        long vibrateTimeNs = System.nanoTime();
        mVibrator.vibrate(effect);
        mVibrator.vibrate(effect);
        long vibrateLatencyNs = SystemClock.elapsedRealtimeNanos() - vibrateTimeNs;
        long vibrateLatencyNs = System.nanoTime() - vibrateTimeNs;


        long startTimeNs = mStateListener.awaitVibrating(5, SECONDS)
        long startTimeNs = mStateListener.awaitVibrating(5, SECONDS) ? System.nanoTime() : -1;
                ? SystemClock.elapsedRealtimeNanos() : -1;
        long stopTimeNs = mStateListener.awaitIdle(5, SECONDS) ? System.nanoTime() : -1;
        long stopTimeNs = mStateListener.awaitIdle(5, SECONDS)
                ? SystemClock.elapsedRealtimeNanos() : -1;
        mStateListener.resetCounters();
        mStateListener.resetCounters();


        // Rate-limiting, wait for service to clean-up previous vibration and become idle.
        // Rate-limiting, wait for service to clean-up previous vibration and become idle.