Merge "Make ImePerfTest#testShowImeCold more accurate" into udc-dev
This commit is contained in:
@@ -76,6 +76,7 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
implements ManualBenchmarkState.CustomizedIterationListener {
|
implements ManualBenchmarkState.CustomizedIterationListener {
|
||||||
private static final String TAG = ImePerfTest.class.getSimpleName();
|
private static final String TAG = ImePerfTest.class.getSimpleName();
|
||||||
private static final long ANIMATION_NOT_STARTED = -1;
|
private static final long ANIMATION_NOT_STARTED = -1;
|
||||||
|
private static final int WAIT_PROCESS_KILL_TIMEOUT_MS = 2000;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final PerfManualStatusReporter mPerfStatusReporter = new PerfManualStatusReporter();
|
public final PerfManualStatusReporter mPerfStatusReporter = new PerfManualStatusReporter();
|
||||||
@@ -248,19 +249,18 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
boolean shouldRetry = false;
|
boolean shouldRetry = false;
|
||||||
while (shouldRetry || state.keepRunning(measuredTimeNs)) {
|
while (shouldRetry || state.keepRunning(measuredTimeNs)) {
|
||||||
shouldRetry = false;
|
shouldRetry = false;
|
||||||
killBaselineIme();
|
killBaselineImeSync();
|
||||||
try (ImeSession imeSession = new ImeSession(BaselineIme.getName(
|
try (ImeSession imeSession = new ImeSession(BaselineIme.getName(
|
||||||
getInstrumentation().getContext()))) {
|
getInstrumentation().getContext()))) {
|
||||||
|
if (!mIsTraceStarted) {
|
||||||
|
startAsyncAtrace();
|
||||||
|
}
|
||||||
final AtomicReference<CountDownLatch> latchStart = new AtomicReference<>();
|
final AtomicReference<CountDownLatch> latchStart = new AtomicReference<>();
|
||||||
final Activity activity = getActivityWithFocus();
|
final Activity activity = getActivityWithFocus();
|
||||||
|
|
||||||
setImeListener(activity, latchStart, null /* latchEnd */);
|
setImeListener(activity, latchStart, null /* latchEnd */);
|
||||||
latchStart.set(new CountDownLatch(1));
|
latchStart.set(new CountDownLatch(1));
|
||||||
|
|
||||||
if (!mIsTraceStarted) {
|
|
||||||
startAsyncAtrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
final WindowInsetsController controller =
|
final WindowInsetsController controller =
|
||||||
activity.getWindow().getDecorView().getWindowInsetsController();
|
activity.getWindow().getDecorView().getWindowInsetsController();
|
||||||
AtomicLong startTime = new AtomicLong();
|
AtomicLong startTime = new AtomicLong();
|
||||||
@@ -270,6 +270,7 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
});
|
});
|
||||||
|
|
||||||
measuredTimeNs = waitForAnimationStart(latchStart, startTime);
|
measuredTimeNs = waitForAnimationStart(latchStart, startTime);
|
||||||
|
stopAsyncAtraceAndDumpTraces();
|
||||||
|
|
||||||
if (measuredTimeNs == ANIMATION_NOT_STARTED) {
|
if (measuredTimeNs == ANIMATION_NOT_STARTED) {
|
||||||
// Animation didn't start within timeout,
|
// Animation didn't start within timeout,
|
||||||
@@ -285,7 +286,7 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
addResultToState(state);
|
addResultToState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void killBaselineIme() {
|
private void killBaselineImeSync() {
|
||||||
// pidof returns a space separated list of numeric PIDs.
|
// pidof returns a space separated list of numeric PIDs.
|
||||||
String result = SystemUtil.runShellCommand(
|
String result = SystemUtil.runShellCommand(
|
||||||
"pidof com.android.perftests.inputmethod:BaselineIME");
|
"pidof com.android.perftests.inputmethod:BaselineIME");
|
||||||
@@ -294,7 +295,13 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
if (TextUtils.isEmpty(pid)) {
|
if (TextUtils.isEmpty(pid)) {
|
||||||
continue;
|
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 {
|
} finally {
|
||||||
if (mIsTraceStarted) {
|
if (mIsTraceStarted) {
|
||||||
stopAsyncAtrace();
|
stopAsyncAtraceAndDumpTraces();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mActivityRule.finishActivity();
|
mActivityRule.finishActivity();
|
||||||
@@ -488,7 +495,7 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
startAsyncAtrace("wm view");
|
startAsyncAtrace("wm view");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopAsyncAtrace() {
|
private void stopAsyncAtraceAndDumpTraces() {
|
||||||
if (!mIsTraceStarted) {
|
if (!mIsTraceStarted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -504,6 +511,14 @@ public class ImePerfTest extends ImePerfTestBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void stopAsyncAtrace() {
|
||||||
|
if (!mIsTraceStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mIsTraceStarted = false;
|
||||||
|
getUiAutomation().executeShellCommand("atrace --async_stop");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(int iteration) {
|
public void onStart(int iteration) {
|
||||||
// Do not capture trace when profiling because the result will be much slower.
|
// Do not capture trace when profiling because the result will be much slower.
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class WindowPerfTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void startAsyncAtrace(String tags) {
|
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.
|
// Avoid atrace isn't ready immediately.
|
||||||
SystemClock.sleep(TimeUnit.NANOSECONDS.toMillis(TIME_1_S_IN_NS));
|
SystemClock.sleep(TimeUnit.NANOSECONDS.toMillis(TIME_1_S_IN_NS));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user