Wednesday, October 20, 2010

Where Does Android Gets Its Traffic Stats?

Quite simple.  Android get these stats from Linux sysfs and proc file systems.  They can be found at the following locations on a Android powered device:
Android TrafficStats Linux File Location
Android Traffic Stats Table
getMobileTxPackets() /sys/class/net/rmnet0/statistics/tx_packets
getMobileRxPackets() /sys/class/net/rmnet0/statistics/rx_packets
getMobileTxBytes() /sys/class/net/rmnet0/statistics/tx_bytes
getMobileRxBytes() /sys/class/net/rmnet0/statistics/rx_bytes
getTotalTxPackets() Add up tx_packets for all interfaces under /sys/class/net
getTotalRxPackets() Add up rx_packets for all interfaces under /sys/class/net
getTotalTxBytes() Add up tx_bytes for all interfaces under /sys/class/net
getTotalRxBytes() Add up rx_bytes for all interfaces under /sys/class/net
getUidRxBytes() /proc/uid_stat/[uid]/tcp_rcv
getUidTxBytes() /proc/uid_stat/[uid]/tcp_snd

1 comment:

  1. Is there any way to get the statistics per uid seperately for each and every application in android?