Gina Dimino | 61e55ad | 2015-04-09 16:42:14 -0700 | [diff] [blame] | 1 | page.title=Viewing Network Usage Data |
| 2 | @jd:body |
| 3 | |
| 4 | <!-- |
| 5 | Copyright 2015 The Android Open Source Project |
| 6 | |
| 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | --> |
| 19 | |
| 20 | <p>Using the command <code>adb shell dumpsys netstats detail</code> provides |
| 21 | network usage statistics collected since the device booted up.</p> |
| 22 | |
| 23 | <h2 id=input>Input</h2> |
| 24 | |
| 25 | |
| 26 | <p>To view network usage statistics, run the following command:</p> |
| 27 | |
| 28 | <pre class=prettyprint> |
| 29 | $ adb shell dumpsys netstats detail |
| 30 | </pre> |
| 31 | |
| 32 | |
| 33 | <h2 id=output>Output</h2> |
| 34 | |
| 35 | |
| 36 | <p>The set of information reported varies depending on the version of Android but |
| 37 | consists of several sections: </p> |
| 38 | |
| 39 | <ul> |
| 40 | <li> Active interfaces |
| 41 | <li> Active UID interfaces |
| 42 | <li> Dev statistics |
| 43 | <li> Xt statistics |
| 44 | <li> UID statistics (sometimes also called "Detailed UID statistics") |
| 45 | <li> UID tag statistics |
| 46 | </ul> |
| 47 | |
| 48 | <h3 id=active_interfaces_active_uid_interfaces>Active interfaces/Active UID interfaces</h3> |
| 49 | |
| 50 | <p>Here is sample output for the active interfaces and active UID interfaces |
| 51 | sections:</p> |
| 52 | |
| 53 | <pre> |
| 54 | Active interfaces: |
| 55 | iface=wlan0 ident=[{type=WIFI, subType=COMBINED, networkId="GoogleGuest"}] |
| 56 | Active UID interfaces: |
| 57 | iface=wlan0 ident=[{type=WIFI, subType=COMBINED, networkId="GoogleGuest"}] |
| 58 | </pre> |
| 59 | |
| 60 | |
| 61 | <p>This shows network statistics for the whole device. In most cases, the |
| 62 | information in these two section is the same.</p> |
| 63 | |
| 64 | <h3 id=dev_stats_xt_stats>Dev statistics/Xt statistics</h3> |
| 65 | |
| 66 | |
| 67 | <p>Here is sample output for the Dev statistics section:</p> |
| 68 | |
| 69 | <pre> |
| 70 | Dev stats: |
| 71 | Pending bytes: 170775 |
| 72 | Complete history: |
| 73 | ident=[[type=MOBILE_HIPRI, subType=COMBINED, subscriberId=311111...]] uid=-1 set=ALL tag=0x0 |
| 74 | NetworkStatsHistory: bucketDuration=3600000 |
| 75 | bucketStart=1406138400000 activeTime=3603995 rxBytes=19467 rxPackets=53 txBytes=7500 txPackets=61 operations=0 |
| 76 | bucketStart=1406142000000 activeTime=20730 rxBytes=25403 rxPackets=66 txBytes=9140 txPackets=74 operations=0 |
| 77 | bucketStart=1406145600000 activeTime=29161 rxBytes=9263 rxPackets=37 txBytes=5180 txPackets=38 operations=0 |
| 78 | bucketStart=1406149200000 activeTime=9054 rxBytes=12387 rxPackets=31 txBytes=4052 txPackets=35 operations=0 |
| 79 | ident=[[type=WIFI, subType=COMBINED, networkId="MySSID"]] uid=-1 set=ALL tag=0x0 |
| 80 | NetworkStatsHistory: bucketDuration=3600000 |
| 81 | bucketStart=1406138400000 activeTime=4811082 rxBytes=335913292 rxPackets=265144 txBytes=9729261 txPackets=117220 operations=0 |
| 82 | bucketStart=1406142000000 activeTime=3513477 rxBytes=1193606876 rxPackets=956855 txBytes=29450792 txPackets=306634 operations=0 |
| 83 | bucketStart=1406145600000 activeTime=3297986 rxBytes=729381849 rxPackets=586396 txBytes=24247211 txPackets=237438 operations=0 |
| 84 | bucketStart=1406149200000 activeTime=3580941 rxBytes=57168575 rxPackets=51610 txBytes=5291167 txPackets=29260 operations=0 |
| 85 | ident=[[type=WIFI, subType=COMBINED, networkId="MySecondSSID"]] uid=-1 set=ALL tag=0x0 |
| 86 | NetworkStatsHistory: bucketDuration=3600000 |
| 87 | </pre> |
| 88 | |
| 89 | <h3 id=uid_stats>UID stats</h3> |
| 90 | |
| 91 | <pre> |
| 92 | UID stats: |
| 93 | Pending bytes: 744 |
| 94 | Complete history: |
| 95 | ident=[[type=MOBILE_SUPL, subType=COMBINED, subscriberId=311111...], [type=MOBILE, subType=COMBINED, subscriberId=311111...]] uid=10007 set=DEFAULT tag=0x0 |
| 96 | NetworkStatsHistory: bucketDuration=7200000 |
| 97 | bucketStart=1406167200000 activeTime=7200000 rxBytes=4666 rxPackets=7 txBytes=1597 txPackets=10 operations=0 |
| 98 | ident=[[type=WIFI, subType=COMBINED, networkId="MySSID"]] uid=10007 set=DEFAULT tag=0x0 |
| 99 | NetworkStatsHistory: bucketDuration=7200000 |
| 100 | bucketStart=1406138400000 activeTime=7200000 rxBytes=17086802 rxPackets=15387 txBytes=1214969 txPackets=8036 operations=28 |
| 101 | bucketStart=1406145600000 activeTime=7200000 rxBytes=2396424 rxPackets=2946 txBytes=464372 txPackets=2609 operations=70 |
| 102 | bucketStart=1406152800000 activeTime=7200000 rxBytes=200907 rxPackets=606 txBytes=187418 txPackets=739 operations=0 |
| 103 | bucketStart=1406160000000 activeTime=7200000 rxBytes=826017 rxPackets=1126 txBytes=267342 txPackets=1175 operations=35 |
| 104 | </pre> |
| 105 | |
| 106 | |
| 107 | <h3 id=interpreting_the_results>Interpreting the results</h3> |
| 108 | |
| 109 | |
| 110 | <p>To find the UID for your application, you can run this command: |
| 111 | <code>adb shell dumpsys package <your package name></code>. |
| 112 | Then look for the line labeled <code>userId</code>.</p> |
| 113 | |
| 114 | <p>In our example, suppose we are trying to find network usage for our app |
| 115 | “com.example.myapp”. We would run the following command:</p> |
| 116 | |
| 117 | <pre> |
| 118 | $ adb shell dumpsys package com.example.myapp | grep userId |
| 119 | |
| 120 | userId=10007 gids=[3003, 1028, 1015] |
| 121 | </pre> |
| 122 | |
| 123 | <p>Looking at the dump above, we look for lines that have uid=10007. Two such |
| 124 | lines exist, the first indicating a mobile connection, and the second a Wi-Fi |
| 125 | connection. Underneath each line, the number of bytes and packets sent and |
| 126 | received can be seen, bucketed into two-hour windows. </p> |
| 127 | |
| 128 | <p>A bit more explanation:</p> |
| 129 | |
| 130 | <ul> |
| 131 | <li> <code>set=DEFAULT</code> indicates foreground |
| 132 | network usage, while <code>set=BACKGROUND</code> indicates |
| 133 | background usage. <code>set=ALL</code> implies both. |
| 134 | <li> <code>tag=0x0</code> indicates the socket tag associated with the traffic. |
| 135 | <li> <code>rxBytes</code> and <code>rxPackets</code> represent received bytes and received packets in the |
| 136 | corresponding time interval. |
| 137 | <li> <code>txBytes</code> and <code>txPackets</code> represent sent (transmitted) bytes and sent packets in |
| 138 | the corresponding time interval. |
| 139 | </ul> |
| 140 | |