小编fre*_*man的帖子

在Android中,如何衡量每个应用程序的每个接口的数据流量

我想实现一个扩展来android.net.TrafficStats测量每个应用程序的每个APN或每个APN的数据流量.方法原型看起来像:

getInterfaceTxPackets(String interface)
getInterfaceRxPackets(String interface)
getInterfaceTxBytes(String interface)
getInterfaceRxBytes(String interface)
getUidInterfaceTxPackets(int uid,String interface)
getUidInterfaceRxPackets(int uid,String interface)
getUidInterfaceTxBytes(int uid,String interface)
getUidInterfaceRxBytes(int uid,String interface)
Run Code Online (Sandbox Code Playgroud)

我读了android.net.TrafficStats.java,它调用了本机方法android_net_TrafficStats.cpp,本机方法从一些文件中读取流量统计信息:

  • 总流量统计文件在文件夹中/sys/class/net/,在此文件夹中有一些子文件夹,如:eth0,ip6tnl0,rmnet0,rmnet1,rmnet2,rmnet3.,详细的统计文件保存在这些文件夹中.

  • 每个应用程序流量统计文件都在 /proc/uid_stat/[uid]/

我的问题:

  1. 做文件夹rmnet0, rmnet1, rmnet2, rmnet3...匹配每个APN?如果这样做,匹配规则是什么?如果没有,我怎样才能得到每个APN流量统计数据?

  2. 在文件夹/proc/uid_stat/[uid]/,中只有两个文件:tcp_rcv并且tcp_snd,如何在每个APN流量统计数据上获得每个应用程序?

android traffic-measurement

13
推荐指数
1
解决办法
3165
查看次数

为什么我无法通过Android ICS中的FileReader正确读取/ proc/net/xt_qtaguid/stats

我想在Android ICS中读取/ proc/net/xt_qtaguid/stats,它记录所有接口和应用程序流量统计信息.以下是代码段:

String line = null;
BufferReader reader = new BufferedReader(new FileReader(new File("/proc/net/xt_qtaguid/stats")));

line = reader.readLine();/*Here I can read the 1st line correctly, it return "idx  iface acct_tag_hex..."*/
splitLine(line, keys);
line = reader.readLine();//!!!!!Read next line, it returns null!!!!!!
Run Code Online (Sandbox Code Playgroud)

如果我捕获此文件,它将显示:

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 6266 105 8882 121 1428 30 4838 75 0 0 208 4 2552 44 …

android filereader bufferedreader proc

2
推荐指数
1
解决办法
3364
查看次数