diff options
author | Amith Yamasani <yamasani@google.com> | 2009-06-03 15:16:10 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2009-06-03 15:38:24 -0700 |
commit | eaeb663bcd7a82b654954b42663232cbd7bef7e7 (patch) | |
tree | c9b62c0df637d7bd394aaf39e490641dadda9744 /services/java/com/android/server/ProcessStats.java | |
parent | cede1ed3e1721dc4a697a540388ef0f4b51c60eb (diff) |
Track activity foreground CPU usage for battery stats.
Track the foreground CPU time of an activity so that we can tell if apps are
spending more time in the background compared to foreground.
Update power profile values for screen backlight and GPS.
Fix some javadoc bugs (milliseconds vs. microseconds).
Diffstat (limited to 'services/java/com/android/server/ProcessStats.java')
-rw-r--r-- | services/java/com/android/server/ProcessStats.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/services/java/com/android/server/ProcessStats.java b/services/java/com/android/server/ProcessStats.java index 55adabbfa7a0..58f8980c004d 100644 --- a/services/java/com/android/server/ProcessStats.java +++ b/services/java/com/android/server/ProcessStats.java @@ -54,7 +54,10 @@ public class ProcessStats { PROC_SPACE_TERM|PROC_OUT_LONG // 14: stime }; + /** Stores user time and system time in 100ths of a second. */ private final long[] mProcessStatsData = new long[2]; + /** Stores user time and system time in 100ths of a second. */ + private final long[] mSinglePidStatsData = new long[2]; private static final int[] PROCESS_FULL_STATS_FORMAT = new int[] { PROC_SPACE_TERM, @@ -418,7 +421,18 @@ public class ProcessStats { return pids; } - + + public long getCpuTimeForPid(int pid) { + final String statFile = "/proc/" + pid + "/stat"; + final long[] statsData = mSinglePidStatsData; + if (Process.readProcFile(statFile, PROCESS_STATS_FORMAT, + null, statsData, null)) { + long time = statsData[0] + statsData[1]; + return time; + } + return 0; + } + final public int getLastUserTime() { return mRelUserTime; } |