Merge "Add tx_bytes and rx_bytes to UpstreamEvent message" am: 0f8a7aaede am: dd41476d8e
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2547894
Change-Id: I3ae33f8098f71477f4cc6597be9e7055faac2c05
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java b/Tethering/src/com/android/networkstack/tethering/metrics/TetheringMetrics.java
index de25ff5..814afcd 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 @@
* @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 @@
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 27f2126..b276389 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 @@
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 77950ac..e2c924c 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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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,