Loading src/android/net/ip/IpClient.java +3 −5 Original line number Diff line number Diff line Loading @@ -824,11 +824,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()); } Loading Loading @@ -1084,8 +1084,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); Loading src/android/net/util/Stopwatch.java +2 −1 Original line number Diff line number Diff line Loading @@ -49,10 +49,11 @@ public class Stopwatch { } /** * Retart the Stopwatch. * Restart the Stopwatch. */ public Stopwatch restart() { mStartTimeNs = SystemClock.elapsedRealtimeNanos(); mStopTimeNs = 0; return this; } Loading tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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); } } } Loading
src/android/net/ip/IpClient.java +3 −5 Original line number Diff line number Diff line Loading @@ -824,11 +824,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()); } Loading Loading @@ -1084,8 +1084,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); Loading
src/android/net/util/Stopwatch.java +2 −1 Original line number Diff line number Diff line Loading @@ -49,10 +49,11 @@ public class Stopwatch { } /** * Retart the Stopwatch. * Restart the Stopwatch. */ public Stopwatch restart() { mStartTimeNs = SystemClock.elapsedRealtimeNanos(); mStopTimeNs = 0; return this; } Loading
tests/unit/src/com/android/networkstack/metrics/NetworkIpProvisioningMetricsTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading @@ -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); } } }