• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2021 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
16DROP VIEW IF EXISTS freq_slice;
17
18CREATE VIEW freq_slice AS
19  SELECT
20    counter.track_id AS track_id,
21    track.name AS freq_name,
22    ts,
23    value AS freq_value,
24    LEAD(ts, 1, (SELECT end_ts+1 FROM trace_bounds))
25      OVER (PARTITION by track.id ORDER BY ts)  - ts AS duration
26  FROM counter
27  LEFT JOIN track ON counter.track_id = track.id
28  WHERE track.name GLOB "* Frequency"
29  ORDER BY ts;
30
31DROP VIEW IF EXISTS freq_total_duration;
32
33CREATE VIEW freq_total_duration AS
34  SELECT
35    track_id,
36    freq_name,
37    SUM(duration) AS total_duration
38  FROM freq_slice
39  WHERE duration > 0
40  GROUP BY track_id, freq_name;
41
42DROP VIEW IF EXISTS dvfs_per_band_view;
43
44CREATE VIEW dvfs_per_band_view AS
45WITH
46freq_duration AS (
47  SELECT
48    track_id,
49    freq_name,
50    CAST(freq_value AS int) AS freq_value,
51    SUM(duration) AS duration_ns
52  FROM freq_slice
53  WHERE duration > 0
54  GROUP BY track_id, freq_name, freq_value
55)
56SELECT
57  freq_duration.track_id,
58  freq_duration.freq_name,
59  AndroidDvfsMetric_BandStat(
60     'freq_value', freq_value,
61     'percentage', duration_ns / (total_duration / 1e2),
62     'duration_ns', duration_ns
63  ) AS proto
64FROM freq_duration
65LEFT JOIN freq_total_duration
66USING(track_id)
67ORDER BY freq_duration.freq_name, freq_duration.freq_value;
68
69DROP VIEW IF EXISTS dvfs_per_freq_view;
70CREATE VIEW dvfs_per_freq_view AS
71  SELECT
72    AndroidDvfsMetric_FrequencyResidency(
73      'freq_name', freq_total_duration.freq_name,
74      'band_stat', (
75        SELECT
76          RepeatedField(proto)
77        FROM dvfs_per_band_view
78        WHERE dvfs_per_band_view.track_id = freq_total_duration.track_id
79      )
80    ) AS proto
81  FROM freq_total_duration
82  GROUP BY track_id, freq_name
83  ORDER BY freq_name;
84
85DROP VIEW IF EXISTS android_dvfs_output;
86CREATE VIEW android_dvfs_output AS
87  SELECT AndroidDVFSMetric(
88    'freq_residencies', (
89      SELECT
90        RepeatedField(proto)
91      FROM dvfs_per_freq_view
92    )
93  );
94