Android TrafficStats之setThreadStatsTag()
来源:互联网 发布:哈尔滨工业大学 知乎 编辑:程序博客网 时间:2024/06/05 01:44
一. stats文件
抓取/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 wlan0 0x0 0 0 73557 400 1515 22 0 0 72801 378 756 22 364 7 213 3 938 12
3 wlan0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 wlan0 0x0 1000 0 2551 18 2361 18 663 11 1888 7 0 0 957 13 1404 5 0 0
5 wlan0 0x0 1000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6 wlan0 0x0 10046 0 0 0 60 1 0 0 0 0 0 0 60 1 0 0 0 0
7 wlan0 0x0 10046 1 0 0 1140 19 0 0 0 0 0 0 1140 19 0 0 0 0
8 p2p0 0x0 0 0 0 0 216 3 0 0 0 0 0 0 0 0 0 0 216 3
9 p2p0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 lo 0x0 0 0 965652 963 18720 330 961572 915 1704 24 2376 24 14640 282 1704 24 2376 24
11 lo 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 lo 0x0 10046 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13 lo 0x0 10046 1 2324364 4369 3271296 5002 2324364 4369 0 0 0 0 3271296 5002 0 0 0 0
14 lo 0x4200000000 10046 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
15 lo 0x4200000000 10046 1 120016 2308 3164120 2942 120016 2308 0 0 0 0 3164120 2942 0 0 0 0
16 lo 0x4300000000 10046 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17 lo 0x4300000000 10046 1 2201600 2048 106392 2046 2201600 2048 0 0 0 0 106392 2046 0 0 0 0
iface指端口,acct_tag_hex是指TrafficStats为统计特别socket而下设的tag。上面数据的最后四项中的0x42,0x43就是我们设下去的tag。
uid_tag_int是指app的UID,例如最后的10046,就表示这应用的uid。
cnt_set指前后台。
二. 对socket设置tag
为了统计线程中某个socket的数据流量,可以通过下面的方法进行:
TrafficStats.setThreadStatsTag(int tag);
TrafficStats.tagSocket(sockt outputSocket);
// Transfer data using socket
TrafficStats.untagSocket(socket outputSocket);
setThreadStatsTag()后面要使用tagSocket(),否则是无效的。
三. 调用流程
SetThreadStatsTag()和tagSocket()的调用流程如下:
需要注意的是setThreadStatsTag()最终只是设置了tag到NetworkManagementSocketTagger里,需要调用tagSocket()把socket设置下去,最终触发tag,把socket和tag设置到kernel里。
最终调用到kernel xt_qtaguid.c的ctrl_cmd_tag()里,这里的命令是“t”。
同时有命令“u”,untag。“s”,counter_set。“d”,delete。
四. 总结
在xt_qtaguid里还有对/proc/net/xt_qtaguid/iface_stat_all,iface_stat_fmt文件的操作。iface_stat_all仅简单包含所有的数据流量统计。iface_stat_fmt是按照一定格式整理的。
阅读全文
0 0
- Android TrafficStats之setThreadStatsTag()
- Android之TrafficStats实现流量实时监测
- Android trafficstats的用法
- Android TrafficStats流量统计
- android TrafficStats 流量检测类
- Android TrafficStats类的使用
- android流量监控 TrafficStats 开发
- Android 流量统计TrafficStats总结
- Android流量监控类 trafficstats
- android TrafficStats 下载,上行速率
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- Android流量统计TrafficStats类的使用
- 欢迎使用CSDN-markdown编辑器
- 安装GD扩展库
- 浅谈linux中的根文件系统(rootfs的原理和介绍)
- 图像边缘检测经典算子及MATLAB实现
- flume学习(一):log4j直接输出日志到flume
- Android TrafficStats之setThreadStatsTag()
- Linux 安装mysql
- QML中ListView的深度订制,并利用其实现自定义ComboBox和TreeView
- mysql高速批量导入数据
- VS2013创建动态库(DLL)
- 集合数组相互转换!
- js 实时监听input中值的变化,值改变时自动计算填充到另一个input中
- spring cloud-学习之路(二):搭建一个config repository 和config server
- pycharm新建文件时头部的模板