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

发布于 2024-12-17 20:26:54 字数 1065 浏览 1 评论 0原文

我想实现 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]/

我的问题:

  1. 执行文件夹rmnet0、rmnet1、rmnet2、rmnet3..。匹配每个 APN?如果有的话,比赛规则是什么?如果没有,如何获取每个 APN 流量统计信息?

  2. 在文件夹/proc/uid_stat/[uid]/,中只有两个文件:tcp_rcvtcp_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:

  1. 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?

  2. In folder /proc/uid_stat/[uid]/, there are only two files: tcp_rcv and tcp_snd, how can I get each applicaton on each APN traffic stats?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三寸金莲 2024-12-24 20:26:54

请切换到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文