在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)
我读取了android.net.TrafficStats.java
,它调用android_net_TrafficStats.cpp
中的本机方法,本机方法从一些文件:
总流量统计文件位于文件夹
/sys/class/net/
中,该文件夹中有一些子文件夹,例如:eth0、ip6tnl0、 rmnet0、rmnet1、rmnet2、rmnet3.,详细的统计文件都保存在这些文件夹中。每个应用程序流量统计文件位于
/proc/uid_stat/[uid]/
我的问题:
执行文件夹
rmnet0、rmnet1、rmnet2、rmnet3..
。匹配每个 APN?如果有的话,比赛规则是什么?如果没有,如何获取每个 APN 流量统计信息?在文件夹
/proc/uid_stat/[uid]/,
中只有两个文件:tcp_rcv
和tcp_snd
,我怎样才能得到每个APN流量统计数据上的每个应用程序?
I want to implement an extention to android.net.TrafficStats
to measure the data traffic per APN or per APN per application. the methods prototype looks like:
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)
I read the android.net.TrafficStats.java
, it call the native methods in android_net_TrafficStats.cpp
, and the native methods read the traffic statistics from some files:
the total traffic statistic files are in folder
/sys/class/net/
, in this folder there are some sub folders like: eth0, ip6tnl0, rmnet0, rmnet1, rmnet2, rmnet3., the detailed statistic files are saved in these folders.the per application traffic statistic files are in
/proc/uid_stat/[uid]/
My questions:
Do the folder
rmnet0, rmnet1, rmnet2, rmnet3..
. match each APN? If do, what's the match rule? if don't, how can I get each APN traffic statistic?In folder
/proc/uid_stat/[uid]/,
there are only two files:tcp_rcv
andtcp_snd
, how can I get each applicaton on each APN traffic stats?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请切换到 Android 4.0,其中数据使用监控已得到加强。这些 API 现在位于一个更加复杂的服务之上,该服务收集每个接口每个 uid 的流量信息。
请注意,每个接口名称都没有关联的含义,因此您不能假设在一台设备上找到的特定名称在另一台设备上具有相同的含义。
Please switch over to Android 4.0, where for the data usage monitoring this has been beefed up. These APIs now sit on top of a much more complicated service that collects per-interface per-uid traffic information.
Note that there is no meaning associated with each of the interface names, so you can't just assume that a particular name you find on one device means the same thing on another.