[Android Traffic] Android traffic calculation method

Source: Internet
Author: User

About Android Traffic

    • Traffic statistics File: path/proc/net/dev

Open the file, where Lo is the local traffic, Rmnet0 is 3G/2G traffic, Wlan0 is wireless traffic.

    • You can find a directory of related categories, such as Rmnet0, under/sys/class/net/. Statistics downstream rx_bytes and Tx_bytes records send and receive traffic in their subdirectories.
    • In/PROC/UID_STAT/{UID}/TCP_RCV record the UID app download traffic bytes,/proc/uid_stat/{uid}/tcp_snd have the Uid app upload traffic bytes

Trafficstats Learning

    • Trafficstats Google Develop documentation
    • Trafficstats source File View
    • Important API:

Static long  getmobilerxbytes ()   //Gets the total number of bytes received through the mobile connection and does not contain wifi  
Static Long   getmobilerxpackets ()   //Gets the total number of packets received by the mobile connection   
Static long   Getmobiletxbytes ()   //mobile The total number of bytes sent   
Static long  getmobiletxpackets ()    //mobile the total number of packets sent   
Static long  gettotalrxbytes ()   //Gets the total number of accepted bytes, Includes mobile and WiFi   ,
Static long  gettotalrxpackets ()   //total number of accepted packets, including mobile and WiFi, etc.   
Static long  gettotaltxbytes ()   //The total number of bytes sent, including mobile and WiFi   
Static long  gettotaltxpackets ()   //The total number of packets sent, including mobile and WiFi    
Static long   getuidrxbytes (int uid)   //Gets the number of accepted bytes for a network UID   
Static long  getuidtxbytes ( int uid)//Gets the number of bytes sent for a network UID [/mw_shl_code]
Note: The Trafficstats class appears after the Android 2.2 API level (8).

When doing GXB, the method of checking traffic is based on the UID query system file:

/proc/uid_stat/uid/tcp_send Upload Traffic
/PROC/UID_STAT/UID/TCP_RCV Download Traffic

When doing AVT, it is the method of calling the system through the UID to query the traffic:

proc/uid_stat/10086
Long tx = Trafficstats.getuidtxbytes (UID);//upload traffic sent by byte
Long rx = trafficstats.getuidrxbytes (UID);//Download Traffic byte

Trafficstats.getmobiletxbytes ();//Get the total traffic of mobile 3g/2g network uploads
Trafficstats.getmobilerxbytes ();//Mobile 2g/3g Total Download traffic

Trafficstats.gettotaltxbytes ();//Mobile phone all network interface including WIFI,3G, 2g upload Total traffic
Trafficstats.gettotalrxbytes ();//Mobile all network interface including WIFI,3G, 2g download Total traffic

The essence is the same.

[Android Traffic] Android traffic calculation method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.