内存和每个进程的CPU ANDROID [英] Memory and CPU per process ANDROID

查看:133
本文介绍了内存和每个进程的CPU ANDROID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序在哪里,我想获得正在运行的进程或应用程序列表。我有点找到了一种方法使用activitymanager做。但我不知道的是如何让每个这一过程中使用的处理器和内存。没有任何一个知道我可以实现这个目标。

在code,以获得正在运行的进程是,

我得到的所有从上面code中的正在运行的应用程序。请帮助我获得列表中的每一个的每一个过程中的值。

感谢您。


解决方案

  1. CPU负载 - 你需要阅读的/ proc / [PID] / STAT(参考的http:// linux.die.net/man/5/proc )。寻找UTIME&安培; STIME,它们是该流程的用户模式和内核模式中花费的时间。一个很好的例子,看看它是如何工作的,你可以找到顶级的实用程序的源代码code(检查出top.c的read_stat功能)。


  2. 内存使用情况 - 传统上,人们再次读取的/ proc / [PID] / STAT的RSS领域。现在是比较流行的使用PSS。 (参见<一个href=\"http://developer.android.com/reference/android/os/Debug.html#getPss%28%29\">http://developer.android.com/reference/android/os/Debug.html#getPss%28%29).您可以维基的定义和RSS和PSS的差别 - 这是是与全球份额库的大小


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. 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.

这篇关于内存和每个进程的CPU ANDROID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆