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
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java b/apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java
index 2c84db1..40778de 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java
@@ -150,6 +150,8 @@
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);
}
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/Stats.java b/apct-tests/perftests/utils/src/android/perftests/utils/Stats.java
index acc44a8..5e50073 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/Stats.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/Stats.java
@@ -21,7 +21,7 @@
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 @@
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 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);
+ }
}