diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java index 93bf541d02b49..e1928615211a6 100644 --- a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java +++ b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java @@ -53,7 +53,8 @@ public final class BenchmarkState { private static final int NOT_STARTED = 0; // The benchmark has not started yet. private static final int WARMUP = 1; // The benchmark is warming up. private static final int RUNNING = 2; // The benchmark is running. - private static final int FINISHED = 3; // The benchmark has stopped. + private static final int RUNNING_CUSTOMIZED = 3; // Running for customized measurement. + private static final int FINISHED = 4; // The benchmark has stopped. private int mState = NOT_STARTED; // Current benchmark state. @@ -76,6 +77,14 @@ public final class BenchmarkState { private int mRepeatCount = 0; + /** + * Additional iteration that used to apply customized measurement. The result during these + * iterations won't be counted into {@link #mStats}. + */ + private int mMaxCustomizedIterations; + private int mCustomizedIterations; + private CustomizedIterationListener mCustomizedIterationListener; + // Statistics. These values will be filled when the benchmark has finished. // The computation needs double precision, but long int is fine for final reporting. private Stats mStats; @@ -110,6 +119,15 @@ public final class BenchmarkState { mPaused = false; } + /** + * This is used to run the benchmark with more information by enabling some debug mechanism but + * we don't want to account the special runs (slower) in the stats report. + */ + public void setCustomizedIterations(int iterations, CustomizedIterationListener listener) { + mMaxCustomizedIterations = iterations; + mCustomizedIterationListener = listener; + } + private void beginWarmup() { mStartTimeNs = System.nanoTime(); mIteration = 0; @@ -141,6 +159,11 @@ public final class BenchmarkState { Debug.stopMethodTracing(); } mStats = new Stats(mResults); + if (mMaxCustomizedIterations > 0 && mCustomizedIterationListener != null) { + mState = RUNNING_CUSTOMIZED; + mCustomizedIterationListener.onStart(mCustomizedIterations); + return true; + } mState = FINISHED; return false; } @@ -180,6 +203,15 @@ public final class BenchmarkState { "Resume the benchmark before finishing each step."); } return true; + case RUNNING_CUSTOMIZED: + mCustomizedIterationListener.onFinished(mCustomizedIterations); + mCustomizedIterations++; + if (mCustomizedIterations >= mMaxCustomizedIterations) { + mState = FINISHED; + return false; + } + mCustomizedIterationListener.onStart(mCustomizedIterations); + return true; case FINISHED: throw new IllegalStateException("The benchmark has finished."); default: @@ -240,4 +272,13 @@ public final class BenchmarkState { status.putLong(key + "_standardDeviation", standardDeviation()); instrumentation.sendStatus(Activity.RESULT_OK, status); } + + /** The interface to receive the events of customized iteration. */ + public interface CustomizedIterationListener { + /** The customized iteration starts. */ + void onStart(int iteration); + + /** The customized iteration finished. */ + void onFinished(int iteration); + } } diff --git a/apct-tests/perftests/windowmanager/AndroidManifest.xml b/apct-tests/perftests/windowmanager/AndroidManifest.xml index 85fd7176c33a9..95ede345fbee0 100644 --- a/apct-tests/perftests/windowmanager/AndroidManifest.xml +++ b/apct-tests/perftests/windowmanager/AndroidManifest.xml @@ -29,5 +29,7 @@ + android:targetPackage="com.android.perftests.wm"> + + diff --git a/apct-tests/perftests/windowmanager/AndroidTest.xml b/apct-tests/perftests/windowmanager/AndroidTest.xml index aee02c7ab7679..6ac9f9373f8ca 100644 --- a/apct-tests/perftests/windowmanager/AndroidTest.xml +++ b/apct-tests/perftests/windowmanager/AndroidTest.xml @@ -42,7 +42,7 @@