am d0ce1fbb: am 69e17f59: am da43a3aa: Merge "BatteryStats: Start using cpu power from kernel" into mnc-dr-dev
* commit 'd0ce1fbbba497e9b5082c69d8da7260e85b0b579': BatteryStats: Start using cpu power from kernel
This commit is contained in:
@@ -468,6 +468,7 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
* @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
|
* @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
|
||||||
* @see BatteryStats#getCpuSpeedSteps()
|
* @see BatteryStats#getCpuSpeedSteps()
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract long getTimeAtCpuSpeed(int step, int which);
|
public abstract long getTimeAtCpuSpeed(int step, int which);
|
||||||
|
|
||||||
public static abstract class Sensor {
|
public static abstract class Sensor {
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ public final class BatteryStatsHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mCpuPowerCalculator == null) {
|
if (mCpuPowerCalculator == null) {
|
||||||
mCpuPowerCalculator = new CpuPowerCalculator(mPowerProfile);
|
mCpuPowerCalculator = new CpuPowerCalculator();
|
||||||
}
|
}
|
||||||
mCpuPowerCalculator.reset();
|
mCpuPowerCalculator.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -23,54 +23,14 @@ public class CpuPowerCalculator extends PowerCalculator {
|
|||||||
private static final String TAG = "CpuPowerCalculator";
|
private static final String TAG = "CpuPowerCalculator";
|
||||||
private static final boolean DEBUG = BatteryStatsHelper.DEBUG;
|
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
|
@Override
|
||||||
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
|
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
|
||||||
long rawUptimeUs, int statsType) {
|
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;
|
app.cpuTimeMs = (u.getUserCpuTimeUs(statsType) + u.getSystemCpuTimeUs(statsType)) / 1000;
|
||||||
if (DEBUG && app.cpuTimeMs != 0) {
|
app.cpuPowerMah = (double) u.getCpuPowerMaUs(statsType) / (60.0 * 60.0 * 1000.0 * 1000.0);
|
||||||
Log.d(TAG, "UID " + u.getUid() + ": CPU time " + app.cpuTimeMs + " ms");
|
if (DEBUG && (app.cpuTimeMs != 0 || app.cpuPowerMah != 0)) {
|
||||||
}
|
Log.d(TAG, "UID " + u.getUid() + ": CPU time=" + app.cpuTimeMs + " ms power="
|
||||||
|
+ BatteryStatsHelper.makemAh(app.cpuPowerMah));
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of the package with highest drain.
|
// Keep track of the package with highest drain.
|
||||||
@@ -108,8 +68,5 @@ public class CpuPowerCalculator extends PowerCalculator {
|
|||||||
// Statistics may not have been gathered yet.
|
// Statistics may not have been gathered yet.
|
||||||
app.cpuTimeMs = app.cpuFgTimeMs;
|
app.cpuTimeMs = app.cpuFgTimeMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the CPU power to mAh
|
|
||||||
app.cpuPowerMah = cpuPowerMaMs / (60 * 60 * 1000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user