Merge "Emit trace sections for warmup and benchmark phases" into main
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
index 73bff08..af02374 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
@@ -20,6 +20,7 @@
import android.app.Instrumentation;
import android.os.Bundle;
import android.os.Debug;
+import android.os.Trace;
import android.util.Log;
import androidx.test.InstrumentationRegistry;
@@ -129,17 +130,23 @@
}
private void beginWarmup() {
+ Trace.beginSection("Warmup");
mStartTimeNs = System.nanoTime();
mIteration = 0;
mState = WARMUP;
}
+ private void endWarmup() {
+ Trace.endSection();
+ }
+
private void beginBenchmark(long warmupDuration, int iterations) {
if (ENABLE_PROFILING) {
File f = new File(InstrumentationRegistry.getContext().getDataDir(), "benchprof");
Log.d(TAG, "Tracing to: " + f.getAbsolutePath());
Debug.startMethodTracingSampling(f.getAbsolutePath(), 16 * 1024 * 1024, 100);
}
+ Trace.beginSection("Benchmark");
mMaxIterations = (int) (TARGET_TEST_DURATION_NS / (warmupDuration / iterations));
mMaxIterations = Math.min(MAX_TEST_ITERATIONS,
Math.max(mMaxIterations, MIN_TEST_ITERATIONS));
@@ -150,6 +157,10 @@
mStartTimeNs = System.nanoTime();
}
+ private void endBenchmark() {
+ Trace.endSection();
+ }
+
private boolean startNextTestRun() {
final long currentTime = System.nanoTime();
mResults.add((currentTime - mStartTimeNs - mPausedDurationNs) / mMaxIterations);
@@ -165,6 +176,7 @@
return true;
}
mState = FINISHED;
+ endBenchmark();
return false;
}
mPausedDurationNs = 0;
@@ -189,6 +201,7 @@
// don't yet have a target iteration count.
final long duration = System.nanoTime() - mStartTimeNs;
if (mIteration >= WARMUP_MIN_ITERATIONS && duration >= WARMUP_DURATION_NS) {
+ endWarmup();
beginBenchmark(duration, mIteration);
}
return true;
@@ -208,6 +221,7 @@
mCustomizedIterations++;
if (mCustomizedIterations >= mMaxCustomizedIterations) {
mState = FINISHED;
+ endBenchmark();
return false;
}
mCustomizedIterationListener.onStart(mCustomizedIterations);