• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2019 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
17-- View of Power Rail counters with ts converted from ns to ms.
18DROP VIEW IF EXISTS power_rails_counters;
19CREATE VIEW power_rails_counters AS
20SELECT value, ts/1000000 AS ts, name
21FROM counter c
22JOIN counter_track t on c.track_id = t.id
23WHERE name GLOB 'power.*';
24
25DROP VIEW IF EXISTS avg_used_powers;
26CREATE VIEW avg_used_powers AS
27SELECT
28  name,
29  avg_used_power
30FROM (
31  SELECT
32    name,
33    (LEAD(value) OVER (PARTITION BY name ORDER BY ts) - value) /
34      (LEAD(ts) OVER (PARTITION BY name ORDER BY ts) - ts) AS avg_used_power
35  FROM (
36    SELECT name, MIN(ts) AS ts, value
37    FROM power_rails_counters
38    GROUP BY name
39    UNION
40    SELECT name, MAX(ts) AS ts, value
41    FROM power_rails_counters
42    GROUP BY name
43  )
44  ORDER BY name, ts
45) WHERE avg_used_power IS NOT NULL;
46
47DROP VIEW IF EXISTS power_rails_view;
48CREATE VIEW power_rails_view AS
49WITH RECURSIVE name AS (SELECT DISTINCT name FROM power_rails_counters)
50SELECT
51  name,
52  ts,
53  AndroidPowerRails_PowerRails(
54    'name', name,
55    'energy_data', RepeatedField(
56      AndroidPowerRails_EnergyData(
57        'timestamp_ms', ts,
58        'energy_uws', value
59      )
60    ),
61    'avg_used_power_mw', (SELECT avg_used_power FROM avg_used_powers
62        WHERE avg_used_powers.name = power_rails_counters.name)
63  ) AS power_rails_proto
64FROM power_rails_counters
65GROUP BY name
66ORDER BY ts ASC;
67
68DROP VIEW IF EXISTS android_powrails_output;
69CREATE VIEW android_powrails_output AS
70SELECT AndroidPowerRails(
71  'power_rails', (
72    SELECT RepeatedField(power_rails_proto)
73    FROM power_rails_view
74  )
75);
76