summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2009-09-20 15:52:35 -0700
committerAmith Yamasani <yamasani@google.com>2009-09-20 15:57:39 -0700
commitd459bebd89756a8b735feb6f27bd864b0427feb7 (patch)
tree9bbd8e4c06ef241673e3db9e8a54765c3fef9a50 /src
parent8cd8b0b7edca98b84c5a1f6223ac0b343eb26e8d (diff)
downloadpackages_apps_settings-d459bebd89756a8b735feb6f27bd864b0427feb7.zip
packages_apps_settings-d459bebd89756a8b735feb6f27bd864b0427feb7.tar.gz
packages_apps_settings-d459bebd89756a8b735feb6f27bd864b0427feb7.tar.bz2
Use the ratio of different CPU speeds to compute CPU power consumption per app.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/fuelgauge/PowerUsageSummary.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 10c9a43..a41cbf4 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -295,7 +295,12 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
private void processAppUsage() {
SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
final int which = mStatsType;
- final double powerCpuNormal = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_NORMAL);
+ final int speedSteps = mPowerProfile.getNumSpeedSteps();
+ final double[] powerCpuNormal = new double[speedSteps];
+ final long[] cpuSpeedStepTimes = new long[speedSteps];
+ for (int p = 0; p < speedSteps; p++) {
+ powerCpuNormal[p] = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE, p);
+ }
final double averageCostPerByte = getAverageDataCost();
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which);
updateStatsPeriod(uSecTime);
@@ -322,7 +327,19 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
final long foregroundTime = ps.getForegroundTime(which);
cpuFgTime += foregroundTime * 10; // convert to millis
final long tmpCpuTime = (userTime + systemTime) * 10; // convert to millis
- final double processPower = tmpCpuTime * powerCpuNormal;
+ int totalTimeAtSpeeds = 0;
+ // Get the total first
+ for (int step = 0; step < speedSteps; step++) {
+ cpuSpeedStepTimes[step] = ps.getTimeAtCpuSpeedStep(step, which);
+ totalTimeAtSpeeds += cpuSpeedStepTimes[step];
+ }
+ if (totalTimeAtSpeeds == 0) totalTimeAtSpeeds = 1;
+ // Then compute the ratio of time spent at each speed
+ double processPower = 0;
+ for (int step = 0; step < speedSteps; step++) {
+ double ratio = (double) cpuSpeedStepTimes[step] / totalTimeAtSpeeds;
+ processPower += ratio * tmpCpuTime * powerCpuNormal[step];
+ }
cpuTime += tmpCpuTime;
power += processPower;
if (highestDrain < processPower) {