summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrank Li <lifr@google.com>2020-05-28 03:54:47 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-05-28 03:54:47 +0000
commit59b66b8f2c3ab4ad3d9ecf372e12a498f0a45f5a (patch)
treeaa813e6a57292870eebe2e3619fcd8e968249a9b /src
parent7b486419f47f2af216c0fcefe84700ad59fab706 (diff)
parentfa91414542efaf8a4ed60cd59953e158e90dd2d4 (diff)
Merge "Change stopwatch accuracy from milliseconds to microseconds" into rvc-dev
Diffstat (limited to 'src')
-rw-r--r--src/android/net/util/Stopwatch.java24
-rw-r--r--src/com/android/networkstack/util/DnsUtils.java11
-rwxr-xr-xsrc/com/android/server/connectivity/NetworkMonitor.java10
3 files changed, 23 insertions, 22 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;
}
}
diff --git a/src/com/android/networkstack/util/DnsUtils.java b/src/com/android/networkstack/util/DnsUtils.java
index c47ccc1..83f2daf 100644
--- a/src/com/android/networkstack/util/DnsUtils.java
+++ b/src/com/android/networkstack/util/DnsUtils.java
@@ -147,7 +147,7 @@ public class DnsUtils {
} catch (TimeoutException | InterruptedException e) {
errorMsg = "Timeout";
} finally {
- logDnsResult(result, watch.stop() /* latency */, logger, type, errorMsg);
+ logDnsResult(result, watch.stop() / 1000 /* latencyMs */, logger, type, errorMsg);
}
if (null != errorMsg) throw new UnknownHostException(host);
@@ -155,8 +155,9 @@ public class DnsUtils {
return result.toArray(new InetAddress[0]);
}
- private static void logDnsResult(@Nullable final List<InetAddress> results, final long latency,
- @Nullable final DnsLogFunc logger, int type, @NonNull final String errorMsg) {
+ private static void logDnsResult(@Nullable final List<InetAddress> results,
+ final long latencyMs, @Nullable final DnsLogFunc logger, int type,
+ @NonNull final String errorMsg) {
if (logger == null) {
return;
}
@@ -166,9 +167,9 @@ public class DnsUtils {
for (InetAddress address : results) {
builder.append(',').append(address.getHostAddress());
}
- logger.log(String.format("%dms OK %s", latency, builder.substring(1)));
+ logger.log(String.format("%dms OK %s", latencyMs, builder.substring(1)));
} else {
- logger.log(String.format("%dms FAIL in type %s %s", latency, dnsTypeToStr(type),
+ logger.log(String.format("%dms FAIL in type %s %s", latencyMs, dnsTypeToStr(type),
errorMsg));
}
}
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index 093118a..8a1b0c7 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -1412,11 +1412,11 @@ public class NetworkMonitor extends StateMachine {
time = watch.stop();
final String strIps = Arrays.toString(ips);
success = (ips != null && ips.length > 0);
- validationLog(PROBE_PRIVDNS, host, String.format("%dms: %s", time, strIps));
+ validationLog(PROBE_PRIVDNS, host, String.format("%dus: %s", time, strIps));
} catch (UnknownHostException uhe) {
time = watch.stop();
validationLog(PROBE_PRIVDNS, host,
- String.format("%dms - Error: %s", time, uhe.getMessage()));
+ String.format("%dus - Error: %s", time, uhe.getMessage()));
}
logValidationProbe(time, PROBE_PRIVDNS, success ? DNS_SUCCESS : DNS_FAILURE);
return success;
@@ -2943,18 +2943,18 @@ public class NetworkMonitor extends StateMachine {
if (mEvaluationTimer.isRunning()) {
int[] transports = mNetworkCapabilities.getTransportTypes();
mMetricsLog.log(mCleartextDnsNetwork, transports,
- new NetworkEvent(evtype, mEvaluationTimer.stop()));
+ new NetworkEvent(evtype, mEvaluationTimer.stop() / 1000));
mEvaluationTimer.reset();
}
}
- private void logValidationProbe(long durationMs, int probeType, int probeResult) {
+ private void logValidationProbe(long durationUs, int probeType, int probeResult) {
int[] transports = mNetworkCapabilities.getTransportTypes();
boolean isFirstValidation = validationStage().mIsFirstValidation;
ValidationProbeEvent ev = new ValidationProbeEvent.Builder()
.setProbeType(probeType, isFirstValidation)
.setReturnCode(probeResult)
- .setDurationMs(durationMs)
+ .setDurationMs(durationUs / 1000)
.build();
mMetricsLog.log(mCleartextDnsNetwork, transports, ev);
}