Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding usage of resources (CPU and memory) by threads of a process in Android

I have a multi-threaded application(C++,C and pthread library) and I will like to know how much resources(CPU and memory) each thread uses. Is there a way to find out these details on Android?

I have tried

$ adb shell ps -p -t 

But, this gives information in the below format,

USER     PID   PPID  VSIZE  RSS   PRIO  NICE  RTPRI SCHED   WCHAN    PC         NAME

root      1     0     476    312   20    0     0     0     c037c0e0 000087bc S /init

root      2     0     0      0     20    0     0     0     c031f114 00000000 S kthreadd

root      3     2     0      0     20    0     0     0     c030e5d0 00000000 S ksoftirqd/0

root      4     2     0      0     -100  0     99    1     c033fc50 00000000 S watchdog/0

root      5     2     0      0     20    0     0     0     c031b4b4 00000000 S events/0

root      6     2     0      0     20    0     0     0     c031b4b4 00000000 S khelper

Any way to know which threads are running along with their parent's id will be really helpful.

using

$ adb logcat -v threadtime 

prints info about the running process (PID) and the thread (TID). But, its not enough for my purpose. I want to know how much resources is a particular thread consuming. Any pointers.

like image 489
mkamthan Avatar asked Nov 13 '22 10:11

mkamthan


1 Answers

ps command in android seems to be very limited compared to linux.

You could try:

ps -t -c APP_NAME

This will show you threads(-t) and the CPU assigned to the thread (-c)

Example:

ps -t -c -p com.whatsapp

-p is thread priority(linux nice value)

like image 71
ismaia Avatar answered Nov 16 '22 03:11

ismaia