summaryrefslogtreecommitdiff
path: root/apct-tests/perftests/utils
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2016-10-14 15:05:05 -0700
committerJohn Reck <jreck@google.com>2016-10-17 13:49:16 -0700
commitc1d6ba4053b4d5f7a9c3c255073d22fbe4af392f (patch)
tree85db120f684c137cd56b0767bc91adf97db858ac /apct-tests/perftests/utils
parentc93a7ef9cbba1afe1c1c24b500c3ebf67d4ef9b1 (diff)
Fix pause/resume timing
Test: run SystemPerfTest#testPauseResumeOverhead Change-Id: Icc34355e29f3a6ba8f7d73a904bf549d2685eee4
Diffstat (limited to 'apct-tests/perftests/utils')
-rw-r--r--apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java22
1 files changed, 12 insertions, 10 deletions
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 bf04f6d2013b..519d5248a347 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
@@ -43,13 +43,13 @@ import java.util.concurrent.TimeUnit;
* }
*/
public final class BenchmarkState {
+
private static final String TAG = "BenchmarkState";
private static final int NOT_STARTED = 0; // The benchmark has not started yet.
private static final int WARMUP = 1; // The benchmark is warming up.
private static final int RUNNING = 2; // The benchmark is running.
- private static final int RUNNING_PAUSED = 3; // The benchmark is temporary paused.
- private static final int FINISHED = 4; // The benchmark has stopped.
+ private static final int FINISHED = 3; // The benchmark has stopped.
private int mState = NOT_STARTED; // Current benchmark state.
@@ -63,6 +63,7 @@ public final class BenchmarkState {
private static final int REPEAT_COUNT = 5;
private long mStartTimeNs = 0; // Previously captured System.nanoTime().
+ private boolean mPaused;
private long mPausedTimeNs = 0; // The System.nanoTime() when the pauseTiming() is called.
private long mPausedDurationNs = 0; // The duration of paused state in nano sec.
@@ -118,24 +119,24 @@ public final class BenchmarkState {
// Stops the benchmark timer.
// This method can be called only when the timer is running.
public void pauseTiming() {
- if (mState == RUNNING_PAUSED) {
+ if (mPaused) {
throw new IllegalStateException(
"Unable to pause the benchmark. The benchmark has already paused.");
}
mPausedTimeNs = System.nanoTime();
- mState = RUNNING_PAUSED;
+ mPaused = true;
}
// Starts the benchmark timer.
// This method can be called only when the timer is stopped.
public void resumeTiming() {
- if (mState == RUNNING) {
+ if (!mPaused) {
throw new IllegalStateException(
"Unable to resume the benchmark. The benchmark is already running.");
}
mPausedDurationNs += System.nanoTime() - mPausedTimeNs;
mPausedTimeNs = 0;
- mState = RUNNING;
+ mPaused = false;
}
private void beginWarmup() {
@@ -194,11 +195,12 @@ public final class BenchmarkState {
if (mIteration >= mMaxIterations) {
return startNextTestRun();
}
+ if (mPaused) {
+ throw new IllegalStateException(
+ "Benchmark step finished with paused state. " +
+ "Resume the benchmark before finishing each step.");
+ }
return true;
- case RUNNING_PAUSED:
- throw new IllegalStateException(
- "Benchmark step finished with paused state. " +
- "Resume the benchmark before finishing each step.");
case FINISHED:
throw new IllegalStateException("The benchmark has finished.");
default: