Merge "Make ImePerfTest#testShowImeCold more accurate" into udc-dev am: 1d4c9421bd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21738300

Change-Id: Ia11e264dafe6d050acbcb3fae414f1bd7b8fc935
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ming-Shin Lu
2023-03-07 12:08:31 +00:00
committed by Automerger Merge Worker
2 changed files with 25 additions and 10 deletions

View File

@@ -76,6 +76,7 @@ public class ImePerfTest extends ImePerfTestBase
implements ManualBenchmarkState.CustomizedIterationListener {
private static final String TAG = ImePerfTest.class.getSimpleName();
private static final long ANIMATION_NOT_STARTED = -1;
private static final int WAIT_PROCESS_KILL_TIMEOUT_MS = 2000;
@Rule
public final PerfManualStatusReporter mPerfStatusReporter = new PerfManualStatusReporter();
@@ -248,19 +249,18 @@ public class ImePerfTest extends ImePerfTestBase
boolean shouldRetry = false;
while (shouldRetry || state.keepRunning(measuredTimeNs)) {
shouldRetry = false;
killBaselineIme();
killBaselineImeSync();
try (ImeSession imeSession = new ImeSession(BaselineIme.getName(
getInstrumentation().getContext()))) {
if (!mIsTraceStarted) {
startAsyncAtrace();
}
final AtomicReference<CountDownLatch> latchStart = new AtomicReference<>();
final Activity activity = getActivityWithFocus();
setImeListener(activity, latchStart, null /* latchEnd */);
latchStart.set(new CountDownLatch(1));
if (!mIsTraceStarted) {
startAsyncAtrace();
}
final WindowInsetsController controller =
activity.getWindow().getDecorView().getWindowInsetsController();
AtomicLong startTime = new AtomicLong();
@@ -270,6 +270,7 @@ public class ImePerfTest extends ImePerfTestBase
});
measuredTimeNs = waitForAnimationStart(latchStart, startTime);
stopAsyncAtraceAndDumpTraces();
if (measuredTimeNs == ANIMATION_NOT_STARTED) {
// Animation didn't start within timeout,
@@ -285,7 +286,7 @@ public class ImePerfTest extends ImePerfTestBase
addResultToState(state);
}
private void killBaselineIme() {
private void killBaselineImeSync() {
// pidof returns a space separated list of numeric PIDs.
String result = SystemUtil.runShellCommand(
"pidof com.android.perftests.inputmethod:BaselineIME");
@@ -294,7 +295,13 @@ public class ImePerfTest extends ImePerfTestBase
if (TextUtils.isEmpty(pid)) {
continue;
}
Process.killProcess(Integer.parseInt(pid));
final int pidToKill = Integer.parseInt(pid);
Process.killProcess(pidToKill);
try {
// Wait kill IME process being settled down.
Process.waitForProcessDeath(pidToKill, WAIT_PROCESS_KILL_TIMEOUT_MS);
} catch (Exception e) {
}
}
}
@@ -381,7 +388,7 @@ public class ImePerfTest extends ImePerfTestBase
}
} finally {
if (mIsTraceStarted) {
stopAsyncAtrace();
stopAsyncAtraceAndDumpTraces();
}
}
mActivityRule.finishActivity();
@@ -488,7 +495,7 @@ public class ImePerfTest extends ImePerfTestBase
startAsyncAtrace("wm view");
}
private void stopAsyncAtrace() {
private void stopAsyncAtraceAndDumpTraces() {
if (!mIsTraceStarted) {
return;
}
@@ -504,6 +511,14 @@ public class ImePerfTest extends ImePerfTestBase
}
}
private void stopAsyncAtrace() {
if (!mIsTraceStarted) {
return;
}
mIsTraceStarted = false;
getUiAutomation().executeShellCommand("atrace --async_stop");
}
@Override
public void onStart(int iteration) {
// Do not capture trace when profiling because the result will be much slower.

View File

@@ -73,7 +73,7 @@ public class WindowPerfTestBase {
}
public static void startAsyncAtrace(String tags) {
getUiAutomation().executeShellCommand("atrace -b 32768 --async_start " + tags);
getUiAutomation().executeShellCommand("atrace --async_start -b 32768 -c " + tags);
// Avoid atrace isn't ready immediately.
SystemClock.sleep(TimeUnit.NANOSECONDS.toMillis(TIME_1_S_IN_NS));
}