diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-08-31 19:13:39 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-08-31 19:13:39 +0000 |
commit | 69e17f59f8aaccbe66ea9ef976d01f076a7a06c3 (patch) | |
tree | e1551c941d4ea6b210bc5634c88823a584bb6d5a /core/java/com | |
parent | bbd723ce63abdc63c77869fe00ca4aee5a756a9e (diff) | |
parent | da43a3aacaba069e79f1dbfa491f6bc0b6f7fa95 (diff) | |
download | frameworks_base-69e17f59f8aaccbe66ea9ef976d01f076a7a06c3.zip frameworks_base-69e17f59f8aaccbe66ea9ef976d01f076a7a06c3.tar.gz frameworks_base-69e17f59f8aaccbe66ea9ef976d01f076a7a06c3.tar.bz2 |
am da43a3aa: Merge "BatteryStats: Start using cpu power from kernel" into mnc-dr-dev
* commit 'da43a3aacaba069e79f1dbfa491f6bc0b6f7fa95':
BatteryStats: Start using cpu power from kernel
Diffstat (limited to 'core/java/com')
-rw-r--r-- | core/java/com/android/internal/os/BatteryStatsHelper.java | 2 | ||||
-rw-r--r-- | core/java/com/android/internal/os/CpuPowerCalculator.java | 51 |
2 files changed, 5 insertions, 48 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsHelper.java b/core/java/com/android/internal/os/BatteryStatsHelper.java index f178c8c..4f4d3e0 100644 --- a/core/java/com/android/internal/os/BatteryStatsHelper.java +++ b/core/java/com/android/internal/os/BatteryStatsHelper.java @@ -338,7 +338,7 @@ public final class BatteryStatsHelper { } if (mCpuPowerCalculator == null) { - mCpuPowerCalculator = new CpuPowerCalculator(mPowerProfile); + mCpuPowerCalculator = new CpuPowerCalculator(); } mCpuPowerCalculator.reset(); diff --git a/core/java/com/android/internal/os/CpuPowerCalculator.java b/core/java/com/android/internal/os/CpuPowerCalculator.java index a3ef612..d62f7a6 100644 --- a/core/java/com/android/internal/os/CpuPowerCalculator.java +++ b/core/java/com/android/internal/os/CpuPowerCalculator.java @@ -23,54 +23,14 @@ public class CpuPowerCalculator extends PowerCalculator { private static final String TAG = "CpuPowerCalculator"; private static final boolean DEBUG = BatteryStatsHelper.DEBUG; - private final double[] mPowerCpuNormal; - - /** - * Reusable array for calculations. - */ - private final long[] mSpeedStepTimes; - - public CpuPowerCalculator(PowerProfile profile) { - final int speedSteps = profile.getNumSpeedSteps(); - mPowerCpuNormal = new double[speedSteps]; - mSpeedStepTimes = new long[speedSteps]; - for (int p = 0; p < speedSteps; p++) { - mPowerCpuNormal[p] = profile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE, p); - } - } - @Override public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) { - final int speedSteps = mSpeedStepTimes.length; - - long totalTimeAtSpeeds = 0; - for (int step = 0; step < speedSteps; step++) { - mSpeedStepTimes[step] = u.getTimeAtCpuSpeed(step, statsType); - totalTimeAtSpeeds += mSpeedStepTimes[step]; - } - totalTimeAtSpeeds = Math.max(totalTimeAtSpeeds, 1); - app.cpuTimeMs = (u.getUserCpuTimeUs(statsType) + u.getSystemCpuTimeUs(statsType)) / 1000; - if (DEBUG && app.cpuTimeMs != 0) { - Log.d(TAG, "UID " + u.getUid() + ": CPU time " + app.cpuTimeMs + " ms"); - } - - double cpuPowerMaMs = 0; - for (int step = 0; step < speedSteps; step++) { - final double ratio = (double) mSpeedStepTimes[step] / totalTimeAtSpeeds; - final double cpuSpeedStepPower = ratio * app.cpuTimeMs * mPowerCpuNormal[step]; - if (DEBUG && ratio != 0) { - Log.d(TAG, "UID " + u.getUid() + ": CPU step #" - + step + " ratio=" + BatteryStatsHelper.makemAh(ratio) + " power=" - + BatteryStatsHelper.makemAh(cpuSpeedStepPower / (60 * 60 * 1000))); - } - cpuPowerMaMs += cpuSpeedStepPower; - } - - if (DEBUG && cpuPowerMaMs != 0) { - Log.d(TAG, "UID " + u.getUid() + ": cpu total power=" - + BatteryStatsHelper.makemAh(cpuPowerMaMs / (60 * 60 * 1000))); + app.cpuPowerMah = (double) u.getCpuPowerMaUs(statsType) / (60.0 * 60.0 * 1000.0 * 1000.0); + if (DEBUG && (app.cpuTimeMs != 0 || app.cpuPowerMah != 0)) { + Log.d(TAG, "UID " + u.getUid() + ": CPU time=" + app.cpuTimeMs + " ms power=" + + BatteryStatsHelper.makemAh(app.cpuPowerMah)); } // Keep track of the package with highest drain. @@ -108,8 +68,5 @@ public class CpuPowerCalculator extends PowerCalculator { // Statistics may not have been gathered yet. app.cpuTimeMs = app.cpuFgTimeMs; } - - // Convert the CPU power to mAh - app.cpuPowerMah = cpuPowerMaMs / (60 * 60 * 1000); } } |