Is there any way that I can, over a period of say a day, see how much CPU (or battery) each app uses? Here's a sample from BatteryDoctor app:
I think they did some works programmatically like:
- Get CPU time of an app
- Get Network Data Usage of an app
From that, they can "calculate" the battery usage per app (in percent).
I know there is some way to get the second work (Data Usage). But for the first one, seems like it's really hard to get.
I've found some ways, but they seems don't work
- Tracking long-term CPU usage of apps in android (The
"/proc/" + pid + "/stat"
way)- I can't run this one, seems like toks[2] is always "S" - The command way (
"sh -c top -m 1000 -d 1 -n 1 | grep \"" + pid + "\" "
).
In anyway, it only can return the percent of CPU which app is using. But I want the time of CPU which app's used for a period (like 24 hours in the example).
So does anyone know how to get that CPU time per app programmatically ? Or maybe it just the foreground/running time of an app?