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

Commit b943fabf authored by Adam Lesinski's avatar Adam Lesinski
Browse files

Adding per UID WiFi power distribution.

Change-Id: Ia3d97e0a1c3352127185c18626d8ba8221c9ab40
parent 1fd5d21e
Loading
Loading
Loading
Loading
+56 −16
Original line number Original line Diff line number Diff line
@@ -268,6 +268,15 @@ public abstract class BatteryStats implements Parcelable {
         */
         */
        public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
        public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);


        /**
         * Returns the total time in microseconds associated with this Timer since the
         * 'mark' was last set.
         *
         * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
         * @return a time in microseconds
         */
        public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);

        /**
        /**
         * Temporary for debugging.
         * Temporary for debugging.
         */
         */
@@ -333,6 +342,16 @@ public abstract class BatteryStats implements Parcelable {
         */
         */
        public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
        public abstract ArrayMap<String, ? extends Pkg> getPackageStats();


        /**
         * Returns the time in milliseconds that this app kept the WiFi controller in the
         * specified state <code>type</code>.
         * @param type one of {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, or
         *             {@link #CONTROLLER_TX_TIME}.
         * @param which one of {@link #STATS_CURRENT}, {@link #STATS_SINCE_CHARGED}, or
         *              {@link #STATS_SINCE_UNPLUGGED}.
         */
        public abstract long getWifiControllerActivity(int type, int which);

        /**
        /**
         * {@hide}
         * {@hide}
         */
         */
@@ -1914,7 +1933,6 @@ public abstract class BatteryStats implements Parcelable {
    public static final int NETWORK_MOBILE_TX_DATA = 1;
    public static final int NETWORK_MOBILE_TX_DATA = 1;
    public static final int NETWORK_WIFI_RX_DATA = 2;
    public static final int NETWORK_WIFI_RX_DATA = 2;
    public static final int NETWORK_WIFI_TX_DATA = 3;
    public static final int NETWORK_WIFI_TX_DATA = 3;

    public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
    public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;


    public abstract long getNetworkActivityBytes(int type, int which);
    public abstract long getNetworkActivityBytes(int type, int which);
@@ -1923,10 +1941,25 @@ public abstract class BatteryStats implements Parcelable {
    public static final int CONTROLLER_IDLE_TIME = 0;
    public static final int CONTROLLER_IDLE_TIME = 0;
    public static final int CONTROLLER_RX_TIME = 1;
    public static final int CONTROLLER_RX_TIME = 1;
    public static final int CONTROLLER_TX_TIME = 2;
    public static final int CONTROLLER_TX_TIME = 2;
    public static final int CONTROLLER_ENERGY = 3;
    public static final int CONTROLLER_POWER_DRAIN = 3;
    public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_ENERGY + 1;
    public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_POWER_DRAIN + 1;


    /**
     * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
     * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
     * respective state.
     * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
     * milli-ampere-milliseconds (mAms).
     */
    public abstract long getBluetoothControllerActivity(int type, int which);
    public abstract long getBluetoothControllerActivity(int type, int which);

    /**
     * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
     * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
     * respective state.
     * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
     * milli-ampere-milliseconds (mAms).
     */
    public abstract long getWifiControllerActivity(int type, int which);
    public abstract long getWifiControllerActivity(int type, int which);


    /**
    /**
@@ -2618,7 +2651,7 @@ public abstract class BatteryStats implements Parcelable {
                        label = "???";
                        label = "???";
                }
                }
                dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
                dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
                        BatteryStatsHelper.makemAh(bs.value));
                        BatteryStatsHelper.makemAh(bs.totalPowerMah));
            }
            }
        }
        }


@@ -3262,6 +3295,13 @@ public abstract class BatteryStats implements Parcelable {
        sb.append(")");
        sb.append(")");
        pw.println(sb.toString());
        pw.println(sb.toString());


        sb.setLength(0);
        sb.append(prefix);
        sb.append("  WiFi Energy use: ").append(BatteryStatsHelper.makemAh(
                getWifiControllerActivity(CONTROLLER_POWER_DRAIN, which) / (double)(1000*60*60)));
        sb.append(" mAh");
        pw.println(sb.toString());

        sb.setLength(0);
        sb.setLength(0);
        sb.append(prefix);
        sb.append(prefix);
                sb.append("  Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
                sb.append("  Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
@@ -3376,48 +3416,48 @@ public abstract class BatteryStats implements Parcelable {
                final BatterySipper bs = sippers.get(i);
                final BatterySipper bs = sippers.get(i);
                switch (bs.drainType) {
                switch (bs.drainType) {
                    case IDLE:
                    case IDLE:
                        pw.print(prefix); pw.print("    Idle: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Idle: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case CELL:
                    case CELL:
                        pw.print(prefix); pw.print("    Cell standby: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Cell standby: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case PHONE:
                    case PHONE:
                        pw.print(prefix); pw.print("    Phone calls: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Phone calls: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case WIFI:
                    case WIFI:
                        pw.print(prefix); pw.print("    Wifi: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Wifi: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case BLUETOOTH:
                    case BLUETOOTH:
                        pw.print(prefix); pw.print("    Bluetooth: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Bluetooth: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case SCREEN:
                    case SCREEN:
                        pw.print(prefix); pw.print("    Screen: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Screen: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case FLASHLIGHT:
                    case FLASHLIGHT:
                        pw.print(prefix); pw.print("    Flashlight: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Flashlight: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case APP:
                    case APP:
                        pw.print(prefix); pw.print("    Uid ");
                        pw.print(prefix); pw.print("    Uid ");
                        UserHandle.formatUid(pw, bs.uidObj.getUid());
                        UserHandle.formatUid(pw, bs.uidObj.getUid());
                        pw.print(": "); printmAh(pw, bs.value); pw.println();
                        pw.print(": "); printmAh(pw, bs.totalPowerMah); pw.println();
                        break;
                        break;
                    case USER:
                    case USER:
                        pw.print(prefix); pw.print("    User "); pw.print(bs.userId);
                        pw.print(prefix); pw.print("    User "); pw.print(bs.userId);
                        pw.print(": "); printmAh(pw, bs.value); pw.println();
                        pw.print(": "); printmAh(pw, bs.totalPowerMah); pw.println();
                        break;
                        break;
                    case UNACCOUNTED:
                    case UNACCOUNTED:
                        pw.print(prefix); pw.print("    Unaccounted: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Unaccounted: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                    case OVERCOUNTED:
                    case OVERCOUNTED:
                        pw.print(prefix); pw.print("    Over-counted: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Over-counted: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        pw.println();
                        break;
                        break;
                }
                }
+1 −0
Original line number Original line Diff line number Diff line
@@ -109,6 +109,7 @@ interface IBatteryStats {
    void noteWifiBatchedScanStoppedFromSource(in WorkSource ws);
    void noteWifiBatchedScanStoppedFromSource(in WorkSource ws);
    void noteWifiMulticastEnabledFromSource(in WorkSource ws);
    void noteWifiMulticastEnabledFromSource(in WorkSource ws);
    void noteWifiMulticastDisabledFromSource(in WorkSource ws);
    void noteWifiMulticastDisabledFromSource(in WorkSource ws);
    void noteWifiRadioPowerState(int powerState, long timestampNs);
    void noteNetworkInterfaceType(String iface, int type);
    void noteNetworkInterfaceType(String iface, int type);
    void noteNetworkStatsEnabled();
    void noteNetworkStatsEnabled();
    void noteDeviceIdleMode(boolean enabled, boolean fromActive, boolean fromMotion);
    void noteDeviceIdleMode(boolean enabled, boolean fromActive, boolean fromMotion);
+50 −34
Original line number Original line Diff line number Diff line
@@ -23,17 +23,25 @@ import android.os.BatteryStats.Uid;
public class BatterySipper implements Comparable<BatterySipper> {
public class BatterySipper implements Comparable<BatterySipper> {
    public int userId;
    public int userId;
    public Uid uidObj;
    public Uid uidObj;
    public double value;
    public double totalPowerMah;
    public double[] values;
    public DrainType drainType;
    public DrainType drainType;


    // Measured in milliseconds.
    /**
    public long usageTime;
     * Generic usage time in milliseconds.
    public long cpuTime;
     */
    public long gpsTime;
    public long usageTimeMs;
    public long wifiRunningTime;

    public long cpuFgTime;
    /**
    public long wakeLockTime;
     * Generic power usage in mAh.
     */
    public double usagePowerMah;

    // Subsystem usage times.
    public long cpuTimeMs;
    public long gpsTimeMs;
    public long wifiRunningTimeMs;
    public long cpuFgTimeMs;
    public long wakeLockTimeMs;


    public long mobileRxPackets;
    public long mobileRxPackets;
    public long mobileTxPackets;
    public long mobileTxPackets;
@@ -52,12 +60,13 @@ public class BatterySipper implements Comparable<BatterySipper> {
    public String packageWithHighestDrain;
    public String packageWithHighestDrain;


    // Measured in mAh (milli-ampere per hour).
    // Measured in mAh (milli-ampere per hour).
    public double wifiPower;
    // These are included when summed.
    public double cpuPower;
    public double wifiPowerMah;
    public double wakeLockPower;
    public double cpuPowerMah;
    public double mobileRadioPower;
    public double wakeLockPowerMah;
    public double gpsPower;
    public double mobileRadioPowerMah;
    public double sensorPower;
    public double gpsPowerMah;
    public double sensorPowerMah;


    public enum DrainType {
    public enum DrainType {
        IDLE,
        IDLE,
@@ -73,17 +82,12 @@ public class BatterySipper implements Comparable<BatterySipper> {
        OVERCOUNTED
        OVERCOUNTED
    }
    }


    public BatterySipper(DrainType drainType, Uid uid, double[] values) {
    public BatterySipper(DrainType drainType, Uid uid, double value) {
        this.values = values;
        this.totalPowerMah = value;
        if (values != null) value = values[0];
        this.drainType = drainType;
        this.drainType = drainType;
        uidObj = uid;
        uidObj = uid;
    }
    }


    public double[] getValues() {
        return values;
    }

    public void computeMobilemspp() {
    public void computeMobilemspp() {
        long packets = mobileRxPackets+mobileTxPackets;
        long packets = mobileRxPackets+mobileTxPackets;
        mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0;
        mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0;
@@ -101,7 +105,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
            }
            }
        }
        }
        // Return the flipped value because we want the items in descending order
        // Return the flipped value because we want the items in descending order
        return Double.compare(other.value, value);
        return Double.compare(other.totalPowerMah, totalPowerMah);
    }
    }


    /**
    /**
@@ -123,11 +127,14 @@ public class BatterySipper implements Comparable<BatterySipper> {
     * Add stats from other to this BatterySipper.
     * Add stats from other to this BatterySipper.
     */
     */
    public void add(BatterySipper other) {
    public void add(BatterySipper other) {
        cpuTime += other.cpuTime;
        totalPowerMah += other.totalPowerMah;
        gpsTime += other.gpsTime;
        usageTimeMs += other.usageTimeMs;
        wifiRunningTime += other.wifiRunningTime;
        usagePowerMah += other.usagePowerMah;
        cpuFgTime += other.cpuFgTime;
        cpuTimeMs += other.cpuTimeMs;
        wakeLockTime += other.wakeLockTime;
        gpsTimeMs += other.gpsTimeMs;
        wifiRunningTimeMs += other.wifiRunningTimeMs;
        cpuFgTimeMs += other.cpuFgTimeMs;
        wakeLockTimeMs += other.wakeLockTimeMs;
        mobileRxPackets += other.mobileRxPackets;
        mobileRxPackets += other.mobileRxPackets;
        mobileTxPackets += other.mobileTxPackets;
        mobileTxPackets += other.mobileTxPackets;
        mobileActive += other.mobileActive;
        mobileActive += other.mobileActive;
@@ -138,11 +145,20 @@ public class BatterySipper implements Comparable<BatterySipper> {
        mobileTxBytes += other.mobileTxBytes;
        mobileTxBytes += other.mobileTxBytes;
        wifiRxBytes += other.wifiRxBytes;
        wifiRxBytes += other.wifiRxBytes;
        wifiTxBytes += other.wifiTxBytes;
        wifiTxBytes += other.wifiTxBytes;
        wifiPower += other.wifiPower;
        wifiPowerMah += other.wifiPowerMah;
        gpsPower += other.gpsPower;
        gpsPowerMah += other.gpsPowerMah;
        cpuPower += other.cpuPower;
        cpuPowerMah += other.cpuPowerMah;
        sensorPower += other.sensorPower;
        sensorPowerMah += other.sensorPowerMah;
        mobileRadioPower += other.mobileRadioPower;
        mobileRadioPowerMah += other.mobileRadioPowerMah;
        wakeLockPower += other.wakeLockPower;
        wakeLockPowerMah += other.wakeLockPowerMah;
    }

    /**
     * Sum all the powers and store the value into `value`.
     * @return the sum of all the power in this BatterySipper.
     */
    public double sumPower() {
        return totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + sensorPowerMah
                + mobileRadioPowerMah + wakeLockPowerMah;
    }
    }
}
}
+186 −537

File changed.

Preview size limit exceeded, changes collapsed.

+318 −54

File changed.

Preview size limit exceeded, changes collapsed.

Loading