Pregunta

I'm trying to write an Android app (java) that does things like determine battery usage by app, cpu usage by app, memory usage by app, and then overall things like battery level, cpu voltage, battery temp, cpu temp, etc. Basically a bunch of statistics which may later be used for analysis. After reading into how this might be done, it seemed to me like the best way to go about this would be to make use of /proc. Specifically, /proc/apm for battery things, /proc/cpuinfo for cpu speed, /proc/meminfo for memory fields, and /proc/stat for cpu usage. To get app specific data, would you follow /proc with the PIDs, maybe in a loop? For instance to pseudo code it, it would be like this:

Get PIDs of all running processes
Run a loop that reads info from /proc/<PID>/apm and saves pertinent data to an array,  
        then iterates the PID
Run loops like the one above for cpuinfo, meminfo, and stat

I currently read battery level just fine, and CPU usage took me a while but I think I have that too. Its app specific stuff that is getting me into trouble. Would I need root access for any of the statistics that I mentioned?

Thank you so much!

¿Fue útil?

Solución

What about using procrank? I know it isn't /proc/"PID"/stat, but doesn't it give everything you need to do the job? In the first column, you are give the PID, then columns 4/5 are PSS/USS respectively. From my understanding of this link PSS and USS can be used to calculate memory use by doing the following:

PSS/[Σ(PSS)] -> This is memory usage %

USS/[Σ(PSS)] -> This is % of memory that can be freed by killing the process

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top