• 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;
18
19INCLUDE PERFETTO MODULE time.conversion;
20
21-- Android power rails counters data.
22-- For details see: https://perfetto.dev/docs/data-sources/battery-counters#odpm
23-- NOTE: Requires dedicated hardware - table is only populated on Pixels.
24CREATE PERFETTO TABLE android_power_rails_counters (
25  -- `counter.id`
26  id LONG,
27  -- Timestamp of the energy measurement.
28  ts TIMESTAMP,
29  -- Time until the next energy measurement.
30  dur DURATION,
31  -- Power rail name. Alias of `counter_track.name`.
32  power_rail_name STRING,
33  -- Raw power rail name.
34  raw_power_rail_name STRING,
35  -- Energy accumulated by this rail since boot in microwatt-seconds
36  -- (uWs) (AKA micro-joules). Alias of `counter.value`.
37  energy_since_boot DOUBLE,
38  -- Energy accumulated by this rail at next energy measurement in
39  -- microwatt-seconds (uWs) (AKA micro-joules). Alias of `counter.value` of
40  -- the next meaningful (with value change) counter value.
41  energy_since_boot_at_end DOUBLE,
42  -- Average power in mW (milliwatts) over between ts and the next energy
43  -- measurement.
44  average_power DOUBLE,
45  -- The change of energy accumulated by this rails since the last
46  -- measurement in microwatt-seconds (uWs) (AKA micro-joules).
47  energy_delta DOUBLE,
48  -- Power rail track id. Alias of `counter_track.id`.
49  track_id JOINID(track.id),
50  -- DEPRECATED. Use `energy_since_boot` instead.
51  value DOUBLE
52) AS
53WITH
54  counter_table AS (
55    SELECT
56      c.*
57    FROM counter AS c
58    JOIN counter_track AS t
59      ON c.track_id = t.id
60    WHERE
61      name GLOB 'power.*'
62  )
63SELECT
64  c.id,
65  c.ts,
66  c.dur,
67  t.name AS power_rail_name,
68  extract_arg(source_arg_set_id, 'raw_name') AS raw_power_rail_name,
69  c.value AS energy_since_boot,
70  c.next_value AS energy_since_boot_at_end,
71  1e6 * (
72    c.delta_value / c.dur
73  ) AS average_power,
74  c.delta_value AS energy_delta,
75  c.track_id,
76  c.value
77FROM counter_leading_intervals!(counter_table) AS c
78JOIN counter_track AS t
79  ON c.track_id = t.id;
80