How to get higher precision of “CPU%” than that from TOP command?

前端 未结 4 643
走了就别回头了
走了就别回头了 2021-02-02 02:08

When I use TOP command, I could get the following info:

shell@android:/ $ top -n 1                                                     

User 31%, System 10%, IO         


        
4条回答
  •  花落未央
    2021-02-02 02:20

    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.

提交回复
热议问题