diff options
author | Frank Li <lifr@google.com> | 2020-06-23 01:14:15 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-06-23 01:14:15 +0000 |
commit | 7f626e3b43cdfb6caa52929e479e9642004f7b77 (patch) | |
tree | 583f34f8d0a1d83453b03cbe9933e5c6fa7aec6f | |
parent | 00c2dd8e265200e340337c3b7e898e306810387e (diff) | |
parent | 0c423089f7c64ab82461be73778e067872789f8b (diff) |
Fix the mStopTimeNs not be reset in Stopwatch#Restart am: 0c423089f7
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/11931260
Change-Id: I80f0e311be8b2199090b7e7cd17e8b4641babe8e
-rw-r--r-- | src/android/net/ip/IpClient.java | 8 | ||||
-rw-r--r-- | src/android/net/util/Stopwatch.java | 3 | ||||
-rw-r--r-- | tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java | 24 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/android/net/ip/IpClient.java b/src/android/net/ip/IpClient.java index eeff157..1591f43 100644 --- a/src/android/net/ip/IpClient.java +++ b/src/android/net/ip/IpClient.java @@ -819,11 +819,11 @@ public class IpClient extends StateMachine { * Stop this IpClient. * * <p>This does not shut down the StateMachine itself, which is handled by {@link #shutdown()}. + * The message "arg1" parameter is used to record the disconnect code metrics. + * Usually this method is called by the peer (e.g. wifi) intentionally to stop IpClient, + * consider that's the normal user termination. */ public void stop() { - // The message "arg1" parameter is used to record the disconnect code metrics. - // Usually this method is called by the peer (e.g. wifi) intentionally to stop IpClient, - // consider that's the normal user termination. sendMessage(CMD_STOP, DisconnectCode.DC_NORMAL_TERMINATION.getNumber()); } @@ -1079,8 +1079,6 @@ public class IpClient extends StateMachine { } // Record the DisconnectCode and transition to StoppingState. - // When jumping to mStoppingState This function will ensure - // that you will not forget to fill in DisconnectCode. private void transitionToStoppingState(final DisconnectCode code) { mIpProvisioningMetrics.setDisconnectCode(code); transitionTo(mStoppingState); diff --git a/src/android/net/util/Stopwatch.java b/src/android/net/util/Stopwatch.java index 33653dd..88e523e 100644 --- a/src/android/net/util/Stopwatch.java +++ b/src/android/net/util/Stopwatch.java @@ -49,10 +49,11 @@ public class Stopwatch { } /** - * Retart the Stopwatch. + * Restart the Stopwatch. */ public Stopwatch restart() { mStartTimeNs = SystemClock.elapsedRealtimeNanos(); + mStopTimeNs = 0; return this; } diff --git a/tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java b/tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java index 39906e2..08812b7 100644 --- a/tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java +++ b/tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java @@ -23,6 +23,7 @@ import android.stats.connectivity.DisconnectCode; import android.stats.connectivity.HostnameTransResult; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -122,6 +123,9 @@ public class NetworkIpProvisioningMetricsTest { mMetrics.setDisconnectCode(DisconnectCode.DC_PROVISIONING_TIMEOUT); mMetrics.setDisconnectCode(DisconnectCode.DC_ERROR_STARTING_IPV4); + mMetrics.setIPv4ProvisionedLatencyOnFirstTime(true); + mMetrics.setIPv6ProvisionedLatencyOnFirstTime(true); + // Writing the metrics into statsd mStats = mMetrics.statsWrite(); @@ -133,5 +137,25 @@ public class NetworkIpProvisioningMetricsTest { assertEquals(6, mStats.getDhcpSession().getErrorCodeCount()); assertEquals(HostnameTransResult.HTR_SUCCESS, mStats.getDhcpSession().getHtResult()); assertEquals(DisconnectCode.DC_PROVISIONING_TIMEOUT, mStats.getDisconnectCode()); + assertTrue(mStats.getIpv4LatencyMicros() >= 0); + assertTrue(mStats.getIpv6LatencyMicros() >= 0); + assertTrue(mStats.getProvisioningDurationMicros() >= 0); + } + + @Test + public void testIpProvisioningMetrics_VerifyConsecutiveMetricsLatency() throws Exception { + final IpProvisioningMetrics metrics = new IpProvisioningMetrics(); + for (int i = 0; i < 2; i++) { + metrics.reset(); + // delay 1 msec. + Thread.sleep(1); + metrics.setIPv4ProvisionedLatencyOnFirstTime(true); + metrics.setIPv6ProvisionedLatencyOnFirstTime(true); + NetworkIpProvisioningReported mStats = metrics.statsWrite(); + // Each timer should be greater than 1000. + assertTrue(mStats.getIpv4LatencyMicros() >= 1000); + assertTrue(mStats.getIpv6LatencyMicros() >= 1000); + assertTrue(mStats.getProvisioningDurationMicros() >= 1000); + } } } |