Power data sources

On Android Perfetto bundles data sources to retrieve power counters from the device power management units (where supported).

Battery counters

This data source has been introduced in Android 10 (Q) and requires the presence of power-management hardware on the device. This is available on most Google Pixel smartphones.

Modern smartphones are equipped with a power monitoring IC which is able to measure the charge flowing in and out of the battery. This allows Perfetto to observe the total and instantaneous charge drained from the battery by the overall device (the union of SoC, display, radios and all other hardware units).

A simplified block diagram:

These counters report:

The presence and the resolution of these counters depends on the device manufacturer. At the platform level this data is obtained polling the Android IHealth HAL. For more details on HW specs and resolution see Measuring Device Power.

Measuring charge while plugged on USB

Battery counters measure the charge flowing in and out of the battery. If the device is plugged to a USB cable, you will likely observe a positive instantaneous current and an increase of the total charge, denoting the fact that charge is flowing in the battery (i.e. charging it) rather than out.

This can make measurements in lab settings problematic. The known workarounds for this are:

UI

SQL

select ts, t.name, value from counter as c left join counter_track t on c.track_id = t.id
ts name value
338297039804951 batt.charge_uah 2085000
338297039804951 batt.capacity_pct 75
338297039804951 batt.current_ua -1469687
338297145212097 batt.charge_uah 2085000
338297145212097 batt.capacity_pct 75
338297145212097 batt.current_ua -1434062

TraceConfig

Trace proto: BatteryCounters

Config proto: AndroidPowerConfig

Sample config (Android):

data_sources: { config { name: "android.power" android_power_config { battery_poll_ms: 250 battery_counters: BATTERY_COUNTER_CAPACITY_PERCENT battery_counters: BATTERY_COUNTER_CHARGE battery_counters: BATTERY_COUNTER_CURRENT battery_counters: BATTERY_COUNTER_VOLTAGE } } }

Sample Config (Chrome OS or Linux):

data_sources: { config { name: "linux.sysfs_power" } }

On-Device Power Rails Monitor (ODPM)

This data source has been introduced in Android 10 (Q) and requires the dedicated hardware on the device. This hardware is not yet available on most production phones.

Recent version of Android introduced the support for more advanced power monitoring at the hardware subsystem level, known as "On-Device Power Rail Monitors" (ODPMs). These counters measure the energy drained by (groups of) hardware units.

Unlike the battery counters, they are not affected by the charging/discharging state of the battery, because they measure power downstream of the battery.

The presence and the resolution of power rail counters depends on the device manufacturer. At the platform level this data is obtained polling the Android IPowerStats HAL.

Googlers: See go/power-rails-internal-doc for instructions on how to change the default rail selection on Pixel devices.

Simplified block diagram:

TraceConfig

Trace proto: PowerRails

Config proto: AndroidPowerConfig

Sample config:

data_sources: { config { name: "android.power" android_power_config { battery_poll_ms: 250 collect_power_rails: true # Note: it is possible to specify both rails and battery counters # in this section. } } }

Related data sources

See also the CPU -> Frequency scaling data source.