Memory and CPU per process ANDROID

好久不见. 提交于 2020-01-13 07:24:05

问题


I'm developing an android application where in it, I want to get the running process or app list. I kinda found a way to do using activitymanager. but what I don't know is on how to get the processor and memory used per that process. does any one know how I can achieve this goal.

the code to get the running processes is,

I get all the running app processes from the above code. please help me to get the values for each an every process in the list.

thank you.


回答1:


  1. CPU load - you need to read the /proc/[pid]/stat (ref http://linux.die.net/man/5/proc). Looking for utime & stime, they are the times the process spends on user mode and kernel mode. A good example to see how it works, you can find the source code of the top utility (check out the read_stat function in top.c).

  2. Memory usage - traditionally, people read /proc/[pid]/stat again for the rss field. Now it is more popular to use the PSS. (ref http://developer.android.com/reference/android/os/Debug.html#getPss%28%29). You can wiki the definition and difference of RSS and PSS - it is something to do with the size of global share library.



来源:https://stackoverflow.com/questions/11486570/memory-and-cpu-per-process-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!