Tracking an application's network statistics (netstats) using ADB - android

I have a feeling this is possible, I'm just not quite sure where the information is held.
I want to get the up/down statistics for specific applications, but I want to do it using ADB and not wireshark or netty.
I know I can see the vmData using
adb shell
cd proc
cd pid#
cat status
and I know I can see the netstats using:
ADB Shell dumpsys netstats details full
which gives me these results:
Dev stats:
Pending bytes: 1410076
Complete history:
ident=[[type=MOBILE, subType=COMBINED, subscriberId=310260...]] uid=-1 set=ALL tag=0x0
NetworkStatsHistory: bucketDuration=3600000
bucketStart=1349211600000 activeTime=3600000 rxBytes=19656154 rxPackets=16897 txBytes=615620 txPackets=8084 operations=0
bucketStart=1349215200000 activeTime=3600000 rxBytes=28854708 rxPackets=23363 txBytes=1037409 txPackets=12206 operations=0
bucketStart=1349218800000 activeTime=3600000 rxBytes=1839274 rxPackets=1565 txBytes=89791 txPackets=914 operations=0
bucketStart=1349222400000 activeTime=3600000 rxBytes=17421 rxPackets=88 txBytes=18376 txPackets=95 operations=0
bucketStart=1349226000000 activeTime=3600000 rxBytes=506966 rxPackets=788 txBytes=96491 txPackets=859 operations=0
Unfortunately this looks like a combined netstat that does not differentiate between applications.
So my question, is there a way to see network traffic by unique PID#'s or application names, by simply using the command prompt?
EDIT
Alright I made some good strides
With this code
adb shell cat proc/1638(thePID)/net/dev > C:\netstats.txt
I can get this information:
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 3564 28 0 0 0 0 0 0 3564 28 0 0 0 0 0 0
dummy0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
rmnet0: 117062940 191775 0 0 0 0 0 0 19344640 177574 0 0 0 0 0 0
rmnet1: 2925492 5450 0 0 0 0 0 0 1448544 5664 0 0 0 0 0 0
rmnet2: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
rmnet3: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
rmnet4: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
rmnet5: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
rmnet6: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
rmnet7: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
vip0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Unfortunately after double checking these numbers with programs like "Network Usage" from the android market place, I discovered that these numbers are the total up and down across the entire device.
So it still leaves me with, how/where the heck are programs like "Network Usage" and "Spare Parts" getting their information from?

Well I figured out where "spare parts" and "Net Usage" get their information from.
adb shell cat proc/uid_stat/(uid#)/tcp_rcv
adb shell cat proc/uid_stat/(uid#)/tcp_snd
The Problem I see with how they are doing it though is that this only accounts for TCP usage and does not account for and UDP usage.
The only way to figure out the total tx_bytes and rx_bytes is through this command.
adb shell cat /proc/net/xt_qtaguid/stats
or if you would like to convert it to a text file and view it easier.
adb shell cat /proc/net/xt_qtaguid/stats > C:\Netstats.txt
This gives you something that looks like this:
------ QTAGUID STATS INFO (su root cat /proc/net/xt_qtaguid/stats) ------
idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets
2 rmnet0 0x0 0 0 18393 326 8506 166 10889 267 7504 59 0 0 4180 101 3397 54 929 11
3 rmnet0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 rmnet0 0x0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
5 rmnet0 0x0 1000 1 7181 14 1834 19 7023 12 158 2 0 0 1616 16 218 3 0 0
6 rmnet0 0x0 10001 0 5723 19 3162 26 5723 19 0 0 0 0 3162 26 0 0 0 0
7 rmnet0 0x0 10001 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8 rmnet0 0x0 10007 0 1895740 1570 44556 898 1895740 1570 0 0 0 0 44556 898 0 0 0 0
9 rmnet0 0x0 10007 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 rmnet0 0x0 10019 0 5319 12 2546 14 5319 12 0 0 0 0 2546 14 0 0 0 0
11 rmnet0 0x0 10019 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 rmnet0 0x0 10026 0 6866 19 2846 24 6866 19 0 0 0 0 2846 24 0 0 0 0
13 rmnet0 0x0 10026 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The fourth tab over (1000, 10001, etc) is the UID number. The easiest way to find out what application belongs to what UID number is:
adb shell dumpsys package > C:\apps.txt
Go down to the "Package:" section, and then its the first line down after the process name labeled "userid=".
Now to read the above chart, the main two numbers that you want to know are the 6th number in (the rx_bytes) and the 8th number in (the tx_bytes). Those two numbers should be an accurate portrayal of all the bytes in and out, for any particular application.
Enjoy.

Adding a snippet to Nefarii's comment, the easiest way to find out the UID for a particular application, e.g., com.example.myapp, is:
adb shell dumpsys package com.example.myapp | grep userId=

Related

Android app consuming a lot of native heap space

I am trying to reduce the memory usage of my app.I started by fixing memory leaks in my code.This reduced the Dalvik heap space considerably but no difference in the native heap space allocated.
Is there a way I can reduce my native heap space consumption. If so, how should I go about doing it?
Heres what my app's heap dump looks like ""
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 27240 27208 0 0 57344 24872 32471
Dalvik Heap 27138 26804 0 0 49430 41737 7693
Dalvik Other 624 624 0 0
Stack 924 924 0 0
Gfx dev 8738 5788 0 0
Other dev 16 0 16 0
.so mmap 833 332 124 0
.apk mmap 634 0 176 0
.ttf mmap 32 0 0 0
.dex mmap 12484 0 12480 0
.oat mmap 1146 0 124 0
.art mmap 1395 1212 4 0
Other mmap 44 4 0 0
Unknown 160 160 0 0
TOTAL 81408 63056 12924 0 106774 66609 40164
Objects
Views: 919 ViewRootImpl: 1
AppContexts: 3 Activities: 1
Assets: 214 AssetManagers: 214
Local Binders: 85 Proxy Binders: 22
Parcel memory: 24 Parcel count: 96
Death Recipients: 0 OpenSSL Sockets: 3
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0

Color selector for vector image doesn't work

I have a vector image (svg converted to xml):
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:better="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
tools:ignore="NewApi"
android:viewportWidth="24"
better:viewportWidth="24"
android:viewportHeight="24"
better:viewportHeight="24"
android:width="24dp"
android:height="24dp">
<path
android:pathData="M10.09 15.59l1.41 1.41 5 -5 -5 -5 -1.41 1.41 2.58 2.59 -9.67 0 0 2 9.67 0 -2.58 2.59zM19 3L5 3C3.89 3 3 3.9 3 5l0 4 2 0 0 -4 14 0 0 14 -14 0 0 -4 -2 0 0 4c0 1.1 0.89 2 2 2l14 0c1.1 0 2 -0.9 2 -2L21 5C21 3.9 20.1 3 19 3Z"
better:pathData="M10.09 15.59l1.41 1.41 5 -5 -5 -5 -1.41 1.41 2.58 2.59 -9.67 0 0 2 9.67 0 -2.58 2.59zM19 3L5 3C3.89 3 3 3.9 3 5l0 4 2 0 0 -4 14 0 0 14 -14 0 0 -4 -2 0 0 4c0 1.1 0.89 2 2 2l14 0c1.1 0 2 -0.9 2 -2L21 5C21 3.9 20.1 3 19 3Z"
android:fillColor="#color/menu_color_selector"
better:fillColor="#color/menu_color_selector" />
</vector>
But the color selector doesn't work. Is it possible to achieve what I am trying to do?
Try to use StateListDrawable with different VectorDrawable for each required state.

reduce the memory when starting a Service(EGL mtrack too big)

First I declared the Service at manifest:
<service android:name=".TestService"
android:process=":test">
</service>
Then, I create a Service that does nothing:
public class TestService extends Service{
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
I started a Service with
mContext.startService(new Intent(mContext, TestService.class));
in my Application,then I found the memory usage in 'Runing App' (get there by settings-> apps-> running) is 24M.And here is the meminfo I got:
adb shell dumpsys meminfo com.mypush:test
Applications Memory Usage (kB):
Uptime: 79955214 Realtime: 87129943
** MEMINFO in pid 2452 [com.mypush:test] **
Pss Private Private Swapped Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 2508 2468 0 0 12288 4916 7371
Dalvik Heap 1354 956 0 0 22320 16969 5351
Dalvik Other 400 400 0 0
Stack 136 136 0 0
Gfx dev 628 628 0 0
Other dev 4 0 4 0
.so mmap 860 336 4 0
.apk mmap 29 0 0 0
.ttf mmap 9 0 0 0
.dex mmap 156 0 4 0
.oat mmap 191 0 0 0
.art mmap 564 268 0 0
Other mmap 36 4 0 0
EGL mtrack 13888 13888 0 0
GL mtrack 3272 3272 0 0
Unknown 152 152 0 0
TOTAL 24187 22508 12 0 34608 21885 12722
Objects
Views: 0 ViewRootImpl: 0
AppContexts: 3 Activities: 0
Assets: 3 AssetManagers: 3
Local Binders: 8 Proxy Binders: 13
Parcel memory: 3 Parcel count: 12
Death Recipients: 2 OpenSSL Sockets: 0
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
I am running on Android 5.0/Nexus5, and found some apps used a Service use less memory than mine.So I want to know why?
Update
I have found that the EGL mtrack dumped is about 13M, it is not normal for a app that only has a empty Service.

Generate Double Tap Event Android

How do i generate a double tap event on Android.
This is the implementation that i have done.
$event="/dev/event/event1"
$x=$1
$y=$2
sendevent $event 3 57 2421
sendevent $event 3 58 232
sendevent $event 3 53 $x
sendevent $event 3 54 $y
sendevent $event 0 0 0
sendevent $event 3 57 4294967295
sendevent $event 0 0 0
sendevent $event 3 57 2421
sendevent $event 3 58 232
sendevent $event 3 53 $x
sendevent $event 3 54 $y
sendevent $event 0 0 0
sendevent $event 3 57 4294967295
sendevent $event 0 0 0
With this implementation the double tap is slow that it appears as two separate single taps to the android system.
P.S: I tried these on Samsung Galaxy Nexus phone.
Why do you need to implement your custom double tab event? Maybe you can use SimpleOnGestureListener, this listener has method onDoubleTap(MotionEvent e)

Missing texture in .OBJ model on min3d framwork android

I am following this tuttorial:
http://www.mat-d.com/site/tutorial-load-a-3d-obj-model-with-min3d-for-android/
this is my mtl file:
newmtl Texture0
Ns 20
d 1
illum 2
map_Kd face_eyel_hi.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
newmtl Texture1
Ns 20
d 1
illum 2
map_Kd face_eyer_hi.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
newmtl Texture2
Ns 20
d 1
illum 2
map_Kd face_skin_hi.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
newmtl Texture3
Ns 20
d 1
illum 2
map_Kd face_sock.jpg
Kd 0.7 0.7 0.7
Ks 0 0 0
Ka 0 0 0
the obj file is in the last comment in the url i gave above
The texture is always missing can u tell me whats wrong ?
if u want to see the code check the url above.
i found whats wrong ,
the problem is in the tabulation of the mtl file,
just make sure that their is no indentation in the mtl file, and the texture will load perfectly
thank you !

Categories

Resources