Hey for me am getting recv  and sent values as '-1' .  where is the
problem here??

On Jun 30, 7:02 pm, Guillaume Perrot <guillaume.p...@gmail.com> wrote:
> Hi everyone, I am trying to use TrafficStats and I have an issue when I try
> to get the traffic for each uid: if i sum all the traffic, I get values that
> can be completely different than the ones return by the getTotalXxBytes.
> In air plane mode, the total methods return 0 on a HTC Desire while the "by
> uid" methods still return the same numbers...
> Does anyone have a clue about the magic behind this API ?
>
> Example of my code running on a "Nexus S":
>
> code:
>
>     /* Get all UIDs, by the way is there an alternative way to tod this? */
>     Map<Integer, String> users = new TreeMap<Integer, String>();
>     PackageManager packageManager = getPackageManager();
>     for (ApplicationInfo info : packageManager.getInstalledApplications(0))
>     {
>       int uid = info.uid;
>       if (!users.containsKey(uid))
>         users.put(uid, packageManager.getNameForUid(uid).split(":")[0]);
>     }
>
>     long totalRx = 0;
>     long totalTx = 0;
>     for (Entry<Integer, String> entry : users.entrySet())
>     {
>       int uid = entry.getKey();
>       String uidName = entry.getValue();
>       long recv = TrafficStats.getUidRxBytes(uid);
>       long sent = TrafficStats.getUidTxBytes(uid);
>       if (sent > 0)
>       {
>         Log.v("tmp", "uid=" + uidName + " tx=" + sent);
>         totalTx += sent;
>       }
>       if (recv > 0)
>       {
>         Log.d("tmp", "uid=" + uidName + " rx=" + recv);
>         totalRx += recv;
>       }
>     }
>     Log.i("tmp", "totalRx sum=" + totalRx + " api=" +
> TrafficStats.getTotalRxBytes());
>     Log.i("tmp", "totalTx sum=" + totalTx + " api=" +
> TrafficStats.getTotalTxBytes());
>
> logcat:
>
> 06-30 15:58:24.855: VERBOSE/tmp(3109): uid=android.uid.system tx=5928
> 06-30 15:58:24.855: DEBUG/tmp(3109): uid=android.uid.system rx=7593
> 06-30 15:58:24.855: VERBOSE/tmp(3109): uid=android.uid.phone tx=528
> 06-30 15:58:24.855: DEBUG/tmp(3109): uid=android.uid.phone rx=288
> 06-30 15:58:24.855: VERBOSE/tmp(3109): uid=com.android.vending tx=35809
> 06-30 15:58:24.855: DEBUG/tmp(3109): uid=com.android.vending rx=715394
> 06-30 15:58:24.859: VERBOSE/tmp(3109): uid=com.google.uid.shared tx=62441
> 06-30 15:58:24.859: DEBUG/tmp(3109): uid=com.google.uid.shared rx=122406
> 06-30 15:58:24.859: VERBOSE/tmp(3109): uid=com.google.android.music tx=2527
> 06-30 15:58:24.859: DEBUG/tmp(3109): uid=com.google.android.music rx=7449
> 06-30 15:58:24.859: VERBOSE/tmp(3109): uid=android.media tx=3681
> 06-30 15:58:24.859: DEBUG/tmp(3109): uid=android.media rx=8781485
> 06-30 15:58:24.859: VERBOSE/tmp(3109): uid=com.google.android.apps.maps
> tx=1728
> 06-30 15:58:24.859: DEBUG/tmp(3109): uid=com.google.android.apps.maps
> rx=4818
> 06-30 15:58:24.859: VERBOSE/tmp(3109):
> uid=com.google.android.googlequicksearchbox tx=3238
> 06-30 15:58:24.859: DEBUG/tmp(3109):
> uid=com.google.android.googlequicksearchbox rx=7977
> 06-30 15:58:24.859: VERBOSE/tmp(3109): uid=com.google.android.gm tx=53463
> 06-30 15:58:24.859: DEBUG/tmp(3109): uid=com.google.android.gm rx=130145
> 06-30 15:58:24.859: VERBOSE/tmp(3109):
> uid=com.google.android.apps.genie.geniewidget tx=1901
> 06-30 15:58:24.859: DEBUG/tmp(3109):
> uid=com.google.android.apps.genie.geniewidget rx=38193
> 06-30 15:58:24.859: VERBOSE/tmp(3109): uid=com.google.android.gallery3d
> tx=1864
> 06-30 15:58:24.859: DEBUG/tmp(3109): uid=com.google.android.gallery3d
> rx=1192
> 06-30 15:58:24.863: VERBOSE/tmp(3109): uid=com.android.browser tx=446767
> 06-30 15:58:24.863: DEBUG/tmp(3109): uid=com.android.browser rx=203230268
> 06-30 15:58:24.863: VERBOSE/tmp(3109): uid=com.google.android.apps.reader
> tx=184116
> 06-30 15:58:24.863: DEBUG/tmp(3109): uid=com.google.android.apps.reader
> rx=1430630
> 06-30 15:58:24.863: VERBOSE/tmp(3109): uid=com.adao.android.afm tx=1407
> 06-30 15:58:24.863: DEBUG/tmp(3109): uid=com.adao.android.afm rx=13693
> 06-30 15:58:24.863: VERBOSE/tmp(3109): uid=com.apksoftware.compass tx=8820
> 06-30 15:58:24.863: DEBUG/tmp(3109): uid=com.apksoftware.compass rx=15371
> 06-30 15:58:24.863: VERBOSE/tmp(3109): uid=com.google.android.apps.docs
> tx=3967
> 06-30 15:58:24.863: DEBUG/tmp(3109): uid=com.google.android.apps.docs
> rx=23985
> 06-30 15:58:24.863: VERBOSE/tmp(3109): uid=*myapp* tx=27448
> 06-30 15:58:24.863: DEBUG/tmp(3109): uid=*myapp* rx=33575
> 06-30 15:58:24.863: INFO/tmp(3109): totalRx sum=214564462 api=2065472
> 06-30 15:58:24.867: INFO/tmp(3109): totalTx sum=845633 api=443360

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to