Search code examples
androidlinuxadbcpu-usage

How to log the CPU and network utilization for Android


I want to get the CPU utilization over time and turn the records into plot diagrams. I have surveyed some method for instant utilization, like shell command top, dumpsys.

Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
-m num  Maximum number of processes to display.
-n num  Updates to show before exiting.
-d num  Seconds to wait between updates.
-s col  Column to sort by (cpu,vss,rss,thr).
-t      Show threads instead of processes.
-h      Display this help screen.

dumpsys

~$ adb shell dumpsys cpuinfo

I try to customize the chart like TaskSpy and add some details to analysis. It will be better to analysis on PC/MAC. Can I log the data periodically and efficiently by adb shell command?

https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-ash3/529645_105311226278927_50022122_n.jpg


Solution

  • I finally use top command and log it to a txt file

    top -d 1|grep 'CPU' > /sdcard/xxx.txt
    

    I choose to use top command in busybox. By using original Android top command, I can't grep the data in discrete time. In order not to increase utilization of CPU, other calculations, like graph, will be done after logging.

    If there are better answers, please let me know. Thanks