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-- 16CREATE VIEW freq_view AS 17SELECT 18 ts, 19 lead(ts) OVER (PARTITION BY track_id ORDER BY ts) - ts AS dur, 20 cpu, 21 name AS freq_name, 22 value AS freq_value 23FROM counter 24JOIN cpu_counter_track 25 ON counter.track_id = cpu_counter_track.id 26WHERE name = 'cpufreq'; 27 28CREATE VIEW idle_view 29AS SELECT 30 ts, 31 lead(ts) OVER (PARTITION BY track_id ORDER BY ts) - ts AS dur, 32 cpu, 33 name AS idle_name, 34 value AS idle_value 35FROM counter 36JOIN cpu_counter_track 37 ON counter.track_id = cpu_counter_track.id 38WHERE name = 'cpuidle'; 39 40CREATE VIRTUAL TABLE freq_idle 41USING span_join(freq_view PARTITIONED cpu, idle_view PARTITIONED cpu); 42 43CREATE VIRTUAL TABLE window_freq_idle USING window; 44 45CREATE VIRTUAL TABLE span_freq_idle 46USING span_join(freq_idle PARTITIONED cpu, window_freq_idle); 47 48UPDATE window_freq_idle 49SET 50 window_start = (SELECT min(ts) FROM sched), 51 window_dur = (SELECT max(ts) - min(ts) FROM sched), 52 quantum = 1000000 53WHERE rowid = 0; 54 55CREATE VIEW counter_view 56AS SELECT 57 ts, 58 dur, 59 quantum_ts, 60 cpu, 61 CASE idle_value 62 WHEN 4294967295 THEN "freq" 63 ELSE "idle" 64 END AS name, 65 CASE idle_value 66 WHEN 4294967295 THEN freq_value 67 ELSE idle_value 68 END AS value 69FROM span_freq_idle; 70 71SELECT cpu, name, value, sum(dur) FROM counter_view GROUP BY cpu, name, value; 72