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

Commit 8a3e20a7 authored by Olivier Gaillard's avatar Olivier Gaillard
Browse files

Update BinderCallsStats perf tests to use a more realistic workload.

Test: this is a test
Change-Id: I6dc7151c3df2a1e488db7d1b703ca29049b2e01a
parent e367c38d
Loading
Loading
Loading
Loading
+45 −6
Original line number Original line Diff line number Diff line
@@ -38,6 +38,23 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
@LargeTest
@LargeTest
public class BinderCallsStatsPerfTest {
public class BinderCallsStatsPerfTest {
    private static final int DEFAULT_BUCKET_SIZE = 1000;
    static class FakeCpuTimeBinderCallsStats extends BinderCallsStats {
        private int mTimeMs;

        FakeCpuTimeBinderCallsStats() {
            super(new BinderCallsStats.Injector());
            setDeviceState(new CachedDeviceState(false, false).getReadonlyClient());
        }

        protected long getThreadTimeMicro() {
            return mTimeMs++;
        }

        protected long getElapsedRealtimeMicro() {
            return mTimeMs++;
        }
    }


    @Rule
    @Rule
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
@@ -57,28 +74,50 @@ public class BinderCallsStatsPerfTest {
    @Test
    @Test
    public void timeCallSession() {
    public void timeCallSession() {
        mBinderCallsStats.setDetailedTracking(true);
        mBinderCallsStats.setDetailedTracking(true);
        runScenario();
        runScenario(DEFAULT_BUCKET_SIZE);
    }
    }


    @Test
    @Test
    public void timeCallSessionOnePercentSampling() {
    public void timeCallSessionOnePercentSampling() {
        mBinderCallsStats.setDetailedTracking(false);
        mBinderCallsStats.setDetailedTracking(false);
        mBinderCallsStats.setSamplingInterval(100);
        mBinderCallsStats.setSamplingInterval(100);
        runScenario();
        runScenario(DEFAULT_BUCKET_SIZE);
    }
    }


    @Test
    @Test
    public void timeCallSessionTrackingDisabled() {
    public void timeCallSessionTrackingDisabled() {
        mBinderCallsStats.setDetailedTracking(false);
        mBinderCallsStats.setDetailedTracking(false);
        runScenario();
        runScenario(DEFAULT_BUCKET_SIZE);
    }

    @Test
    public void timeCallSession_1000_buckets_cpuNotRecorded() {
        mBinderCallsStats = new FakeCpuTimeBinderCallsStats();
        mBinderCallsStats.setSamplingInterval(1);
        runScenario(/* max bucket size */ 1000);
    }

    @Test
    public void timeCallSession_500_buckets_cpuNotRecorded() {
        mBinderCallsStats = new FakeCpuTimeBinderCallsStats();
        mBinderCallsStats.setSamplingInterval(1);
        runScenario(/* max bucket size */ 500);
    }

    @Test
    public void timeCallSession_100_buckets_cpuNotRecorded() {
        mBinderCallsStats = new FakeCpuTimeBinderCallsStats();
        mBinderCallsStats.setSamplingInterval(1);
        runScenario(/* max bucket size */ 100);
    }
    }


    private void runScenario() {
    // There will be a warmup time of maxBucketSize to initialize the map of CallStat.
    private void runScenario(int maxBucketSize) {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        Binder b = new Binder();
        Binder b = new Binder();
        while (state.keepRunning()) {
        while (state.keepRunning()) {
            for (int i = 0; i < 1000; i++) {
            for (int i = 0; i < 10000; i++) {
                CallSession s = mBinderCallsStats.callStarted(b, i % 100);
                CallSession s = mBinderCallsStats.callStarted(b, i % maxBucketSize);
                mBinderCallsStats.callEnded(s, 0, 0);
                mBinderCallsStats.callEnded(s, 0, 0);
            }
            }
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -419,7 +419,7 @@ public class BinderCallsStats implements BinderInternal.Observer {
        return SystemClock.elapsedRealtimeNanos() / 1000;
        return SystemClock.elapsedRealtimeNanos() / 1000;
    }
    }


    private boolean shouldRecordDetailedData() {
    protected boolean shouldRecordDetailedData() {
        return mRandom.nextInt() % mPeriodicSamplingInterval == 0;
        return mRandom.nextInt() % mPeriodicSamplingInterval == 0;
    }
    }