aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2024-01-17 22:15:02 -0800
committerXin Li <delphij@google.com>2024-01-17 22:15:02 -0800
commitbcaa5955e825faa76a54c2974c5dde4aba8dadd2 (patch)
treeb07a89c5cfa6e7ca1414520b4e4814312c9bc8f0
parent2a26b9490f90bba1fdba75bcd868d3617cfd93ec (diff)
parentd2d86386131d57c117f749c66a326ddd9f106fe4 (diff)
downloadcontrib-bcaa5955e825faa76a54c2974c5dde4aba8dadd2.tar.gz
Merge Android 24Q1 Release (ab/11220357)temp_319669529
Bug: 319669529 Merged-In: I849c660a18ba2ab514d2811c696250862add883b Change-Id: I03b77226902eea6447c9f4bad5aad6fe4e1db671
-rw-r--r--src/com/android/performance/tests/BootTimeTest.java77
1 files changed, 61 insertions, 16 deletions
diff --git a/src/com/android/performance/tests/BootTimeTest.java b/src/com/android/performance/tests/BootTimeTest.java
index 1ef102b..ebc0fff 100644
--- a/src/com/android/performance/tests/BootTimeTest.java
+++ b/src/com/android/performance/tests/BootTimeTest.java
@@ -109,7 +109,7 @@ public class BootTimeTest extends InstalledInstrumentationsTest
private static final String LOGCAT_FILE = "Successive_reboots_logcat";
private static final String LOGCAT_UNLOCK_FILE = "Successive_reboots_unlock_logcat";
private static final String BOOT_COMPLETE_ACTION = "sys.boot_completed=1";
- private static final String RUNNER = "android.support.test.runner.AndroidJUnitRunner";
+ private static final String RUNNER = "androidx.test.runner.AndroidJUnitRunner";
private static final String PACKAGE_NAME = "com.android.boothelper";
private static final String CLASS_NAME = "com.android.boothelper.BootHelperTest";
private static final String SETUP_PIN_TEST = "setupLockScreenPin";
@@ -192,6 +192,8 @@ public class BootTimeTest extends InstalledInstrumentationsTest
"Logging for this PID.*\\s+([0-9]+)$",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
+ private static final String METRIC_COUNT = "MetricCount";
+
@Option(name = "test-run-name", description = "run name to report to result reporters")
private String mTestRunName = BOOTTIME_TEST;
@@ -245,6 +247,12 @@ public class BootTimeTest extends InstalledInstrumentationsTest
private long mBootDelayTime = 2000;
@Option(
+ name = "after-boot-delay",
+ isTimeVal = true,
+ description = "Time to wait immediately after the successive boots.")
+ private long mAfterBootDelayTime = 0;
+
+ @Option(
name = "post-initial-boot-idle",
isTimeVal = true,
description =
@@ -334,6 +342,13 @@ public class BootTimeTest extends InstalledInstrumentationsTest
description = "Run logcat --statistics command and collect data")
private boolean mCollectLogcat = false;
+ @Option(
+ name = "metric-prefix-pattern-for-count",
+ description =
+ "A list of metric prefix pattern that will be used to count number of metrics"
+ + " generated in the test")
+ private List<String> mMetricPrefixPatternForCount = new ArrayList<>();
+
private IBuildInfo mBuildInfo;
private IConfiguration mConfiguration;
private TestInformation mTestInfo;
@@ -412,6 +427,9 @@ public class BootTimeTest extends InstalledInstrumentationsTest
mTestInfo = testInfo;
long start = System.currentTimeMillis();
listener.testRunStarted(mTestRunName, 1);
+ for (IMetricCollector collector : mCollectors) {
+ listener = collector.init(mInvocationContext, listener);
+ }
try {
try {
// Set the current date from the host in test device.
@@ -487,10 +505,13 @@ public class BootTimeTest extends InstalledInstrumentationsTest
}
testSuccessiveBoots(true, listener);
} finally {
- try (InputStreamSource logcatData = mRebootLogcatReceiver.getLogcatData()) {
- listener.testLog(LOGCAT_UNLOCK_FILE, LogDataType.TEXT, logcatData);
+ if (null != mRebootLogcatReceiver) {
+ try (InputStreamSource logcatData =
+ mRebootLogcatReceiver.getLogcatData()) {
+ listener.testLog(LOGCAT_UNLOCK_FILE, LogDataType.TEXT, logcatData);
+ }
+ mRebootLogcatReceiver.stop();
}
- mRebootLogcatReceiver.stop();
listener.testStarted(successiveBootUnlockTestId);
listener.testEnded(successiveBootUnlockTestId, successiveBootUnlockResult);
}
@@ -598,9 +619,6 @@ public class BootTimeTest extends InstalledInstrumentationsTest
throws DeviceNotAvailableException {
CLog.v("Waiting for %d msecs before successive boots.", mBootDelayTime);
getRunUtil().sleep(mBootDelayTime);
- for (IMetricCollector collector : mCollectors) {
- listener = collector.init(mInvocationContext, listener);
- }
for (int count = 0; count < mBootCount; count++) {
getDevice().enableAdbRoot();
// Property used for collecting the perfetto trace file on boot.
@@ -620,10 +638,14 @@ public class BootTimeTest extends InstalledInstrumentationsTest
double onlineTime = INVALID_TIME_DURATION;
double bootTime = INVALID_TIME_DURATION;
String testId = String.format("%s.%s$%d", BOOTTIME_TEST, BOOTTIME_TEST, (count + 1));
- TestDescription successiveBootIterationTestId =
- new TestDescription(testId, String.format("%s", SUCCESSIVE_BOOT_TEST));
- if (mBootTimePerIteration) {
- listener.testStarted(successiveBootIterationTestId);
+ TestDescription successiveBootIterationTestId;
+ if (!dismissPin) {
+ successiveBootIterationTestId =
+ new TestDescription(testId, String.format("%s", SUCCESSIVE_BOOT_TEST));
+ } else {
+ successiveBootIterationTestId =
+ new TestDescription(
+ testId, String.format("%s", SUCCESSIVE_BOOT_UNLOCK_TEST));
}
if (mGranularBootInfo || dismissPin) {
clearAndStartLogcat();
@@ -677,12 +699,17 @@ public class BootTimeTest extends InstalledInstrumentationsTest
if (mBootloaderInfo) analyzeBootloaderTimingInfo();
if (dismissPin) {
+ getRunUtil().sleep(2000);
mRunner = createRemoteAndroidTestRunner(UNLOCK_PIN_TEST);
getDevice().runInstrumentationTests(mRunner, new CollectingTestListener());
- // Wait for 15 secs after every unlock to make sure home screen is loaded
- // and logs are printed
- getRunUtil().sleep(15000);
}
+
+ if (mBootTimePerIteration) {
+ listener.testStarted(successiveBootIterationTestId);
+ }
+
+ CLog.v("Waiting for %d msecs immediately after successive boot.", mAfterBootDelayTime);
+ getRunUtil().sleep(mAfterBootDelayTime);
if (onlineTime != INVALID_TIME_DURATION) {
if (mBootInfo.containsKey(SUCCESSIVE_ONLINE)) {
mBootInfo.get(SUCCESSIVE_ONLINE).add(onlineTime);
@@ -739,6 +766,22 @@ public class BootTimeTest extends InstalledInstrumentationsTest
if (!collectLogcatInfoResult.isEmpty()) {
iterationResult.putAll(collectLogcatInfoResult);
}
+ // If metric-prefix-pattern-for-count is present, calculate the count
+ // of all metrics with the prefix pattern and add the count as a new metric to the
+ // iterationResult map.
+ if (!mMetricPrefixPatternForCount.isEmpty()) {
+ for (String metricPrefixPattern : mMetricPrefixPatternForCount) {
+ long metricCount =
+ iterationResult.entrySet().stream()
+ .filter(
+ (entry) ->
+ entry.getKey()
+ .startsWith(metricPrefixPattern))
+ .count();
+ iterationResult.put(
+ metricPrefixPattern + METRIC_COUNT, Long.toString(metricCount));
+ }
+ }
listener.testEnded(successiveBootIterationTestId, iterationResult);
}
@@ -848,10 +891,13 @@ public class BootTimeTest extends InstalledInstrumentationsTest
Matcher matcherPid = LOGCAT_STATISTICS_PID_PATTERN.matcher(outputList[i]);
pidFound = matcherPid.find();
if (!pidFound) continue;
- CLog.d("logcat statistics pid %d output = %s", pid, outputList[i]);
+ CLog.d(
+ "Process %s with pid %d : logcat statistics output = %s",
+ processName, pid, outputList[i]);
results.put(
String.join(METRIC_KEY_SEPARATOR, LOGCAT_STATISTICS_SIZE, processName),
matcherPid.group(1).trim());
+ break;
}
if (!pidFound) {
// the process doesn't found in the logcat statistics output
@@ -860,7 +906,6 @@ public class BootTimeTest extends InstalledInstrumentationsTest
processName, pid);
}
}
-
return results;
}