Loading core/java/android/os/BatteryStats.java +1 −0 Original line number Diff line number Diff line Loading @@ -468,6 +468,7 @@ public abstract class BatteryStats implements Parcelable { * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @see BatteryStats#getCpuSpeedSteps() */ @Deprecated public abstract long getTimeAtCpuSpeed(int step, int which); public static abstract class Sensor { Loading core/java/com/android/internal/os/BatteryStatsHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -338,7 +338,7 @@ public final class BatteryStatsHelper { } if (mCpuPowerCalculator == null) { mCpuPowerCalculator = new CpuPowerCalculator(mPowerProfile); mCpuPowerCalculator = new CpuPowerCalculator(); } mCpuPowerCalculator.reset(); Loading core/java/com/android/internal/os/CpuPowerCalculator.java +4 −47 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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); } } Loading
core/java/android/os/BatteryStats.java +1 −0 Original line number Diff line number Diff line Loading @@ -468,6 +468,7 @@ public abstract class BatteryStats implements Parcelable { * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @see BatteryStats#getCpuSpeedSteps() */ @Deprecated public abstract long getTimeAtCpuSpeed(int step, int which); public static abstract class Sensor { Loading
core/java/com/android/internal/os/BatteryStatsHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -338,7 +338,7 @@ public final class BatteryStatsHelper { } if (mCpuPowerCalculator == null) { mCpuPowerCalculator = new CpuPowerCalculator(mPowerProfile); mCpuPowerCalculator = new CpuPowerCalculator(); } mCpuPowerCalculator.reset(); Loading
core/java/com/android/internal/os/CpuPowerCalculator.java +4 −47 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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); } }