summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yasin Kilicdere <tyk@google.com> 2024-06-03 10:59:52 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-06-03 10:59:52 +0000
commit4c0faa6be9a01c72cfde37b962667a3012f4df90 (patch)
treec911d419f942b5097717d50f2762af0edb1c87fb
parent5f8269e7299517717256ec07813f8dbd2248f1ac (diff)
parent26130d14661f3deba3b72896f7a114be12c4fea9 (diff)
Merge "Revert "Remove timeout from waitForBroadcastIdle to improve spikiness."" into main
-rw-r--r--apct-tests/perftests/multiuser/src/android/multiuser/BenchmarkRunner.java47
1 files changed, 24 insertions, 23 deletions
diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/BenchmarkRunner.java b/apct-tests/perftests/multiuser/src/android/multiuser/BenchmarkRunner.java
index 459c2868e9ba..a4128a3de52f 100644
--- a/apct-tests/perftests/multiuser/src/android/multiuser/BenchmarkRunner.java
+++ b/apct-tests/perftests/multiuser/src/android/multiuser/BenchmarkRunner.java
@@ -22,12 +22,12 @@ import android.perftests.utils.ShellHelper;
import android.util.Log;
import java.util.ArrayList;
+import java.util.concurrent.TimeoutException;
// Based on //platform/frameworks/base/apct-tests/perftests/utils/BenchmarkState.java
public class BenchmarkRunner {
private static final String TAG = BenchmarkRunner.class.getSimpleName();
- private static final long COOL_OFF_PERIOD_MS = 1000;
- private static final int CPU_IDLE_TIMEOUT_MS = 60 * 1000;
+ private static final int TIMEOUT_IN_SECONDS = 45;
private static final int CPU_IDLE_THRESHOLD_PERCENTAGE = 90;
private static final int NUM_ITERATIONS = 4;
@@ -82,7 +82,6 @@ public class BenchmarkRunner {
}
private void prepareForNextRun() {
- SystemClock.sleep(COOL_OFF_PERIOD_MS);
waitCoolDownPeriod();
mStartTimeNs = System.nanoTime();
mPausedDurationNs = 0;
@@ -166,42 +165,42 @@ public class BenchmarkRunner {
return null;
}
- /** Waits for the broadcast queue and the CPU cores to be idle. */
+ /** Waits for the CPU cores and the broadcast queue to be idle. */
public void waitCoolDownPeriod() {
- waitForBroadcastIdle();
waitForCpuIdle();
+ waitForBroadcastIdle();
}
private void waitForBroadcastIdle() {
- Log.d(TAG, "starting to waitForBroadcastIdle");
- final long startedAt = System.currentTimeMillis();
- ShellHelper.runShellCommand("am wait-for-broadcast-idle --flush-broadcast-loopers");
- final long elapsed = System.currentTimeMillis() - startedAt;
- Log.d(TAG, "waitForBroadcastIdle is complete in " + elapsed + " ms");
+ try {
+ ShellHelper.runShellCommandWithTimeout(
+ "am wait-for-broadcast-idle --flush-broadcast-loopers", TIMEOUT_IN_SECONDS);
+ } catch (TimeoutException e) {
+ Log.e(TAG, "Ending waitForBroadcastIdle because it didn't finish in "
+ + TIMEOUT_IN_SECONDS + " seconds", e);
+ }
}
+
private void waitForCpuIdle() {
- Log.d(TAG, "starting to waitForCpuIdle");
- final long startedAt = System.currentTimeMillis();
- while (true) {
- final int idleCpuPercentage = getIdleCpuPercentage();
- final long elapsed = System.currentTimeMillis() - startedAt;
- Log.d(TAG, "waitForCpuIdle " + idleCpuPercentage + "% (" + elapsed + "ms elapsed)");
- if (idleCpuPercentage >= CPU_IDLE_THRESHOLD_PERCENTAGE) {
- Log.d(TAG, "waitForCpuIdle is complete in " + elapsed + " ms");
- return;
- }
- if (elapsed >= CPU_IDLE_TIMEOUT_MS) {
- Log.e(TAG, "Ending waitForCpuIdle because it didn't finish in "
- + CPU_IDLE_TIMEOUT_MS + " ms");
+ int count = 0;
+ int idleCpuPercentage;
+ while (count++ < TIMEOUT_IN_SECONDS) {
+ idleCpuPercentage = getIdleCpuPercentage();
+ Log.d(TAG, "Waiting for CPU idle #" + count + "=" + idleCpuPercentage + "%");
+ if (idleCpuPercentage > CPU_IDLE_THRESHOLD_PERCENTAGE) {
return;
}
SystemClock.sleep(1000);
}
+ Log.e(TAG, "Ending waitForCpuIdle because it didn't finish in "
+ + TIMEOUT_IN_SECONDS + " seconds");
}
private int getIdleCpuPercentage() {
String output = ShellHelper.runShellCommand("top -m 1 -n 1");
+
String[] tokens = output.split("\\s+");
+
float totalCpu = -1;
float idleCpu = -1;
for (String token : tokens) {
@@ -211,10 +210,12 @@ public class BenchmarkRunner {
idleCpu = Float.parseFloat(token.split("%")[0]);
}
}
+
if (totalCpu < 0 || idleCpu < 0) {
Log.e(TAG, "Could not get idle cpu percentage, output=" + output);
return -1;
}
+
return (int) (100 * idleCpu / totalCpu);
}
} \ No newline at end of file