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

Commit ab530203 authored by Chenjie Yu's avatar Chenjie Yu
Browse files

pull PowerProfile into statsd

pull constants from PowerProfile into statsd for power model
calculations. The data is mostly from power_profile.xml

power_profile {
  power_profile_proto {
    cpu_suspend: 5.734
    cpu_idle: 1.389
    cpu_active: 18.76
    wifi_controller_idle: 2.0
    wifi_controller_rx: 107.0
    wifi_controller_tx: 371.0
    wifi_controller_operating_voltage: 3700.0
    bluetooth_controller_idle: 0.01
    bluetooth_controller_rx: 8.0
    bluetooth_controller_tx: 7.0
    bluetooth_controller_operating_voltage: 3300.0
    modem_controller_idle: 105.0
    modem_controller_rx: 175.0
    modem_controller_tx: 176.0
    modem_controller_tx: 216.0
    modem_controller_tx: 300.0
    modem_controller_tx: 427.0
    modem_controller_tx: 604.0
    modem_controller_operating_voltage: 3700.0
    gps_signal_quality_based: 49.0
    gps_signal_quality_based: 11.0
    gps_operating_voltage: 3700.0
    screen_on: 178.708
    screen_full: 240.79
    audio: 75.6
    video: 50.93
    flashlight: 298.498
    camera: 1152.292
    battery_capacity: 3450.0
    cpu_cluster {
      cores: 2
      speed: 307200
      speed: 384000
      speed: 460800
      speed: 537600
      speed: 614400
      speed: 691200
      speed: 768000
      speed: 844800
      speed: 902600
      speed: 979200
      speed: 1056000
      speed: 1132800
      speed: 1209600
      speed: 1286400
      speed: 1363200
      speed: 1440000
      speed: 1516800
      speed: 1593600
      core_power: 11.272
      core_power: 14.842
      core_power: 18.497
      core_power: 22.518
      core_power: 25.967
      core_power: 31.694
      core_power: 37.673
      core_power: 42.859
      core_power: 46.872
      core_power: 57.92
      core_power: 67.561
      core_power: 76.303
      core_power: 87.613
      core_power: 97.045
      core_power: 109.544
      core_power: 122.054
      core_power: 136.345
      core_power: 154.435
    }
    cpu_cluster {
      id: 1
      cores: 2
      speed: 307200
      speed: 384000
      speed: 460800
      speed: 537600
      speed: 614400
      speed: 691200
      speed: 748800
      speed: 825600
      speed: 902400
      speed: 979200
      speed: 1056000
      speed: 1132800
      speed: 1209600
      speed: 1286400
      speed: 1363200
      speed: 1440000
      speed: 1516800
      speed: 1593600
      speed: 1670400
      speed: 1747200
      speed: 1824000
      speed: 1900800
      speed: 1977600
      speed: 2054400
      speed: 2150400
      core_power: 7.055
      core_power: 11.483
      core_power: 14.979
      core_power: 19.642
      core_power: 23.167
      core_power: 27.479
      core_power: 31.632
      core_power: 39.192
      core_power: 47.817
      core_power: 55.659
      core_power: 64.908
      core_power: 73.824
      core_power: 85.299
      core_power: 96.036
      core_power: 109.233
      core_power: 118.56
      core_power: 132.959
      core_power: 143.692
      core_power: 161.378
      core_power: 180.616
      core_power: 193.897
      core_power: 214.361
      core_power: 238.338
      core_power: 265.759
      core_power: 297.918
    }
  }
}

Bug: 113353350
Test: manual test on statsd
Change-Id: I1edd4db255c0440ddbff1d40e1515caaccbc73f8
parent bbd22043
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import "frameworks/base/core/proto/android/telephony/enums.proto";
import "frameworks/base/core/proto/android/view/enums.proto";
import "frameworks/base/proto/src/stats_enums.proto";
import "frameworks/base/core/proto/android/service/procstats.proto";
import "frameworks/base/core/proto/android/internal/powerprofile.proto";

/**
 * The master atom class. This message defines all of the available
@@ -175,10 +176,11 @@ message Atom {
        DirectoryUsage directory_usage = 10026;
        AppSize app_size = 10027;
        CategorySize category_size = 10028;
        ProcStats proc_stats = 10029;
        BatteryVoltage battery_voltage = 10030;
        NumFingerprints num_fingerprints = 10031;
        ProcStats proc_stats = 10029;
        DiskIo disk_io = 10032;
        PowerProfile power_profile = 10033;
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -2665,3 +2667,11 @@ message NumFingerprints {
message ProcStats {
    optional android.service.procstats.ProcessStatsSectionProto proc_stats_section = 1;
}

/**
 * power_profile.xml and other constants for power model calculations.
 * Pulled from PowerProfile.java
 */
message PowerProfile {
    optional com.android.internal.os.PowerProfileProto power_profile_proto = 1;
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ bool StatsCompanionServicePuller::PullInternal(vector<shared_ptr<LogEvent> >* da
        vector<StatsLogEventWrapper> returned_value;
        Status status = statsCompanionServiceCopy->pullData(mTagId, &returned_value);
        if (!status.isOk()) {
            ALOGW("StatsCompanionServicePuller::pull failed to pull for %d", mTagId);
            ALOGW("StatsCompanionServicePuller::pull failed for %d", mTagId);
            return false;
        }
        data->clear();
+3 −0
Original line number Diff line number Diff line
@@ -217,6 +217,9 @@ const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
          {},
          3 * NS_PER_SEC,
          new StatsCompanionServicePuller(android::util::DISK_IO)}},
        // PowerProfile constants for power model calculations.
        {android::util::POWER_PROFILE,
         {{}, {}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::POWER_PROFILE)}},
};

StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
+23 −0
Original line number Diff line number Diff line
@@ -70,11 +70,17 @@ public final class StatsLogEventWrapper implements Parcelable {
                }
            };

    /**
     * Write a int value.
     */
    public void writeInt(int val) {
        mTypes.add(EVENT_TYPE_INT);
        mValues.add(val);
    }

    /**
     * Write a long value.
     */
    public void writeLong(long val) {
        mTypes.add(EVENT_TYPE_LONG);
        mValues.add(val);
@@ -89,11 +95,22 @@ public final class StatsLogEventWrapper implements Parcelable {
        mValues.add(val == null ? "" : val);
    }

    /**
     * Write a float value.
     */
    public void writeFloat(float val) {
        mTypes.add(EVENT_TYPE_FLOAT);
        mValues.add(val);
    }

    /**
     * Write a double value.
     */
    public void writeDouble(double val) {
        mTypes.add(EVENT_TYPE_DOUBLE);
        mValues.add(val);
    }

    /**
     * Write a storage value.
     */
@@ -102,6 +119,9 @@ public final class StatsLogEventWrapper implements Parcelable {
        mValues.add(val);
    }

    /**
     * Write a boolean value.
     */
    public void writeBoolean(boolean val) {
        mTypes.add(EVENT_TYPE_INT);
        mValues.add(val ? 1 : 0);
@@ -134,6 +154,9 @@ public final class StatsLogEventWrapper implements Parcelable {
                case EVENT_TYPE_FLOAT:
                    out.writeFloat((float) mValues.get(i));
                    break;
                case EVENT_TYPE_DOUBLE:
                    out.writeDouble((double) mValues.get(i));
                    break;
                case EVENT_TYPE_STRING:
                    out.writeString((String) mValues.get(i));
                    break;
+178 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.XmlUtils;
@@ -501,4 +502,181 @@ public class PowerProfile {
    public double getBatteryCapacity() {
        return getAveragePower(POWER_BATTERY_CAPACITY);
    }

    /**
     * Dump power constants into PowerProfileProto
     */
    public void writeToProto(ProtoOutputStream proto) {
        // cpu.suspend
        writePowerConstantToProto(proto, POWER_CPU_SUSPEND, PowerProfileProto.CPU_SUSPEND);

        // cpu.idle
        writePowerConstantToProto(proto, POWER_CPU_IDLE, PowerProfileProto.CPU_IDLE);

        // cpu.active
        writePowerConstantToProto(proto, POWER_CPU_ACTIVE, PowerProfileProto.CPU_ACTIVE);

        // cpu.clusters.cores
        // cpu.cluster_power.cluster
        // cpu.core_speeds.cluster
        // cpu.core_power.cluster
        for (int cluster = 0; cluster < mCpuClusters.length; cluster++) {
            final long token = proto.start(PowerProfileProto.CPU_CLUSTER);
            proto.write(PowerProfileProto.CpuCluster.ID, cluster);
            proto.write(PowerProfileProto.CpuCluster.CLUSTER_POWER,
                    sPowerItemMap.get(mCpuClusters[cluster].clusterPowerKey));
            proto.write(PowerProfileProto.CpuCluster.CORES, mCpuClusters[cluster].numCpus);
            for (Double speed : sPowerArrayMap.get(mCpuClusters[cluster].freqKey)) {
                proto.write(PowerProfileProto.CpuCluster.SPEED, speed);
            }
            for (Double corePower : sPowerArrayMap.get(mCpuClusters[cluster].corePowerKey)) {
                proto.write(PowerProfileProto.CpuCluster.CORE_POWER, corePower);
            }
            proto.end(token);
        }

        // wifi.scan
        writePowerConstantToProto(proto, POWER_WIFI_SCAN, PowerProfileProto.WIFI_SCAN);

        // wifi.on
        writePowerConstantToProto(proto, POWER_WIFI_ON, PowerProfileProto.WIFI_ON);

        // wifi.active
        writePowerConstantToProto(proto, POWER_WIFI_ACTIVE, PowerProfileProto.WIFI_ACTIVE);

        // wifi.controller.idle
        writePowerConstantToProto(proto, POWER_WIFI_CONTROLLER_IDLE,
                PowerProfileProto.WIFI_CONTROLLER_IDLE);

        // wifi.controller.rx
        writePowerConstantToProto(proto, POWER_WIFI_CONTROLLER_RX,
                PowerProfileProto.WIFI_CONTROLLER_RX);

        // wifi.controller.tx
        writePowerConstantToProto(proto, POWER_WIFI_CONTROLLER_TX,
                PowerProfileProto.WIFI_CONTROLLER_TX);

        // wifi.controller.tx_levels
        writePowerConstantArrayToProto(proto, POWER_WIFI_CONTROLLER_TX_LEVELS,
                PowerProfileProto.WIFI_CONTROLLER_TX_LEVELS);

        // wifi.controller.voltage
        writePowerConstantToProto(proto, POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE,
                PowerProfileProto.WIFI_CONTROLLER_OPERATING_VOLTAGE);

        // bluetooth.controller.idle
        writePowerConstantToProto(proto, POWER_BLUETOOTH_CONTROLLER_IDLE,
                PowerProfileProto.BLUETOOTH_CONTROLLER_IDLE);

        // bluetooth.controller.rx
        writePowerConstantToProto(proto, POWER_BLUETOOTH_CONTROLLER_RX,
                PowerProfileProto.BLUETOOTH_CONTROLLER_RX);

        // bluetooth.controller.tx
        writePowerConstantToProto(proto, POWER_BLUETOOTH_CONTROLLER_TX,
                PowerProfileProto.BLUETOOTH_CONTROLLER_TX);

        // bluetooth.controller.voltage
        writePowerConstantToProto(proto, POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE,
                PowerProfileProto.BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE);

        // modem.controller.sleep
        writePowerConstantToProto(proto, POWER_MODEM_CONTROLLER_SLEEP,
                PowerProfileProto.MODEM_CONTROLLER_SLEEP);

        // modem.controller.idle
        writePowerConstantToProto(proto, POWER_MODEM_CONTROLLER_IDLE,
                PowerProfileProto.MODEM_CONTROLLER_IDLE);

        // modem.controller.rx
        writePowerConstantToProto(proto, POWER_MODEM_CONTROLLER_RX,
                PowerProfileProto.MODEM_CONTROLLER_RX);

        // modem.controller.tx
        writePowerConstantArrayToProto(proto, POWER_MODEM_CONTROLLER_TX,
                PowerProfileProto.MODEM_CONTROLLER_TX);

        // modem.controller.voltage
        writePowerConstantToProto(proto, POWER_MODEM_CONTROLLER_OPERATING_VOLTAGE,
                PowerProfileProto.MODEM_CONTROLLER_OPERATING_VOLTAGE);

        // gps.on
        writePowerConstantToProto(proto, POWER_GPS_ON, PowerProfileProto.GPS_ON);

        // gps.signalqualitybased
        writePowerConstantArrayToProto(proto, POWER_GPS_SIGNAL_QUALITY_BASED,
                PowerProfileProto.GPS_SIGNAL_QUALITY_BASED);

        // gps.voltage
        writePowerConstantToProto(proto, POWER_GPS_OPERATING_VOLTAGE,
                PowerProfileProto.GPS_OPERATING_VOLTAGE);

        // bluetooth.on
        writePowerConstantToProto(proto, POWER_BLUETOOTH_ON, PowerProfileProto.BLUETOOTH_ON);

        // bluetooth.active
        writePowerConstantToProto(proto, POWER_BLUETOOTH_ACTIVE,
                PowerProfileProto.BLUETOOTH_ACTIVE);

        // bluetooth.at
        writePowerConstantToProto(proto, POWER_BLUETOOTH_AT_CMD,
                PowerProfileProto.BLUETOOTH_AT_CMD);

        // ambient.on
        writePowerConstantToProto(proto, POWER_AMBIENT_DISPLAY, PowerProfileProto.AMBIENT_DISPLAY);

        // screen.on
        writePowerConstantToProto(proto, POWER_SCREEN_ON, PowerProfileProto.SCREEN_ON);

        // radio.on
        writePowerConstantToProto(proto, POWER_RADIO_ON, PowerProfileProto.RADIO_ON);

        // radio.scanning
        writePowerConstantToProto(proto, POWER_RADIO_SCANNING, PowerProfileProto.RADIO_SCANNING);

        // radio.active
        writePowerConstantToProto(proto, POWER_RADIO_ACTIVE, PowerProfileProto.RADIO_ACTIVE);

        // screen.full
        writePowerConstantToProto(proto, POWER_SCREEN_FULL, PowerProfileProto.SCREEN_FULL);

        // audio
        writePowerConstantToProto(proto, POWER_AUDIO, PowerProfileProto.AUDIO);

        // video
        writePowerConstantToProto(proto, POWER_VIDEO, PowerProfileProto.VIDEO);

        // camera.flashlight
        writePowerConstantToProto(proto, POWER_FLASHLIGHT, PowerProfileProto.FLASHLIGHT);

        // memory.bandwidths
        writePowerConstantToProto(proto, POWER_MEMORY, PowerProfileProto.MEMORY);

        // camera.avg
        writePowerConstantToProto(proto, POWER_CAMERA, PowerProfileProto.CAMERA);

        // wifi.batchedscan
        writePowerConstantToProto(proto, POWER_WIFI_BATCHED_SCAN,
                PowerProfileProto.WIFI_BATCHED_SCAN);

        // battery.capacity
        writePowerConstantToProto(proto, POWER_BATTERY_CAPACITY,
                PowerProfileProto.BATTERY_CAPACITY);
    }

    // Writes items in sPowerItemMap to proto if exists.
    private void writePowerConstantToProto(ProtoOutputStream proto, String key, long fieldId) {
        if (sPowerItemMap.containsKey(key)) {
            proto.write(fieldId, sPowerItemMap.get(key));
        }
    }

    // Writes items in sPowerArrayMap to proto if exists.
    private void writePowerConstantArrayToProto(ProtoOutputStream proto, String key, long fieldId) {
        if (sPowerArrayMap.containsKey(key)) {
            for (Double d : sPowerArrayMap.get(key)) {
                proto.write(fieldId, d);
            }
        }
    }
}
Loading