From b5ee365614c93645dc5b3615db64985d70321d7e Mon Sep 17 00:00:00 2001 From: Wayne Ma Date: Thu, 20 Apr 2023 11:04:11 +0800 Subject: [PATCH] Add tx_bytes and rx_bytes to UpstreamEvent message This commit adds two new fields, tx_bytes and rx_bytes, to the UpstreamEvent message. These fields provide information about the amount of data transferred during the event, which can be useful for network performance analysis. The current tx/rx usages are always zero, but it will be updated in a later change to reflect the actual usage. No changes were made to the existing fields upstream_type and duration_millis. Test: atest TetheringMetricsTest Change-Id: I9e1043b3fff5aa3f548b8696bac7e5bc4271c77c --- .../tethering/metrics/TetheringMetrics.java | 13 +++++--- .../tethering/metrics/stats.proto | 14 +++++++-- .../metrics/TetheringMetricsTest.java | 31 ++++++++++--------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java b/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java index de25ff56ef..814afcdba3 100644 --- a/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java +++ b/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java @@ -166,10 +166,13 @@ public class TetheringMetrics { * @param upstream the type of upstream type (e.g. Wifi, Cellular, Bluetooth, ...) */ private void addUpstreamEvent(final UpstreamEvents.Builder upstreamEventsBuilder, - final long start, final long stop, @Nullable final UpstreamType upstream) { + final long start, final long stop, @Nullable final UpstreamType upstream, + final long txBytes, final long rxBytes) { final UpstreamEvent.Builder upstreamEventBuilder = UpstreamEvent.newBuilder() .setUpstreamType(upstream == null ? UpstreamType.UT_NO_NETWORK : upstream) - .setDurationMillis(stop - start); + .setDurationMillis(stop - start) + .setTxBytes(txBytes) + .setRxBytes(rxBytes); upstreamEventsBuilder.addUpstreamEvent(upstreamEventBuilder); } @@ -193,18 +196,20 @@ public class TetheringMetrics { private void noteDownstreamStopped(final NetworkTetheringReported.Builder statsBuilder, final long downstreamStartTime) { UpstreamEvents.Builder upstreamEventsBuilder = UpstreamEvents.newBuilder(); + for (RecordUpstreamEvent event : mUpstreamEventList) { if (downstreamStartTime > event.mStopTime) continue; final long startTime = Math.max(downstreamStartTime, event.mStartTime); // Handle completed upstream events. addUpstreamEvent(upstreamEventsBuilder, startTime, event.mStopTime, - event.mUpstreamType); + event.mUpstreamType, 0L /* txBytes */, 0L /* rxBytes */); } final long startTime = Math.max(downstreamStartTime, mCurrentUpStreamStartTime); final long stopTime = timeNow(); // Handle the last upstream event. - addUpstreamEvent(upstreamEventsBuilder, startTime, stopTime, mCurrentUpstream); + addUpstreamEvent(upstreamEventsBuilder, startTime, stopTime, mCurrentUpstream, + 0L /* txBytes */, 0L /* rxBytes */); statsBuilder.setUpstreamEvents(upstreamEventsBuilder); statsBuilder.setDurationMillis(stopTime - downstreamStartTime); } diff --git a/Tethering/src/com/android/networkstack/tethering/metrics/stats.proto b/Tethering/src/com/android/networkstack/tethering/metrics/stats.proto index 27f2126655..b276389757 100644 --- a/Tethering/src/com/android/networkstack/tethering/metrics/stats.proto +++ b/Tethering/src/com/android/networkstack/tethering/metrics/stats.proto @@ -21,13 +21,21 @@ package com.android.networkstack.tethering.metrics; import "frameworks/proto_logging/stats/enums/stats/connectivity/tethering.proto"; -// Logs each upstream for a successful switch over +/** + * Represents an event that logs information about a successful switch to an upstream network. + */ message UpstreamEvent { - // Transport type of upstream network + // Indicates the transport type of network. optional .android.stats.connectivity.UpstreamType upstream_type = 1; - // A time period that an upstream continued + // The duration of network usage. optional int64 duration_millis = 2; + + // The amount of data received from tethered clients. + optional int64 tx_bytes = 3; + + // The amount of data received from remote. + optional int64 rx_bytes = 4; } message UpstreamEvents { diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java index 77950acfac..e2c924c4a7 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java @@ -150,10 +150,13 @@ public final class TetheringMetricsTest { } private void addUpstreamEvent(UpstreamEvents.Builder upstreamEvents, - final UpstreamType expectedResult, final long duration) { + final UpstreamType expectedResult, final long duration, final long txBytes, + final long rxBytes) { UpstreamEvent.Builder upstreamEvent = UpstreamEvent.newBuilder() .setUpstreamType(expectedResult) - .setDurationMillis(duration); + .setDurationMillis(duration) + .setTxBytes(txBytes) + .setRxBytes(rxBytes); upstreamEvents.addUpstreamEvent(upstreamEvent); } @@ -164,7 +167,7 @@ public final class TetheringMetricsTest { incrementCurrentTime(duration); UpstreamEvents.Builder upstreamEvents = UpstreamEvents.newBuilder(); // Set UpstreamType as NO_NETWORK because the upstream type has not been changed. - addUpstreamEvent(upstreamEvents, UpstreamType.UT_NO_NETWORK, duration); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_NO_NETWORK, duration, 0L, 0L); updateErrorAndSendReport(type, TETHER_ERROR_NO_ERROR); verifyReport(expectedResult, ErrorCode.EC_NO_ERROR, UserType.USER_UNKNOWN, @@ -193,7 +196,7 @@ public final class TetheringMetricsTest { updateErrorAndSendReport(TETHERING_WIFI, errorCode); UpstreamEvents.Builder upstreamEvents = UpstreamEvents.newBuilder(); - addUpstreamEvent(upstreamEvents, UpstreamType.UT_WIFI, duration); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_WIFI, duration, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_WIFI, expectedResult, UserType.USER_UNKNOWN, upstreamEvents, getElapsedRealtime()); reset(mTetheringMetrics); @@ -235,7 +238,7 @@ public final class TetheringMetricsTest { UpstreamEvents.Builder upstreamEvents = UpstreamEvents.newBuilder(); // Set UpstreamType as NO_NETWORK because the upstream type has not been changed. - addUpstreamEvent(upstreamEvents, UpstreamType.UT_NO_NETWORK, duration); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_NO_NETWORK, duration, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_WIFI, ErrorCode.EC_NO_ERROR, expectedResult, upstreamEvents, getElapsedRealtime()); reset(mTetheringMetrics); @@ -260,7 +263,7 @@ public final class TetheringMetricsTest { updateErrorAndSendReport(TETHERING_WIFI, TETHER_ERROR_NO_ERROR); UpstreamEvents.Builder upstreamEvents = UpstreamEvents.newBuilder(); - addUpstreamEvent(upstreamEvents, expectedResult, duration); + addUpstreamEvent(upstreamEvents, expectedResult, duration, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_WIFI, ErrorCode.EC_NO_ERROR, UserType.USER_UNKNOWN, upstreamEvents, getElapsedRealtime()); reset(mTetheringMetrics); @@ -296,7 +299,7 @@ public final class TetheringMetricsTest { UpstreamEvents.Builder wifiTetheringUpstreamEvents = UpstreamEvents.newBuilder(); addUpstreamEvent(wifiTetheringUpstreamEvents, UpstreamType.UT_NO_NETWORK, - currentTimeMillis() - wifiTetheringStartTime); + currentTimeMillis() - wifiTetheringStartTime, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_WIFI, ErrorCode.EC_DHCPSERVER_ERROR, UserType.USER_SETTINGS, wifiTetheringUpstreamEvents, currentTimeMillis() - wifiTetheringStartTime); @@ -305,7 +308,7 @@ public final class TetheringMetricsTest { UpstreamEvents.Builder usbTetheringUpstreamEvents = UpstreamEvents.newBuilder(); addUpstreamEvent(usbTetheringUpstreamEvents, UpstreamType.UT_NO_NETWORK, - currentTimeMillis() - usbTetheringStartTime); + currentTimeMillis() - usbTetheringStartTime, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_USB, ErrorCode.EC_ENABLE_FORWARDING_ERROR, UserType.USER_SYSTEMUI, usbTetheringUpstreamEvents, @@ -315,7 +318,7 @@ public final class TetheringMetricsTest { UpstreamEvents.Builder bluetoothTetheringUpstreamEvents = UpstreamEvents.newBuilder(); addUpstreamEvent(bluetoothTetheringUpstreamEvents, UpstreamType.UT_NO_NETWORK, - currentTimeMillis() - bluetoothTetheringStartTime); + currentTimeMillis() - bluetoothTetheringStartTime, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_BLUETOOTH, ErrorCode.EC_TETHER_IFACE_ERROR, UserType.USER_GMS, bluetoothTetheringUpstreamEvents, currentTimeMillis() - bluetoothTetheringStartTime); @@ -336,7 +339,7 @@ public final class TetheringMetricsTest { UpstreamEvents.Builder usbTetheringUpstreamEvents = UpstreamEvents.newBuilder(); addUpstreamEvent(usbTetheringUpstreamEvents, UpstreamType.UT_WIFI, - currentTimeMillis() - usbTetheringStartTime); + currentTimeMillis() - usbTetheringStartTime, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_USB, ErrorCode.EC_NO_ERROR, UserType.USER_SYSTEMUI, usbTetheringUpstreamEvents, currentTimeMillis() - usbTetheringStartTime); @@ -345,7 +348,7 @@ public final class TetheringMetricsTest { UpstreamEvents.Builder wifiTetheringUpstreamEvents = UpstreamEvents.newBuilder(); addUpstreamEvent(wifiTetheringUpstreamEvents, UpstreamType.UT_WIFI, - currentTimeMillis() - wifiUpstreamStartTime); + currentTimeMillis() - wifiUpstreamStartTime, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_WIFI, ErrorCode.EC_NO_ERROR, UserType.USER_SETTINGS, wifiTetheringUpstreamEvents, currentTimeMillis() - wifiTetheringStartTime); @@ -368,9 +371,9 @@ public final class TetheringMetricsTest { updateErrorAndSendReport(TETHERING_WIFI, TETHER_ERROR_NO_ERROR); UpstreamEvents.Builder upstreamEvents = UpstreamEvents.newBuilder(); - addUpstreamEvent(upstreamEvents, UpstreamType.UT_WIFI, wifiDuration); - addUpstreamEvent(upstreamEvents, UpstreamType.UT_BLUETOOTH, bluetoothDuration); - addUpstreamEvent(upstreamEvents, UpstreamType.UT_CELLULAR, celltoothDuration); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_WIFI, wifiDuration, 0L, 0L); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_BLUETOOTH, bluetoothDuration, 0L, 0L); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_CELLULAR, celltoothDuration, 0L, 0L); verifyReport(DownstreamType.DS_TETHERING_WIFI, ErrorCode.EC_NO_ERROR, UserType.USER_SETTINGS, upstreamEvents,