Viewing Network Usage Data
Using the command adb shell dumpsys netstats detail
provides network usage statistics collected since the device booted up.
Input
To view network usage statistics, run the following command:
$ adb shell dumpsys netstats detail
Output
The set of information reported varies depending on the version of Android but consists of several sections:
- Active interfaces
- Active UID interfaces
- Dev statistics
- Xt statistics
- UID statistics (sometimes also called "Detailed UID statistics")
- UID tag statistics
Active interfaces/Active UID interfaces
Here is sample output for the active interfaces and active UID interfaces sections:
Active interfaces:
iface=wlan0 ident=[{type=WIFI, subType=COMBINED, networkId="GoogleGuest"}]
Active UID interfaces:
iface=wlan0 ident=[{type=WIFI, subType=COMBINED, networkId="GoogleGuest"}]
This shows network statistics for the whole device. In most cases, the information in these two section is the same.
Dev statistics/Xt statistics
Here is sample output for the Dev statistics section:
Dev stats:
Pending bytes: 170775
Complete history:
ident=[[type=MOBILE_HIPRI, subType=COMBINED, subscriberId=311111...]] uid=-1 set=ALL tag=0x0
NetworkStatsHistory: bucketDuration=3600000
bucketStart=1406138400000 activeTime=3603995 rxBytes=19467 rxPackets=53 txBytes=7500 txPackets=61 operations=0
bucketStart=1406142000000 activeTime=20730 rxBytes=25403 rxPackets=66 txBytes=9140 txPackets=74 operations=0
bucketStart=1406145600000 activeTime=29161 rxBytes=9263 rxPackets=37 txBytes=5180 txPackets=38 operations=0
bucketStart=1406149200000 activeTime=9054 rxBytes=12387 rxPackets=31 txBytes=4052 txPackets=35 operations=0
ident=[[type=WIFI, subType=COMBINED, networkId="MySSID"]] uid=-1 set=ALL tag=0x0
NetworkStatsHistory: bucketDuration=3600000
bucketStart=1406138400000 activeTime=4811082 rxBytes=335913292 rxPackets=265144 txBytes=9729261 txPackets=117220 operations=0
bucketStart=1406142000000 activeTime=3513477 rxBytes=1193606876 rxPackets=956855 txBytes=29450792 txPackets=306634 operations=0
bucketStart=1406145600000 activeTime=3297986 rxBytes=729381849 rxPackets=586396 txBytes=24247211 txPackets=237438 operations=0 bucketStart=1406149200000 activeTime=3580941 rxBytes=57168575 rxPackets=51610 txBytes=5291167 txPackets=29260 operations=0 ident=[[type=WIFI, subType=COMBINED, networkId="MySecondSSID"]] uid=-1 set=ALL tag=0x0 NetworkStatsHistory: bucketDuration=3600000
UID stats
UID stats:
Pending bytes: 744
Complete history:
ident=[[type=MOBILE_SUPL, subType=COMBINED, subscriberId=311111...], [type=MOBILE, subType=COMBINED, subscriberId=311111...]] uid=10007 set=DEFAULT tag=0x0
NetworkStatsHistory: bucketDuration=7200000
bucketStart=1406167200000 activeTime=7200000 rxBytes=4666 rxPackets=7 txBytes=1597 txPackets=10 operations=0
ident=[[type=WIFI, subType=COMBINED, networkId="MySSID"]] uid=10007 set=DEFAULT tag=0x0
NetworkStatsHistory: bucketDuration=7200000
bucketStart=1406138400000 activeTime=7200000 rxBytes=17086802 rxPackets=15387 txBytes=1214969 txPackets=8036 operations=28
bucketStart=1406145600000 activeTime=7200000 rxBytes=2396424 rxPackets=2946 txBytes=464372 txPackets=2609 operations=70
bucketStart=1406152800000 activeTime=7200000 rxBytes=200907 rxPackets=606 txBytes=187418 txPackets=739 operations=0
bucketStart=1406160000000 activeTime=7200000 rxBytes=826017 rxPackets=1126 txBytes=267342 txPackets=1175 operations=35
Interpreting the results
To find the UID for your application, you can run this command: adb shell dumpsys package
. Then look for the line labeled userId
.
In our example, suppose we are trying to find network usage for our app “com.example.myapp”. We would run the following command:
$ adb shell dumpsys package com.example.myapp | grep userId
userId=10007 gids=[3003, 1028, 1015]
Looking at the dump above, we look for lines that have uid=10007. Two such lines exist, the first indicating a mobile connection, and the second a Wi-Fi connection. Underneath each line, the number of bytes and packets sent and received can be seen, bucketed into two-hour windows.
A bit more explanation:
set=DEFAULT
indicates foreground network usage, whileset=BACKGROUND
indicates background usage.set=ALL
implies both.tag=0x0
indicates the socket tag associated with the traffic.rxBytes
andrxPackets
represent received bytes and received packets in the corresponding time interval.txBytes
andtxPackets
represent sent (transmitted) bytes and sent packets in the corresponding time interval.