diff options
author | Riddle Hsu <riddlehsu@google.com> | 2019-07-26 21:28:51 -0600 |
---|---|---|
committer | Riddle Hsu <riddlehsu@google.com> | 2019-07-26 21:35:35 +0800 |
commit | 5ef56dd6f36f904b1ad916cae54f22ac41759b14 (patch) | |
tree | 65dea9f2ad003d5a7f797c9e86ad8b02ec94ff0b /apct-tests/perftests/utils | |
parent | cac13d44ab9ced55b6bb13d05993634d9d322487 (diff) |
Add performance test for operations of recents activity
Includes startRecentsActivity, startActivityFromRecents,
and IRecentsAnimationController.finish.
Also make the output stats of manual benchmark customizable.
Bug: 131727899
Test: atest RecentsAnimationPerfTest
Change-Id: I89a08248b4f215c990640aeb50800759d6dbcf22
Diffstat (limited to 'apct-tests/perftests/utils')
-rw-r--r-- | apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java | 75 | ||||
-rw-r--r-- | apct-tests/perftests/utils/src/android/perftests/utils/Stats.java | 6 |
2 files changed, 73 insertions, 8 deletions
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 dd43ae70cc5c..ffe39e8679e1 100644 --- a/apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java +++ b/apct-tests/perftests/utils/src/android/perftests/utils/ManualBenchmarkState.java @@ -16,6 +16,7 @@ package android.perftests.utils; +import android.annotation.IntDef; import android.app.Activity; import android.app.Instrumentation; import android.os.Bundle; @@ -58,6 +59,28 @@ import java.util.concurrent.TimeUnit; public final class ManualBenchmarkState { private static final String TAG = ManualBenchmarkState.class.getSimpleName(); + @IntDef(prefix = {"STATS_REPORT"}, value = { + STATS_REPORT_MEDIAN, + STATS_REPORT_MEAN, + STATS_REPORT_MIN, + STATS_REPORT_MAX, + STATS_REPORT_PERCENTILE90, + STATS_REPORT_PERCENTILE95, + STATS_REPORT_STDDEV, + STATS_REPORT_ITERATION, + }) + public @interface StatsReport {} + + public static final int STATS_REPORT_MEDIAN = 0x00000001; + public static final int STATS_REPORT_MEAN = 0x00000002; + public static final int STATS_REPORT_MIN = 0x00000004; + public static final int STATS_REPORT_MAX = 0x00000008; + public static final int STATS_REPORT_PERCENTILE90 = 0x00000010; + public static final int STATS_REPORT_PERCENTILE95 = 0x00000020; + public static final int STATS_REPORT_STDDEV = 0x00000040; + public static final int STATS_REPORT_COEFFICIENT_VAR = 0x00000080; + public static final int STATS_REPORT_ITERATION = 0x00000100; + // TODO: Tune these values. // warm-up for duration private static final long WARMUP_DURATION_NS = TimeUnit.SECONDS.toNanos(5); @@ -93,6 +116,13 @@ public final class ManualBenchmarkState { // The computation needs double precision, but long int is fine for final reporting. private Stats mStats; + private int mStatsReportFlags = STATS_REPORT_MEDIAN | STATS_REPORT_MEAN + | STATS_REPORT_PERCENTILE90 | STATS_REPORT_PERCENTILE95 | STATS_REPORT_STDDEV; + + private boolean shouldReport(int statsReportFlag) { + return (mStatsReportFlags & statsReportFlag) != 0; + } + void configure(ManualBenchmarkTest testAnnotation) { if (testAnnotation == null) { return; @@ -106,6 +136,10 @@ public final class ManualBenchmarkState { if (targetTestDurationNs >= 0) { mTargetTestDurationNs = targetTestDurationNs; } + final int statsReportFlags = testAnnotation.statsReportFlags(); + if (statsReportFlags >= 0) { + mStatsReportFlags = statsReportFlags; + } } private void beginBenchmark(long warmupDuration, int iterations) { @@ -186,12 +220,35 @@ public final class ManualBenchmarkState { return sb.toString(); } - private static void fillStatus(Bundle status, String key, Stats stats) { - status.putLong(key + "_median", stats.getMedian()); - status.putLong(key + "_mean", (long) stats.getMean()); - status.putLong(key + "_percentile90", stats.getPercentile90()); - status.putLong(key + "_percentile95", stats.getPercentile95()); - status.putLong(key + "_stddev", (long) stats.getStandardDeviation()); + private void fillStatus(Bundle status, String key, Stats stats) { + if (shouldReport(STATS_REPORT_ITERATION)) { + status.putLong(key + "_iteration", stats.getSize()); + } + if (shouldReport(STATS_REPORT_MEDIAN)) { + status.putLong(key + "_median", stats.getMedian()); + } + if (shouldReport(STATS_REPORT_MEAN)) { + status.putLong(key + "_mean", Math.round(stats.getMean())); + } + if (shouldReport(STATS_REPORT_MIN)) { + status.putLong(key + "_min", stats.getMin()); + } + if (shouldReport(STATS_REPORT_MAX)) { + status.putLong(key + "_max", stats.getMax()); + } + if (shouldReport(STATS_REPORT_PERCENTILE90)) { + status.putLong(key + "_percentile90", stats.getPercentile90()); + } + if (shouldReport(STATS_REPORT_PERCENTILE95)) { + status.putLong(key + "_percentile95", stats.getPercentile95()); + } + if (shouldReport(STATS_REPORT_STDDEV)) { + status.putLong(key + "_stddev", Math.round(stats.getStandardDeviation())); + } + if (shouldReport(STATS_REPORT_COEFFICIENT_VAR)) { + status.putLong(key + "_cv", + Math.round((100 * stats.getStandardDeviation() / stats.getMean()))); + } } public void sendFullStatusReport(Instrumentation instrumentation, String key) { @@ -204,8 +261,9 @@ public final class ManualBenchmarkState { if (mExtraResults != null) { for (int i = 0; i < mExtraResults.size(); i++) { final String subKey = key + "_" + mExtraResults.keyAt(i); - final Stats stats = new Stats(mExtraResults.valueAt(i)); - Log.i(TAG, summaryLine(subKey, mStats, mResults)); + final ArrayList<Long> results = mExtraResults.valueAt(i); + final Stats stats = new Stats(results); + Log.i(TAG, summaryLine(subKey, stats, results)); fillStatus(status, subKey, stats); } } @@ -218,5 +276,6 @@ public final class ManualBenchmarkState { public @interface ManualBenchmarkTest { long warmupDurationNs() default -1; long targetTestDurationNs() default -1; + @StatsReport int statsReportFlags() default -1; } } 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 5e50073c0674..f650e810c6de 100644 --- a/apct-tests/perftests/utils/src/android/perftests/utils/Stats.java +++ b/apct-tests/perftests/utils/src/android/perftests/utils/Stats.java @@ -23,6 +23,7 @@ import java.util.List; public class Stats { private long mMedian, mMin, mMax, mPercentile90, mPercentile95; private double mMean, mStandardDeviation; + private final int mSize; /* Calculate stats in constructor. */ public Stats(List<Long> values) { @@ -35,6 +36,7 @@ public class Stats { Collections.sort(values); + mSize = size; mMin = values.get(0); mMax = values.get(values.size() - 1); @@ -56,6 +58,10 @@ public class Stats { mStandardDeviation = Math.sqrt(mStandardDeviation / (double) (size - 1)); } + public int getSize() { + return mSize; + } + public double getMean() { return mMean; } |