• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15--
16
17INCLUDE PERFETTO MODULE counters.intervals;
18INCLUDE PERFETTO MODULE time.conversion;
19
20-- Android power rails counters data.
21-- For details see: https://perfetto.dev/docs/data-sources/battery-counters#odpm
22-- NOTE: Requires dedicated hardware - table is only populated on Pixels.
23CREATE PERFETTO TABLE android_power_rails_counters (
24    -- `counter.id`
25    id INT,
26    -- Timestamp of the energy measurement.
27    ts INT,
28    -- Time until the next energy measurement.
29    dur INT,
30    -- Power rail name. Alias of `counter_track.name`.
31    power_rail_name STRING,
32    -- Raw power rail name.
33    raw_power_rail_name STRING,
34    -- Energy accumulated by this rail since boot in microwatt-seconds
35    -- (uWs) (AKA micro-joules). Alias of `counter.value`.
36    energy_since_boot INT,
37    -- Energy accumulated by this rail at next energy measurement in
38    -- microwatt-seconds (uWs) (AKA micro-joules). Alias of `counter.value` of
39    -- the next meaningful (with value change) counter value.
40    energy_since_boot_at_end INT,
41    -- Average power in mW (milliwatts) over between ts and the next energy
42    -- measurement.
43    average_power DOUBLE,
44    -- The change of energy accumulated by this rails since the last
45    -- measurement in microwatt-seconds (uWs) (AKA micro-joules).
46    energy_delta DOUBLE,
47    -- Power rail track id. Alias of `counter_track.id`.
48    track_id INT,
49    -- DEPRECATED. Use `energy_since_boot` instead.
50    value DOUBLE
51) AS
52WITH counter_table AS (
53SELECT
54    c.*
55FROM counter c
56JOIN counter_track t ON c.track_id = t.id
57WHERE name GLOB 'power.*'
58)
59SELECT
60    c.id,
61    c.ts,
62    c.dur,
63    t.name AS power_rail_name,
64    EXTRACT_ARG(source_arg_set_id, 'raw_name') AS raw_power_rail_name,
65    c.value AS energy_since_boot,
66    c.next_value AS energy_since_boot_at_end,
67    1e3*(c.delta_value/(time_to_s(c.dur))) AS average_power,
68    c.delta_value AS energy_delta,
69    c.track_id,
70    c.value
71FROM counter_leading_intervals!(counter_table) c
72JOIN counter_track t ON c.track_id = t.id;
73