• 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
16
17-- Find all counters from track that satisfies regex 'slc/qurg2_(wr|rd):lvl=0x(0|1|3|7)%'
18DROP VIEW IF EXISTS all_qurg2;
19CREATE VIEW all_qurg2 AS
20SELECT
21  ts,
22  track_id,
23  name,
24  value
25FROM counters
26WHERE name GLOB 'slc/qurg2_??:lvl=0x_*';
27
28-- Find all counters from track that satisfies regex 'slc/qurg2_(wr|rd):lvl=0x(1|3|7)%'
29DROP VIEW IF EXISTS non_zero_qurg2;
30CREATE VIEW non_zero_qurg2 AS
31SELECT
32  *
33FROM all_qurg2
34WHERE name NOT GLOB 'slc/qurg2_??:lvl=0x0*';
35
36-- Find all event counters from simpleperf in the form of
37-- (<event_name> + '_tid' + <tid> + '_cpu' + <cpu_id>)
38DROP VIEW IF EXISTS simpleperf_event_raw;
39CREATE VIEW simpleperf_event_raw AS
40SELECT
41  SUBSTR(name, 0, tid_pos) AS name,
42  CAST(SUBSTR(name, tid_pos + 4, cpu_pos - tid_pos - 4) AS INT) AS tid,
43  CAST(SUBSTR(name, cpu_pos + 4) AS INT) AS cpu,
44  total
45FROM (
46  SELECT
47    name,
48    INSTR(name, '_tid') AS tid_pos,
49    INSTR(name, '_cpu') AS cpu_pos,
50    SUM(value) AS total
51  FROM counters
52  WHERE name GLOB '*_tid*_cpu*'
53  GROUP BY name
54);
55
56DROP VIEW IF EXISTS simpleperf_event_per_process;
57CREATE VIEW simpleperf_event_per_process AS
58SELECT
59  e.name,
60  t.upid,
61  RepeatedField(
62    AndroidSimpleperfMetric_PerfEventMetric_Thread(
63      'tid', e.tid,
64      'name', t.name,
65      'cpu', e.cpu,
66      'total', e.total
67    )
68  ) AS threads,
69  SUM(e.total) AS total
70FROM simpleperf_event_raw e JOIN thread t USING (tid)
71GROUP BY e.name, t.upid;
72
73
74DROP VIEW IF EXISTS simpleperf_event_metric;
75CREATE VIEW simpleperf_event_metric AS
76SELECT
77  AndroidSimpleperfMetric_PerfEventMetric(
78    'name', e.name,
79    'processes', RepeatedField(
80      AndroidSimpleperfMetric_PerfEventMetric_Process(
81        'pid', p.pid,
82        'name', p.name,
83        'threads', e.threads,
84        'total', e.total
85      )
86    ),
87    'total', SUM(total)
88  ) AS proto
89FROM simpleperf_event_per_process e JOIN process p USING (upid)
90GROUP BY e.name;
91
92DROP VIEW IF EXISTS android_simpleperf_output;
93CREATE VIEW android_simpleperf_output AS
94SELECT AndroidSimpleperfMetric(
95  'urgent_ratio', (SELECT sum(value) FROM non_zero_qurg2) / (SELECT sum(value) FROM all_qurg2),
96  'events', (SELECT RepeatedField(proto) FROM simpleperf_event_metric)
97);
98