Skip to content Skip to sidebar Skip to footer

How To Get Higher Precision Of "cpu%" Than That From Top Command?

When I use TOP command, I could get the following info: shell@android:/ $ top -n 1 User 31%, System 10%, IOW 0%, IRQ 0% User 3

Solution 1:

You didn't mention it in your post, but in the comment you said that you really need CPU utilization per thread, not per process.

If you can't find a tool that's accurate enough, you can look directly in /proc/[pid]/task/[ThreadName] as described in the man page for /proc. This gives total CPU time consumed in "clock ticks" since execution began. Getting better resolution than this is probably difficult or impossible.

Edit

From the OP's comment, a command that lists the relevant information is:

adb shell cat /proc/${pid}/task/*/stat | awk -F\ '{print $1, $14}'

This just cats the correct /proc files to the debugging host, which runs a tiny awk program to print the columns for pid and user time. You could also easily use cut -d " " -f1,14 or something similar in perl to get the columns if awk isn't available.

Solution 2:

Try this:

ps -eo pcpu,pid,user,args | sort -r -k1 | less 

%CPU   PID USER     COMMAND
 9.02721user   bash
 1.4956 root     ...
 0.52212user   ...

EDIT:

You can use adb shell and busybox (http://www.busybox.net/downloads/BusyBox.html)

adb shell busybox top

c:\adbpushbusybox/system/binc:\adbshell# busybox top CPU:2.3%usr3.1%sys3.9%nic90.5%idle0.0%io0.0%irq0.0%sirqLoad average:1.061.6610.631/5898048←[7mPIDPPIDUSERSTATVSZ%MEMCPU%CPUCOMMAND←[0m316192180 10112S217m67.003.8com.mgeek.android.DolphinBrowser.B2232  2180 1000     S551m169.602.6system_server8038  8037 0R2068  0.600.8busyboxtop2178     10S110923.300.6/system/bin/drexe6812  2180 10104S199m61.200.5android.tether2291  2180 1001     S324m99.800.3com.android.phone2308  2180 10006S325m100.000.1com.sec.android.app.dialertab2177     11001     S9624  2.800.1/system/bin/rild520SW<00.000.1 [events/0]
300872180 10022S358m110.400.0com.samsung.vvm2304  2180 10006S311m96.000.0com.sec.android.app.twlauncher161102180 10006S296m91.300.0android.process.acore2445  2180 10006S272m83.800.0com.sec.android.provider.logsprovi8064  2180 10002S238m73.400.0com.google.process.gapps315372180 10037S227m69.900.0com.google.android.gm2288  2180 10048S221m68.100.0com.swype.android.inputmethod2285  2180 10013S215m66.300.0com.tat.livewallpaper.aurora306642180 10011S213m65.800.0com.android.email311912180 10099S209m64.400.0com.sirma.mobile.bible.android2377  2180 10087S207m63.900.0android.tts

(Taken from here)

Solution 3:

Got this information from another thread:

3) Getting CPU info

~$ adb shell dumpsys cpuinfo

Output:

Load: 0.08 / 0.4 / 0.64 CPU usage from 42816ms to 34683ms ago: system_server: 1% = 1% user + 0% kernel / faults: 16 minor kdebuglog.sh: 0% = 0% user + 0% kernel / faults: 160 minor tiwlan_wq: 0% = 0% user + 0% kernel usb_mass_storag: 0% = 0% user + 0% kernel pvr_workqueue: 0% = 0% user + 0% kernel +sleep: 0% = 0% user + 0% kernel +sleep: 0% = 0% user + 0% kernel TOTAL: 6% = 1% user + 3% kernel + 0% irq

EDIT:

You can also try this command: echo $(adb shell ps | grep com.android.phone | awk '{ system("adb shell cat /proc/" $2 "/stat");}' | awk '{print $14+$15;}')

Also:

using top : This will show you the cpu stats top -b -n 1 |grep ^Cpu

using ps: This will show you the % cpu usage for each process. ps -eo pcpu,pid,user,args | sort -r -k1 | less

EDIT2:

In realtion to your comments and the bounty description (How can I guess which thread eats the battery?) I found an interesting page:

http://ziyang.eecs.umich.edu/projects/powertutor/

As stated there:

You can use PowerTutor to monitor the power consumption of any application.

Try this for an instance and see if it meets your requirements.

FINAL EDIT:

Check out the Systrace documentation on the developer.android.com site:

http://developer.android.com/tools/debugging/systrace.htmlhttp://developer.android.com/tools/help/systrace.html

I'm sorry if you already tried that, but that's one concrete method to measure the performance.

Solution 4:

Use DDMS and method profiling to get a TraceView.

Basically:

  1. Launch your app in debug mode
  2. In DDMS, in the Devices tab, click "Start method profiling"
  3. Do stuff on your device to recreate the conditions you want to monitor
  4. Click "Stop method profiling"
  5. You'll get a fairly detailed graph with each thread's execution that you can drill down into

More details here: http://developer.android.com/tools/debugging/debugging-tracing.html

Disclaimer: I've only done this with a simple test app so I don't know how much mileage you'll get out of it. It does seem to give a bit more precision than what has been described so far, and does not require root.

enter image description here

Post a Comment for "How To Get Higher Precision Of "cpu%" Than That From Top Command?"