Loading apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java +42 −1 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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: Loading Loading @@ -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); } } apct-tests/perftests/windowmanager/AndroidManifest.xml +3 −1 Original line number Diff line number Diff line Loading @@ -29,5 +29,7 @@ </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" android:targetPackage="com.android.perftests.wm"/> android:targetPackage="com.android.perftests.wm"> <meta-data android:name="listener" android:value="android.wm.WmPerfRunListener" /> </instrumentation> </manifest> apct-tests/perftests/windowmanager/AndroidTest.xml +1 −3 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ <option name="hidden-api-checks" value="false"/> <!-- Listener related args for collecting the traces and waiting for the device to stabilize. --> <option name="device-listeners" value="android.wm.WmPerfRunListener,android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener" /> <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener" /> <!-- Guarantee that user defined RunListeners will be running before any of the default listeners defined in this runner. --> <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> Loading @@ -57,8 +57,6 @@ <!-- PerfettoListener related arguments --> <option name="instrumentation-arg" key="perfetto_config_text_proto" value="true" /> <option name="instrumentation-arg" key="perfetto_config_file" value="trace_config.textproto" /> <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> </test> <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> Loading apct-tests/perftests/windowmanager/README.md +8 −0 Original line number Diff line number Diff line Loading @@ -25,3 +25,11 @@ adb shell am instrument -w -r -e class android.wm.RelayoutPerfTest \ com.android.perftests.wm/androidx.test.runner.AndroidJUnitRunner ``` * `kill-bg` is optional. Test arguments - kill-bg * boolean: Kill background process before running test. - profiling-iterations * int: Run the extra iterations with enabling method profiling. - profiling-sampling * int: The interval (0=trace each method, default is 10) of sample profiling in microseconds. apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java +34 −6 Original line number Diff line number Diff line Loading @@ -41,7 +41,8 @@ import java.util.concurrent.TimeUnit; /** Measure the performance of internal methods in window manager service by trace tag. */ @LargeTest public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase implements ManualBenchmarkState.CustomizedIterationListener { private static final String TAG = InternalWindowOperationPerfTest.class.getSimpleName(); @Rule Loading @@ -68,6 +69,9 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { "finishActivity", "startActivityInner"); private boolean mIsProfiling; private boolean mIsTraceStarted; @Test @ManualBenchmarkTest( targetTestDurationNs = 20 * TIME_1_S_IN_NS, Loading @@ -76,13 +80,13 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { | StatsReport.FLAG_MAX | StatsReport.FLAG_COEFFICIENT_VAR)) public void testLaunchAndFinishActivity() throws Throwable { final ManualBenchmarkState state = mPerfStatusReporter.getBenchmarkState(); state.setCustomizedIterations(getProfilingIterations(), this); long measuredTimeNs = 0; boolean isTraceStarted = false; while (state.keepRunning(measuredTimeNs)) { if (!isTraceStarted && !state.isWarmingUp()) { if (!mIsTraceStarted && !mIsProfiling && !state.isWarmingUp()) { startAsyncAtrace(); isTraceStarted = true; mIsTraceStarted = true; } final long startTime = SystemClock.elapsedRealtimeNanos(); mActivityRule.launchActivity(); Loading @@ -91,7 +95,9 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { measuredTimeNs = SystemClock.elapsedRealtimeNanos() - startTime; } if (mIsTraceStarted) { stopAsyncAtrace(); } mTraceMarkParser.forAllSlices((key, slices) -> { for (TraceMarkSlice slice : slices) { Loading @@ -108,7 +114,7 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { SystemClock.sleep(TimeUnit.NANOSECONDS.toMillis(TIME_1_S_IN_NS)); } private void stopAsyncAtrace() throws IOException { private void stopAsyncAtrace() { final ParcelFileDescriptor pfd = sUiAutomation.executeShellCommand("atrace --async_stop"); final InputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { Loading @@ -116,6 +122,28 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { while ((line = reader.readLine()) != null) { mTraceMarkParser.visit(line); } } catch (IOException e) { Log.w(TAG, "Failed to read the result of stopped atrace", e); } } @Override public void onStart(int iteration) { if (mIsTraceStarted) { // Do not capture trace when profiling because the result will be much slower. stopAsyncAtrace(); mIsTraceStarted = false; } mIsProfiling = true; startProfiling(InternalWindowOperationPerfTest.class.getSimpleName() + "_MethodTracing_" + iteration + ".trace"); } @Override public void onFinished(int iteration) { stopProfiling(); if (iteration >= getProfilingIterations() - 1) { mIsProfiling = false; } } } Loading
apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java +42 −1 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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: Loading Loading @@ -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); } }
apct-tests/perftests/windowmanager/AndroidManifest.xml +3 −1 Original line number Diff line number Diff line Loading @@ -29,5 +29,7 @@ </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" android:targetPackage="com.android.perftests.wm"/> android:targetPackage="com.android.perftests.wm"> <meta-data android:name="listener" android:value="android.wm.WmPerfRunListener" /> </instrumentation> </manifest>
apct-tests/perftests/windowmanager/AndroidTest.xml +1 −3 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ <option name="hidden-api-checks" value="false"/> <!-- Listener related args for collecting the traces and waiting for the device to stabilize. --> <option name="device-listeners" value="android.wm.WmPerfRunListener,android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener" /> <option name="device-listeners" value="android.device.collectors.ProcLoadListener,android.device.collectors.PerfettoListener" /> <!-- Guarantee that user defined RunListeners will be running before any of the default listeners defined in this runner. --> <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> Loading @@ -57,8 +57,6 @@ <!-- PerfettoListener related arguments --> <option name="instrumentation-arg" key="perfetto_config_text_proto" value="true" /> <option name="instrumentation-arg" key="perfetto_config_file" value="trace_config.textproto" /> <option name="instrumentation-arg" key="newRunListenerMode" value="true" /> </test> <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector"> Loading
apct-tests/perftests/windowmanager/README.md +8 −0 Original line number Diff line number Diff line Loading @@ -25,3 +25,11 @@ adb shell am instrument -w -r -e class android.wm.RelayoutPerfTest \ com.android.perftests.wm/androidx.test.runner.AndroidJUnitRunner ``` * `kill-bg` is optional. Test arguments - kill-bg * boolean: Kill background process before running test. - profiling-iterations * int: Run the extra iterations with enabling method profiling. - profiling-sampling * int: The interval (0=trace each method, default is 10) of sample profiling in microseconds.
apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java +34 −6 Original line number Diff line number Diff line Loading @@ -41,7 +41,8 @@ import java.util.concurrent.TimeUnit; /** Measure the performance of internal methods in window manager service by trace tag. */ @LargeTest public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase implements ManualBenchmarkState.CustomizedIterationListener { private static final String TAG = InternalWindowOperationPerfTest.class.getSimpleName(); @Rule Loading @@ -68,6 +69,9 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { "finishActivity", "startActivityInner"); private boolean mIsProfiling; private boolean mIsTraceStarted; @Test @ManualBenchmarkTest( targetTestDurationNs = 20 * TIME_1_S_IN_NS, Loading @@ -76,13 +80,13 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { | StatsReport.FLAG_MAX | StatsReport.FLAG_COEFFICIENT_VAR)) public void testLaunchAndFinishActivity() throws Throwable { final ManualBenchmarkState state = mPerfStatusReporter.getBenchmarkState(); state.setCustomizedIterations(getProfilingIterations(), this); long measuredTimeNs = 0; boolean isTraceStarted = false; while (state.keepRunning(measuredTimeNs)) { if (!isTraceStarted && !state.isWarmingUp()) { if (!mIsTraceStarted && !mIsProfiling && !state.isWarmingUp()) { startAsyncAtrace(); isTraceStarted = true; mIsTraceStarted = true; } final long startTime = SystemClock.elapsedRealtimeNanos(); mActivityRule.launchActivity(); Loading @@ -91,7 +95,9 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { measuredTimeNs = SystemClock.elapsedRealtimeNanos() - startTime; } if (mIsTraceStarted) { stopAsyncAtrace(); } mTraceMarkParser.forAllSlices((key, slices) -> { for (TraceMarkSlice slice : slices) { Loading @@ -108,7 +114,7 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { SystemClock.sleep(TimeUnit.NANOSECONDS.toMillis(TIME_1_S_IN_NS)); } private void stopAsyncAtrace() throws IOException { private void stopAsyncAtrace() { final ParcelFileDescriptor pfd = sUiAutomation.executeShellCommand("atrace --async_stop"); final InputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { Loading @@ -116,6 +122,28 @@ public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { while ((line = reader.readLine()) != null) { mTraceMarkParser.visit(line); } } catch (IOException e) { Log.w(TAG, "Failed to read the result of stopped atrace", e); } } @Override public void onStart(int iteration) { if (mIsTraceStarted) { // Do not capture trace when profiling because the result will be much slower. stopAsyncAtrace(); mIsTraceStarted = false; } mIsProfiling = true; startProfiling(InternalWindowOperationPerfTest.class.getSimpleName() + "_MethodTracing_" + iteration + ".trace"); } @Override public void onFinished(int iteration) { stopProfiling(); if (iteration >= getProfilingIterations() - 1) { mIsProfiling = false; } } }