diff options
author | Frank Li <lifr@google.com> | 2020-05-28 04:03:28 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-28 04:03:28 +0000 |
commit | bd1eb4e698c942c567ff29f3e3c0f46c216c768c (patch) | |
tree | aa813e6a57292870eebe2e3619fcd8e968249a9b /src/android/net/util/Stopwatch.java | |
parent | 251bbe024d8ba8991a93b116301ce8c0c1cacb41 (diff) | |
parent | 59b66b8f2c3ab4ad3d9ecf372e12a498f0a45f5a (diff) |
Merge "Change stopwatch accuracy from milliseconds to microseconds" into rvc-dev am: 59b66b8f2c
Change-Id: I07c4df23a6f8b932ce295846f91a9fc89385ce5b
Diffstat (limited to 'src/android/net/util/Stopwatch.java')
-rw-r--r-- | src/android/net/util/Stopwatch.java | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/android/net/util/Stopwatch.java b/src/android/net/util/Stopwatch.java index c316699..07618e9 100644 --- a/src/android/net/util/Stopwatch.java +++ b/src/android/net/util/Stopwatch.java @@ -23,15 +23,15 @@ import android.os.SystemClock; * @hide */ public class Stopwatch { - private long mStartTimeMs; - private long mStopTimeMs; + private long mStartTimeNs; + private long mStopTimeNs; public boolean isStarted() { - return (mStartTimeMs > 0); + return (mStartTimeNs > 0); } public boolean isStopped() { - return (mStopTimeMs > 0); + return (mStopTimeNs > 0); } public boolean isRunning() { @@ -43,31 +43,31 @@ public class Stopwatch { */ public Stopwatch start() { if (!isStarted()) { - mStartTimeMs = SystemClock.elapsedRealtime(); + mStartTimeNs = SystemClock.elapsedRealtimeNanos(); } return this; } /** * Stop the Stopwatch. - * @return the total time recorded, in milliseconds, or 0 if not started. + * @return the total time recorded, in microseconds, or 0 if not started. */ public long stop() { if (isRunning()) { - mStopTimeMs = SystemClock.elapsedRealtime(); + mStopTimeNs = SystemClock.elapsedRealtimeNanos(); } // Return either the delta after having stopped, or 0. - return (mStopTimeMs - mStartTimeMs); + return (mStopTimeNs - mStartTimeNs) / 1000; } /** - * Return the total time recorded to date, in milliseconds. + * Return the total time recorded to date, in microseconds. * If the Stopwatch is not running, returns the same value as stop(), * i.e. either the total time recorded before stopping or 0. */ public long lap() { if (isRunning()) { - return (SystemClock.elapsedRealtime() - mStartTimeMs); + return (SystemClock.elapsedRealtimeNanos() - mStartTimeNs) / 1000; } else { return stop(); } @@ -77,7 +77,7 @@ public class Stopwatch { * Reset the Stopwatch. It will be stopped when this method returns. */ public void reset() { - mStartTimeMs = 0; - mStopTimeMs = 0; + mStartTimeNs = 0; + mStopTimeNs = 0; } } |