獲取TCP + UDP 等其他協(xié)議流量統(tǒng)計數(shù)據(jù)
方法一:/proc/<pid>/net/dev
1.獲取待測試App pid
adb shell ps | grep packagename
2.獲取指定App 流量消耗數(shù)據(jù)
adb shell cat /proc/#pid#/net/dev
3.獲取總流量消耗數(shù)據(jù)
adb shell cat /proc/net/dev
參數(shù)含義
- Recevice:表示收包
- Transmit:表示發(fā)包
- bytes: 表示收發(fā)的字節(jié)數(shù)
- packets: 表示收發(fā)正確的包量
- errs: 表示收發(fā)錯誤的包量
- drop: 表示收發(fā)丟棄的包量
統(tǒng)計數(shù)據(jù)
1.如果想要將數(shù)據(jù)清0,開關(guān)一下飛行模式,再執(zhí)行命令即可
2.(將上下行的數(shù)據(jù)相加-測試前的數(shù)據(jù))/1024/1024就得到所消耗多少M的流量
方法二:/proc/net/xt_qtaguid/stats | grep <uid>
1.獲取待測試App pid
adb shell ps | grep packagename
2.獲取待測試App uid
adb shell cat /proc/4362/status | grep -i uid
3.獲取待測試App 流量數(shù)據(jù)
adb shell cat /proc/net/xt_qtaguid/stats | grep uid
- 第6列是接收的流量數(shù)值它抱,單位:bytes
- 第8列是發(fā)送的流量數(shù)值秕豫,單位:bytes
- 如果結(jié)果出現(xiàn)多行數(shù)據(jù),相加的總數(shù)即為結(jié)果
對應(yīng)的表頭的列名稱和意思如下:
名稱 | 含義 |
---|---|
idx | 序號 |
iface | 代表流量類型(rmnet表示2G/3G, wlan表示W(wǎng)ifi流量,lo表示本地流量) |
acct_tag_hex | 線程標(biāo)記(用于區(qū)分單個應(yīng)用內(nèi)不同模塊/線程的流量) |
uid_tag_int | 應(yīng)用uid,據(jù)此判斷是否是某應(yīng)用統(tǒng)計的流量數(shù)據(jù) |
cnt_set | 應(yīng)用前后標(biāo)志位 1:前臺观蓄, 0:后臺 |
rx_btyes | receive bytes 接受到的字節(jié)數(shù) |
rx_packets | 接收到的任務(wù)包數(shù) |
tx_bytes | transmit bytes 發(fā)送的總字節(jié)數(shù) |
tx_packets | 發(fā)送的總包數(shù) |
rx_tcp_types | 接收到的tcp字節(jié)數(shù) |
rx_tcp_packets | 接收到的tcp包數(shù) |
rx_udp_bytes | 接收到的udp字節(jié)數(shù) |
rx_udp_packets | 接收到的udp包數(shù) |
rx_other_bytes | 接收到的其他類型字節(jié)數(shù) |
rx_other_packets | 接收到的其他類型包數(shù) |
tx_tcp_bytes | 發(fā)送的tcp字節(jié)數(shù) |
tx_tcp_packets | 發(fā)送的tcp包數(shù) |
tx_udp_bytes | 發(fā)送的udp字節(jié)數(shù) |
tx_udp_packets | 發(fā)送的udp包數(shù) |
tx_other_bytes | 發(fā)送的其他類型字節(jié)數(shù) |
tx_other_packets | 發(fā)送的其他類型包數(shù) |
獲取TCP協(xié)議流量統(tǒng)計數(shù)據(jù)
未完待續(xù)