Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TrafficStats.getTotalRxBytes() is less than expected
    text
    copied!<p>I'm trying to get а real traffic stats data. But, TrafficStats.getTotalRxBytes() is less than a sum of TrafficStats.getUidRxBytes() for each installed application. I've found it out by running each 30 seconds this code (being on a Wi-Fi network):</p> <pre><code>long total = TrafficStats.getTotalRxBytes(); long mobileTotal = TrafficStats.getMobileRxBytes(); long wifiTotal = (total - mobileTotal); Log.v("SSS", "total=" + total + " mob=" + mobileTotal + " wifi=" + wifiTotal); ArrayList&lt;Integer&gt; uids = new ArrayList&lt;Integer&gt;(); int cnt = 0; for (ApplicationInfo appInfo : packageManager.getInstalledApplications(0)) { long bytes = TrafficStats.getUidRxBytes(appInfo.uid); if (!uids.contains(appInfo.uid)) { // few applications can refer to same uid - sum each uid stats only once uids.add(appInfo.uid); if (bytes &gt; 0) cnt += bytes; } } Log.v("SSS", "sum traffic stats = " + cnt); </code></pre> <p>And this is in logs:</p> <pre><code>12-12 19:43:18.798: V/SSS(4772): total=4245863 mob=0 wifi=4245863 12-12 19:43:19.569: V/SSS(4772): sum traffic stats = 9313461 12-12 19:43:49.628: V/SSS(4772): total=4245915 mob=0 wifi=4245915 12-12 19:43:50.459: V/SSS(4772): sum traffic stats = 9314216 12-12 19:44:20.518: V/SSS(4772): total=4246524 mob=0 wifi=4246524 12-12 19:44:21.439: V/SSS(4772): sum traffic stats = 9320030 </code></pre> <p>The difference between totals is less than difference between sums : </p> <pre><code>9320030 - 9314216 = 5814 bytes // sums of traffic stats by uid 4246524 - 4245915 = 609 bytes // total traffic stats </code></pre> <p>1) Why is that? 2) How do i get a correct value for total traffic stats - should i just sum traffic stats by uids?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload