• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2022 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
16SELECT RUN_METRIC("android/android_cpu_agg.sql");
17
18DROP VIEW IF EXISTS p_state_cpu_idle_counter;
19CREATE VIEW p_state_cpu_idle_counter AS
20SELECT
21  ts,
22  ts - LAG(ts) OVER (
23    PARTITION BY track_id
24    ORDER BY
25      ts
26  ) AS dur,
27  cpu,
28  iif(value = 4294967295, -1, cast(value AS int)) AS idle_value
29FROM
30  counter c
31JOIN cpu_counter_track t ON c.track_id = t.id
32WHERE
33  t.name = "cpuidle";
34
35DROP TABLE IF EXISTS p_state_sched_freq_idle;
36CREATE VIRTUAL TABLE p_state_sched_freq_idle USING span_join(
37  cpu_freq_sched_per_thread PARTITIONED cpu,
38  p_state_cpu_idle_counter PARTITIONED cpu
39);
40
41SELECT
42  CREATE_VIEW_FUNCTION(
43    'P_STATE_OVER_INTERVAL(start_ns LONG, end_ns LONG)',
44    'cpu INT, freq_khz INT, idle_value INT, dur_ns INT',
45    '
46    WITH sched_freq_idle_windowed AS (
47      SELECT
48        freq_khz,
49        idle_value,
50        cpu,
51        IIF(ts + dur <= $end_ns, ts + dur, $end_ns) - IIF(ts >= $start_ns, ts, $start_ns) AS dur
52      FROM
53        p_state_sched_freq_idle
54      WHERE
55        ts + dur > $start_ns
56        AND ts < $end_ns
57    )
58    SELECT
59      cast(cpu AS int) AS cpu,
60      cast(freq_khz AS int) AS freq_khz,
61      cast(idle_value AS int) AS idle_value,
62      cast(sum(dur) AS int) AS dur_ns
63    FROM
64      sched_freq_idle_windowed
65    WHERE
66      freq_khz > 0
67    GROUP BY
68      cpu,
69      freq_khz,
70      idle_value
71  '
72  );
73