blob: f22e35a2f6d4f1c6d4fd2b61ffa4dca0042aef37 [file] [log] [blame]
<html devsite><head>
<title>查看网络使用情况数据</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>使用命令 <code>adb shell dumpsys netstats detail</code> 提供自设备启动后收集的网络使用情况统计信息。</p>
<h2 id="input">输入</h2>
<p>要查看网络使用情况统计信息,请运行以下命令:</p>
<pre class="prettyprint">
$ adb shell dumpsys netstats detail
</pre>
<h2 id="output">输出</h2>
<p>报告的一系列信息因 Android 的版本而异,但由以下几个部分组成:</p>
<ul>
<li> 活动接口
</li><li> 活动 UID 接口
</li><li> 开发统计信息
</li><li> Xt 统计信息
</li><li> UID 统计信息(有时也称为“详细的 UID 统计信息”)
</li><li> UID 代码统计信息
</li></ul>
<h3 id="active_interfaces_active_uid_interfaces">活动接口/活动 UID 接口</h3>
<p>以下是活动接口和活动 UID 接口部分的输出示例:</p>
<pre>
Active interfaces:
iface=wlan0 ident=[{type=WIFI, subType=COMBINED, networkId="GoogleGuest"}]
Active UID interfaces:
iface=wlan0 ident=[{type=WIFI, subType=COMBINED, networkId="GoogleGuest"}]
</pre>
<p>此处显示的是整个设备的网络统计信息。在大多数情况下,这两个部分的信息是相同的。</p>
<h3 id="dev_stats_xt_stats">开发统计信息/Xt 统计信息</h3>
<p>以下是开发统计信息部分的输出示例:</p>
<pre>
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
</pre>
<h3 id="uid_stats">UID 统计信息</h3>
<pre>
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
</pre>
<h3 id="interpreting_the_results">解读结果</h3>
<p>要查找应用的 UID,您可以运行以下命令:
<code>adb shell dumpsys package &lt;your package name&gt;</code>
然后查找标有 <code>userId</code> 的行。</p>
<p>在我们的示例中,假设我们要了解应用“com.example.myapp”的网络使用情况,则可以运行以下命令:</p>
<pre>
$ adb shell dumpsys package com.example.myapp | grep userId
userId=10007 gids=[3003, 1028, 1015]
</pre>
<p>在上面的 dumpsys 命令中,我们查找包含 uid = 10007 的行。符合条件的行有两个,第一个表示移动数据连接,第二个表示 WLAN 连接。在每行的下方,可以看到发送和接收的字节数和数据包数,bucket 为两小时时间窗口。</p>
<p>以下是进一步说明:</p>
<ul>
<li> <code>set=DEFAULT</code> 表示前台网络使用情况,<code>set=BACKGROUND</code> 表示后台使用情况,<code>set=ALL</code> 表示上述两类使用情况。
</li><li> <code>tag=0x0</code> 表示与流量关联的套接字代码。
</li><li> <code>rxBytes</code><code>rxPackets</code> 表示在相应时间间隔内接收的字节数和数据包数。
</li><li> <code>txBytes</code><code>txPackets</code> 表示在相应时间间隔内发送(传输)的字节数和数据包数。
</li></ul>
</body></html>