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

Commit 3ffc6e7e authored by Arthur Eubanks's avatar Arthur Eubanks
Browse files

Add 90th and 95th percentile to ManualBenchmarkState

Test: m ActivityManagerPerfTestsTestApp ActivityManagerPerfTests
Test: adb install \
$OUT/data/app/ActivityManagerPerfTestsTestApp/ActivityManagerPerfTestsTestApp.apk
Test: adb install \
$OUT/data/app/ActivityManagerPerfTests/ActivityManagerPerfTests.apk
Test: adb shell am instrument -w -e class \
com.android.frameworks.perftests.am.tests.BroadcastPerfTest \
com.android.frameworks.perftests.amtests/android.support.test.runner.AndroidJUnitRunner

BUG: 67460485
Change-Id: I3da7079758b0f8c123d354780f310f357886543c
parent c65eb444
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -150,6 +150,8 @@ public final class ManualBenchmarkState {
        final Bundle status = new Bundle();
        status.putLong(key + "_median", mStats.getMedian());
        status.putLong(key + "_mean", (long) mStats.getMean());
        status.putLong(key + "_percentile90", mStats.getPercentile90());
        status.putLong(key + "_percentile95", mStats.getPercentile95());
        status.putLong(key + "_stddev", (long) mStats.getStandardDeviation());
        instrumentation.sendStatus(Activity.RESULT_OK, status);
    }
+23 −4
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.List;

public class Stats {
    private long mMedian, mMin, mMax;
    private long mMedian, mMin, mMax, mPercentile90, mPercentile95;
    private double mMean, mStandardDeviation;

    /* Calculate stats in constructor. */
@@ -35,12 +35,14 @@ public class Stats {

        Collections.sort(values);

        mMedian = size % 2 == 0 ? (values.get(size / 2) + values.get(size / 2 - 1)) / 2 :
                values.get(size / 2);

        mMin = values.get(0);
        mMax = values.get(values.size() - 1);

        mMedian = size % 2 == 0 ? (values.get(size / 2) + values.get(size / 2 - 1)) / 2 :
                values.get(size / 2);
        mPercentile90 = getPercentile(values, 90);
        mPercentile95 = getPercentile(values, 95);

        for (int i = 0; i < size; ++i) {
            long result = values.get(i);
            mMean += result;
@@ -73,4 +75,21 @@ public class Stats {
    public double getStandardDeviation() {
        return mStandardDeviation;
    }

    public long getPercentile90() {
        return mPercentile90;
    }

    public long getPercentile95() {
        return mPercentile95;
    }

    private static long getPercentile(List<Long> values, int percentile) {
        if (percentile < 0 || percentile > 100) {
            throw new IllegalArgumentException(
                    "invalid percentile " + percentile + ", should be 0-100");
        }
        int idx = (values.size() - 1) * percentile / 100;
        return values.get(idx);
    }
}