Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ea916b1 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 26050 into eclair

* changes:
  Track CPU speed stepping to get more accurate CPU cost per app.
parents ffe1cf25 e43530ab
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -314,6 +314,15 @@ public abstract class BatteryStats implements Parcelable {
             * @return foreground cpu time in microseconds
             */
            public abstract long getForegroundTime(int which);

            /**
             * Returns the approximate cpu time spent in microseconds, 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_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
             * @see BatteryStats#getCpuSpeedSteps()
             */
            public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
        }

        /**
@@ -573,6 +582,9 @@ public abstract class BatteryStats implements Parcelable {
    
    public abstract Map<String, ? extends Timer> getKernelWakelockStats();

    /** Returns the number of different speeds that the CPU can run at */
    public abstract int getCpuSpeedSteps();

    private final static void formatTimeRaw(StringBuilder out, long seconds) {
        long days = seconds / (60 * 60 * 24);
        if (days != 0) {
+3 −0
Original line number Diff line number Diff line
@@ -121,6 +121,9 @@ public class VolumePreference extends SeekBarPreference implements
       if (mSeekBarVolumizer != null) {
           Dialog dialog = getDialog();
           if (dialog != null && dialog.isShowing()) {
               View view = dialog.getWindow().getDecorView()
                       .findViewById(com.android.internal.R.id.seekbar);
               if (view != null) view.setOnKeyListener(null);
               // Stopped while dialog was showing, revert changes
               mSeekBarVolumizer.revertVolume();
           }
+72 −6
Original line number Diff line number Diff line
@@ -56,7 +56,9 @@ public final class BatteryStatsImpl extends BatteryStats {
    private static final int MAGIC = 0xBA757475; // 'BATSTATS' 

    // Current on-disk Parcel version
    private static final int VERSION = 39;
    private static final int VERSION = 40;

    private static int sNumSpeedSteps;

    private final File mFile;
    private final File mBackupFile;
@@ -213,7 +215,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    /**
     * State for keeping track of counting information.
     */
    public static final class Counter extends BatteryStats.Counter implements Unpluggable {
    public static class Counter extends BatteryStats.Counter implements Unpluggable {
        int mCount;
        int mLoadedCount;
        int mLastCount;
@@ -303,6 +305,21 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
    }

    public static class SamplingCounter extends Counter {

        SamplingCounter(ArrayList<Unpluggable> unpluggables, Parcel in) {
            super(unpluggables, in);
        }

        SamplingCounter(ArrayList<Unpluggable> unpluggables) {
            super(unpluggables);
        }

        public void addCountLocked(long count) {
            mCount += count;
        }
    }

    /**
     * State for keeping track of timing information.
     */
@@ -1940,8 +1957,14 @@ public final class BatteryStatsImpl extends BatteryStats {
             */
            long mUnpluggedForegroundTime;

            SamplingCounter[] mSpeedBins;

            Proc() {
                mUnpluggables.add(this);
                mSpeedBins = new SamplingCounter[getCpuSpeedSteps()];
                for (int i = 0; i < mSpeedBins.length; i++) {
                    mSpeedBins[i] = new SamplingCounter(mUnpluggables);
                }
            }

            public void unplug(long batteryUptime, long batteryRealtime) {
@@ -1974,6 +1997,11 @@ public final class BatteryStatsImpl extends BatteryStats {
                out.writeLong(mUnpluggedSystemTime);
                out.writeLong(mUnpluggedForegroundTime);
                out.writeInt(mUnpluggedStarts);

                out.writeInt(mSpeedBins.length);
                for (int i = 0; i < mSpeedBins.length; i++) {
                    mSpeedBins[i].writeToParcel(out);
                }
            }

            void readFromParcelLocked(Parcel in) {
@@ -1993,6 +2021,12 @@ public final class BatteryStatsImpl extends BatteryStats {
                mUnpluggedSystemTime = in.readLong();
                mUnpluggedForegroundTime = in.readLong();
                mUnpluggedStarts = in.readInt();

                int bins = in.readInt();
                mSpeedBins = new SamplingCounter[bins];
                for (int i = 0; i < bins; i++) {
                    mSpeedBins[i] = new SamplingCounter(mUnpluggables, in);
                }
            }

            public BatteryStatsImpl getBatteryStats() {
@@ -2075,6 +2109,22 @@ public final class BatteryStatsImpl extends BatteryStats {
                }
                return val;
            }

            /* Called by ActivityManagerService when CPU times are updated. */
            public void addSpeedStepTimes(long[] values) {
                for (int i = 0; i < mSpeedBins.length && i < values.length; i++) {
                    mSpeedBins[i].addCountLocked(values[i]);
                }
            }

            @Override
            public long getTimeAtCpuSpeedStep(int speedStep, int which) {
                if (speedStep < mSpeedBins.length) {
                    return mSpeedBins[speedStep].getCountLocked(which);
                } else {
                    return 0;
                }
            }
        }

        /**
@@ -2625,6 +2675,10 @@ public final class BatteryStatsImpl extends BatteryStats {
        readFromParcel(p);
    }

    public void setNumSpeedSteps(int steps) {
        if (sNumSpeedSteps == 0) sNumSpeedSteps = steps;
    }

    @Override
    public int getStartCount() {
        return mStartCount;
@@ -2853,6 +2907,11 @@ public final class BatteryStatsImpl extends BatteryStats {
            return mDischargeCurrentLevel;
    }

    @Override
    public int getCpuSpeedSteps() {
        return sNumSpeedSteps;
    }

    /**
     * Retrieve the statistics object for a particular uid, creating if needed.
     */
@@ -3064,6 +3123,8 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
        }

        sNumSpeedSteps = in.readInt();

        final int NU = in.readInt();
        for (int iu = 0; iu < NU; iu++) {
            int uid = in.readInt();
@@ -3206,6 +3267,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
        }
        
        out.writeInt(sNumSpeedSteps);
        final int NU = mUidStats.size();
        out.writeInt(NU);
        for (int iu = 0; iu < NU; iu++) {
@@ -3404,6 +3466,8 @@ public final class BatteryStatsImpl extends BatteryStats {
        mFullTimers.clear();
        mWindowTimers.clear();

        sNumSpeedSteps = in.readInt();

        int numUids = in.readInt();
        mUidStats.clear();
        for (int i = 0; i < numUids; i++) {
@@ -3485,6 +3549,8 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
        }

        out.writeInt(sNumSpeedSteps);

        int size = mUidStats.size();
        out.writeInt(size);
        for (int i = 0; i < size; i++) {
+14 −9
Original line number Diff line number Diff line
@@ -47,14 +47,9 @@ public class PowerProfile {
    public static final String POWER_CPU_IDLE = "cpu.idle";

    /**
     * Power consumption when CPU is running at normal speed.
     */
    public static final String POWER_CPU_NORMAL = "cpu.normal";

    /**
     * Power consumption when CPU is running at full speed.
     * Power consumption when CPU is in power collapse mode.
     */
    public static final String POWER_CPU_FULL = "cpu.full";
    public static final String POWER_CPU_ACTIVE = "cpu.active";

    /**
     * Power consumption when WiFi driver is scanning for networks.
@@ -124,6 +119,8 @@ public class PowerProfile {
     */
    public static final String POWER_VIDEO = "dsp.video";

    public static final String POWER_CPU_SPEEDS = "cpu.speeds";

    static final HashMap<String, Object> sPowerMap = new HashMap<String, Object>();

    private static final String TAG_DEVICE = "device";
@@ -217,7 +214,7 @@ public class PowerProfile {
     * Returns the average current in mA consumed by the subsystem for the given level.
     * @param type the subsystem type
     * @param level the level of power at which the subsystem is running. For instance, the
     *  signal strength of the cell network between 0 and 4 (if there are 4 bars max.).
     *  signal strength of the cell network between 0 and 4 (if there are 4 bars max.)
     *  If there is no data for multiple levels, the level is ignored.
     * @return the average current in milliAmps.
     */
@@ -240,4 +237,12 @@ public class PowerProfile {
            return 0;
        }
    }

    public int getNumSpeedSteps() {
        Object value = sPowerMap.get(POWER_CPU_SPEEDS);
        if (value != null && value instanceof Double[]) {
            return ((Double[])value).length;
        }
        return 1; // Only one speed
    }
}
+12 −3
Original line number Diff line number Diff line
@@ -26,15 +26,24 @@
  <item name="wifi.on">0.1</item>
  <item name="wifi.active">0.1</item>
  <item name="wifi.scan">0.1</item>
  <item name="cpu.idle">0.1</item>
  <item name="cpu.normal">0.2</item>
  <item name="cpu.full">1</item>
  <item name="dsp.audio">0.1</item>
  <item name="dsp.video">0.1</item>
  <item name="radio.active">1</item>
  <item name="gps.on">1</item>
  <!-- Current consumed by the radio at different signal strengths, when paging -->
  <array name="radio.on"> <!-- Strength 0 to BINS-1 -->
      <value>1</value>
      <value>0.1</value>
  </array>
  <!-- Different CPU speeds as reported in
       /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state -->
  <array name="cpu.speeds">
      <value>400000</value> <!-- 400 MHz CPU speed -->
  </array>
  <!-- Power consumption when CPU is idle -->
  <item name="cpu.idle">0.1</item>
  <!-- Power consumption at different speeds -->
  <array name="cpu.active">
      <value>0.2</value>
  </array>
</device>
Loading