diff options
author | Riddle Hsu <riddlehsu@google.com> | 2020-05-04 21:58:50 +0800 |
---|---|---|
committer | Riddle Hsu <riddlehsu@google.com> | 2020-05-06 00:52:51 +0800 |
commit | b078bc1b9c08ebfebf4114b8b13972784a059e6c (patch) | |
tree | 2e776f38aa976324881e8d7ac8a8b9b8a1757e24 /apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java | |
parent | cb7f8e7280df971b67fa094a8f6eef60d34bdf5f (diff) |
Move window manager perf test to a new package
To isolate the test environment.
Bug: 155404627
Test: atest WmPerfTests
Change-Id: I1d9eda840056efc6c2d0696952ece55fd22b1547
Diffstat (limited to 'apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java')
-rw-r--r-- | apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java b/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java new file mode 100644 index 000000000000..4ed3b4e09d11 --- /dev/null +++ b/apct-tests/perftests/windowmanager/src/android/wm/InternalWindowOperationPerfTest.java @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.wm; + +import static android.perftests.utils.ManualBenchmarkState.StatsReport; + +import android.os.ParcelFileDescriptor; +import android.os.SystemClock; +import android.perftests.utils.ManualBenchmarkState; +import android.perftests.utils.ManualBenchmarkState.ManualBenchmarkTest; +import android.perftests.utils.PerfManualStatusReporter; +import android.perftests.utils.TraceMarkParser; +import android.perftests.utils.TraceMarkParser.TraceMarkSlice; +import android.util.Log; + +import androidx.test.filters.LargeTest; +import androidx.test.runner.lifecycle.Stage; + +import org.junit.Rule; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; + +/** Measure the performance of internal methods in window manager service by trace tag. */ +@LargeTest +public class InternalWindowOperationPerfTest extends WindowManagerPerfTestBase { + private static final String TAG = InternalWindowOperationPerfTest.class.getSimpleName(); + + @Rule + public final PerfManualStatusReporter mPerfStatusReporter = new PerfManualStatusReporter(); + + @Rule + public final PerfTestActivityRule mActivityRule = new PerfTestActivityRule(); + + private final TraceMarkParser mTraceMarkParser = new TraceMarkParser( + "applyPostLayoutPolicy", + "applySurfaceChanges", + "AppTransitionReady", + "closeSurfaceTransactiom", + "openSurfaceTransaction", + "performLayout", + "performSurfacePlacement", + "prepareSurfaces", + "updateInputWindows", + "WSA#startAnimation", + "activityIdle", + "activityPaused", + "activityStopped", + "activityDestroyed", + "finishActivity", + "startActivityInner"); + + @Test + @ManualBenchmarkTest( + targetTestDurationNs = 20 * TIME_1_S_IN_NS, + statsReport = @StatsReport( + flags = StatsReport.FLAG_ITERATION | StatsReport.FLAG_MEAN + | StatsReport.FLAG_MAX | StatsReport.FLAG_COEFFICIENT_VAR)) + public void testLaunchAndFinishActivity() throws Throwable { + final ManualBenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + long measuredTimeNs = 0; + boolean isTraceStarted = false; + + while (state.keepRunning(measuredTimeNs)) { + if (!isTraceStarted && !state.isWarmingUp()) { + startAsyncAtrace(); + isTraceStarted = true; + } + final long startTime = SystemClock.elapsedRealtimeNanos(); + mActivityRule.launchActivity(); + mActivityRule.finishActivity(); + mActivityRule.waitForIdleSync(Stage.DESTROYED); + measuredTimeNs = SystemClock.elapsedRealtimeNanos() - startTime; + } + + stopAsyncAtrace(); + + mTraceMarkParser.forAllSlices((key, slices) -> { + for (TraceMarkSlice slice : slices) { + state.addExtraResult(key, (long) (slice.getDurationInSeconds() * NANOS_PER_S)); + } + }); + + Log.i(TAG, String.valueOf(mTraceMarkParser)); + } + + private void startAsyncAtrace() throws IOException { + sUiAutomation.executeShellCommand("atrace -b 32768 --async_start wm"); + // Avoid atrace isn't ready immediately. + SystemClock.sleep(TimeUnit.NANOSECONDS.toMillis(TIME_1_S_IN_NS)); + } + + private void stopAsyncAtrace() throws IOException { + final ParcelFileDescriptor pfd = sUiAutomation.executeShellCommand("atrace --async_stop"); + final InputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = reader.readLine()) != null) { + mTraceMarkParser.visit(line); + } + } + } +} |