0

I want to measure the data transferred and received for my HTTP request over the mobile network. I found the TrafficStats API in Android 2.2, but the numbers I get from this seem to be too low. I am measuring on a real device (HTC Desire), over 3G network. Immediately before the request a compute the tx/rx data since boot time, then do a GET request, then calculate the rx/tx numbers again:

long bytesStart = TrafficStats.getTotalTxBytes() + TrafficStats.getTotalRxBytes();
// execute request (Apache HTTP client)
client.execute(get);
long totalBytesNow = TrafficStats.getTotalTxBytes() + TrafficStats.getTotalRxBytes();
long bytesDiff = totalBytesNow - bytesStart;

For bytesDiff I get numbers around 1.5KB, where it should have been 3.5KB. The totalBytes number is around 5MB, which seems to be a reasonable amount of data for 10 hours that the device is running.

I read here on stackoverflow that the numbers come from a file, can it be that the data is not flushed to the file immediately? Or why are my numbers always too low (I checked the data size on the server and it is really larger)? Is it a problem of my HTC Desire device (Android 2.2 by HTC), does the TrafficStats API work for anyone?

Thanks, Martin

Community
  • 1
  • 1
hoffimar
  • 543
  • 5
  • 16

2 Answers2

0

Could it be that the HTTP stack is compressing your data?

Also, the files on /sys are not actual files in the common sense, they are a file interface to kernel data (you know, the 'everything is a file' philosophy of Unix/Linux)

svdree
  • 13,298
  • 4
  • 28
  • 21
  • Yes the data is transmitted gzipped, but I checked the numbers for different file sizes on the device and using HTTPwatch (both compressed), and the numbers from TrafficStats are much too low. Right, these are not really files, so the flushing theory might be dumped ;-) – hoffimar Mar 23 '11 at 18:41
0

OK, I found out the problem in my coding. After "client.execute(get);" I only have the headers etc. transferred, not the content. After evaluating the content InputStream the numbers are correct...

hoffimar
  • 543
  • 5
  • 16