使用ADB跟踪应用程序的网络统计信息(netstats)

时间:2012-10-15 22:13:41

标签: android adb netstat

我觉得这是可能的,我只是不太确定信息的位置。

我想获取特定应用程序的up / down统计信息,但我想使用ADB而不是wireshark或netty来完成。

我知道我可以使用

看到vmData
adb shell
cd proc
cd pid#
cat status 

我知道我可以看到netstats使用:

ADB Shell dumpsys netstats details full

给了我这些结果:

Dev stats:

  Pending bytes: 1410076

  Complete history:

  ident=[[type=MOBILE, subType=COMBINED, subscriberId=310260...]] uid=-1 set=ALL tag=0x0
NetworkStatsHistory: bucketDuration=3600000
  bucketStart=1349211600000 activeTime=3600000 rxBytes=19656154 rxPackets=16897 txBytes=615620 txPackets=8084 operations=0
  bucketStart=1349215200000 activeTime=3600000 rxBytes=28854708 rxPackets=23363 txBytes=1037409 txPackets=12206 operations=0
  bucketStart=1349218800000 activeTime=3600000 rxBytes=1839274 rxPackets=1565 txBytes=89791 txPackets=914 operations=0
  bucketStart=1349222400000 activeTime=3600000 rxBytes=17421 rxPackets=88 txBytes=18376 txPackets=95 operations=0
  bucketStart=1349226000000 activeTime=3600000 rxBytes=506966 rxPackets=788 txBytes=96491 txPackets=859 operations=0

不幸的是,这看起来像是一个无法区分应用程序的组合netstat。

所以我的问题是,通过简单地使用命令提示符,有没有办法通过唯一的PID#或应用程序名称来查看网络流量?


修改


好吧我取得了很大的进步

使用此代码

 adb shell cat proc/1638(thePID)/net/dev > C:\netstats.txt 

我可以获得这些信息:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
lo:        3564      28    0    0    0     0          0         0     3564      28    0    0    0     0       0          0
dummy0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet0: 117062940  191775  0    0    0     0          0         0 19344640  177574    0    0    0     0       0          0
rmnet1: 2925492    5450    0    0    0     0          0         0  1448544    5664    0    0    0     0       0          0
rmnet2:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet3:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet4:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet5:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet6:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
rmnet7:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  sit0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  vip0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

不幸的是,在使用来自Android市场的“网络使用”等程序对这些数字进行双重检查后,我发现这些数字是整个设备上下的总数。

所以它仍然留给我,如何/在哪里,像“网络使用”和“备件”这样的程序获取他们的信息?

2 个答案:

答案 0 :(得分:20)

我确定了“备件”和“净用量”从哪里获取信息。

adb shell cat proc/uid_stat/(uid#)/tcp_rcv
adb shell cat proc/uid_stat/(uid#)/tcp_snd

问题我看到他们如何做到这一点虽然这只考虑TCP的使用,并没有考虑和使用UDP。

计算总tx_bytes和rx_bytes的唯一方法是通过此命令。

adb shell cat /proc/net/xt_qtaguid/stats

或者如果您想将其转换为文本文件并更容易查看。

adb shell cat /proc/net/xt_qtaguid/stats > C:\Netstats.txt

这给你一些看起来像这样的东西:

------ QTAGUID STATS INFO (su root cat /proc/net/xt_qtaguid/stats) ------

idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets     rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes   rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
2 rmnet0 0x0 0 0 18393 326 8506 166 10889 267 7504 59 0 0 4180 101 3397 54 929 11
3 rmnet0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 rmnet0 0x0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
5 rmnet0 0x0 1000 1 7181 14 1834 19 7023 12 158 2 0 0 1616 16 218 3 0 0
6 rmnet0 0x0 10001 0 5723 19 3162 26 5723 19 0 0 0 0 3162 26 0 0 0 0
7 rmnet0 0x0 10001 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 rmnet0 0x0 10007 0 1895740 1570 44556 898 1895740 1570 0 0 0 0 44556 898 0 0 0 0
9 rmnet0 0x0 10007 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 rmnet0 0x0 10019 0 5319 12 2546 14 5319 12 0 0 0 0 2546 14 0 0 0 0
11 rmnet0 0x0 10019 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 rmnet0 0x0 10026 0 6866 19 2846 24 6866 19 0 0 0 0 2846 24 0 0 0 0
13 rmnet0 0x0 10026 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

第四个选项卡(1000,10001等)是UID号。找出哪个应用程序属于哪个UID号的最简单方法是:

adb shell dumpsys package > C:\apps.txt

转到“Package:”部分,然后在标有“userid =”的进程名称后面的第一行。

现在要阅读上面的图表,你想知道的两个主要数字是(rx_bytes)中的第6个数字和(tx_bytes)中的第8个数字。对于任何特定的应用程序,这两个数字应该是所有字节输入和输出的准确描绘。

享受。

答案 1 :(得分:1)

在Nefarii的评论中添加一个片段,找到特定应用程序的UID的最简单方法是:(例如,com.example.myapp):

adb shell dumpsys package com.example.myapp | grep userId=

相关问题