Tracking an application's network statistics (netstats) using ADB

偶尔善良 提交于 2019-11-29 22:29:04
Nefariis

Well I figured out where "spare parts" and "Net Usage" get their information from.

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

The Problem I see with how they are doing it though is that this only accounts for TCP usage and does not account for and UDP usage.

The only way to figure out the total tx_bytes and rx_bytes is through this command.

adb shell cat /proc/net/xt_qtaguid/stats

or if you would like to convert it to a text file and view it easier.

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

This gives you something that looks like this:

------ 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

The fourth tab over (1000, 10001, etc) is the UID number. The easiest way to find out what application belongs to what UID number is:

adb shell dumpsys package > C:\apps.txt

Go down to the "Package:" section, and then its the first line down after the process name labeled "userid=".

Now to read the above chart, the main two numbers that you want to know are the 6th number in (the rx_bytes) and the 8th number in (the tx_bytes). Those two numbers should be an accurate portrayal of all the bytes in and out, for any particular application.

Enjoy.

Adding a snippet to Nefarii's comment, the easiest way to find out the UID for a particular application, e.g., com.example.myapp, is:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!