summaryrefslogtreecommitdiffstats
path: root/core/java/android/os/BatteryStats.java
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-05-05 17:35:35 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-05-12 13:19:05 -0700
commit06af1fac166a83507450b6bbb1f98a8dde68d92e (patch)
tree7af6972a2650ba63aa0abb18971f841df4d0cf62 /core/java/android/os/BatteryStats.java
parenta4492b418d23e3bcdb077aab5d48eb24e932fc13 (diff)
downloadframeworks_base-06af1fac166a83507450b6bbb1f98a8dde68d92e.zip
frameworks_base-06af1fac166a83507450b6bbb1f98a8dde68d92e.tar.gz
frameworks_base-06af1fac166a83507450b6bbb1f98a8dde68d92e.tar.bz2
Parse uid_cputime proc file
Instead of using the ProcessCpuTracker as the source of truth, we periodically poll the new uid_cputime kernel module for stats on all UID cpu time. TODO: Need to tell the kernel when to stop tracking UIDs (aka on package uninstall). Change-Id: Id1d251aae23ab53f7acc0aba3bca5118bc2c194a
Diffstat (limited to 'core/java/android/os/BatteryStats.java')
-rw-r--r--core/java/android/os/BatteryStats.java37
1 files changed, 28 insertions, 9 deletions
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 4dfe0de..5f515eb 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -425,6 +425,24 @@ public abstract class BatteryStats implements Parcelable {
public abstract long getMobileRadioActiveTime(int which);
public abstract int getMobileRadioActiveCount(int which);
+ /**
+ * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
+ */
+ public abstract long getUserCpuTimeUs(int which);
+
+ /**
+ * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
+ */
+ public abstract long getSystemCpuTimeUs(int which);
+
+ /**
+ * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
+ * @param speedStep the index of the CPU speed. This is not the actual speed of the CPU.
+ * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
+ * @see BatteryStats#getCpuSpeedSteps()
+ */
+ public abstract long getTimeAtCpuSpeed(int step, int which);
+
public static abstract class Sensor {
/*
* FIXME: it's not correct to use this magic value because it
@@ -506,15 +524,6 @@ public abstract class BatteryStats implements Parcelable {
*/
public abstract long getForegroundTime(int which);
- /**
- * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
- * @param speedStep the index of the CPU speed. This is not the actual speed of the
- * CPU.
- * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
- * @see BatteryStats#getCpuSpeedSteps()
- */
- public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
-
public abstract int countExcessivePowers();
public abstract ExcessivePower getExcessivePower(int i);
@@ -3873,6 +3882,16 @@ public abstract class BatteryStats implements Parcelable {
}
}
+ final long userCpuTimeUs = u.getUserCpuTimeUs(which);
+ final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
+ if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
+ sb.setLength(0);
+ sb.append(prefix);
+ sb.append(" Total cpu time: ");
+ formatTimeMs(sb, (userCpuTimeUs + systemCpuTimeUs) / 1000);
+ pw.println(sb.toString());
+ }
+
final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
= u.getProcessStats();
for (int ipr=processStats.size()-1; ipr>=0; ipr--) {