aboutsummaryrefslogtreecommitdiff
path: root/src/trace_processor/metrics/android/android_powrails.sql
blob: d05324af05e1c47a3ca7c10e75820c2d3f3d8989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--
-- Copyright 2019 The Android Open Source Project
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

-- View of Power Rail counters with ts converted from ns to ms.
DROP VIEW IF EXISTS power_rails_counters;
CREATE VIEW power_rails_counters AS
SELECT value, ts/1000000 AS ts, name
FROM counter c
JOIN counter_track t on c.track_id = t.id
WHERE name LIKE 'power.%';

DROP VIEW IF EXISTS power_rails_view;
CREATE VIEW power_rails_view AS
WITH RECURSIVE name AS (SELECT DISTINCT name FROM power_rails_counters)
SELECT
  name,
  ts,
  AndroidPowerRails_PowerRails(
    'name', name,
    'energy_data', RepeatedField(
      AndroidPowerRails_EnergyData(
        'timestamp_ms', ts,
        'energy_uws', value
      )
    )
  ) AS power_rails_proto
FROM power_rails_counters
GROUP BY name
ORDER BY ts ASC;

DROP VIEW IF EXISTS android_powrails_output;
CREATE VIEW android_powrails_output AS
SELECT AndroidPowerRails(
  'power_rails', (
    SELECT RepeatedField(power_rails_proto)
    FROM power_rails_view
  )
);