1-- 2-- Copyright 2023 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-- Dvfs counter with duration. 17CREATE PERFETTO VIEW android_dvfs_counters ( 18 -- Counter name. 19 name STRING, 20 -- Timestamp when counter value changed. 21 ts TIMESTAMP, 22 -- Counter value. 23 value DOUBLE, 24 -- Counter duration. 25 dur DURATION 26) AS 27SELECT 28 counter_track.name, 29 counter.ts, 30 counter.value, 31 lead(counter.ts, 1, trace_end()) OVER (PARTITION BY counter_track.id ORDER BY counter.ts) - counter.ts AS dur 32FROM counter 33JOIN counter_track 34 ON counter.track_id = counter_track.id 35WHERE 36 counter_track.name IN ('domain@0 Frequency', 'domain@1 Frequency', 'domain@2 Frequency', '17000010.devfreq_mif Frequency', '17000020.devfreq_int Frequency', '17000090.devfreq_dsu Frequency', '170000a0.devfreq_bci Frequency', 'dsu_throughput Frequency', 'bus_throughput Frequency', 'cpu0dsu Frequency', 'cpu1dsu Frequency', 'cpu2dsu Frequency', 'cpu3dsu Frequency', 'cpu4dsu Frequency', 'cpu5dsu Frequency', 'cpu6dsu Frequency', 'cpu7dsu Frequency', 'cpu8dsu Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010 Frequency', 'gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010 Frequency') 37ORDER BY 38 ts; 39 40-- Aggregates dvfs counter slice for statistic. 41CREATE PERFETTO TABLE android_dvfs_counter_stats ( 42 -- Counter name on which all the other values are aggregated on. 43 name STRING, 44 -- Max of all counter values for the counter name. 45 max DOUBLE, 46 -- Min of all counter values for the counter name. 47 min DOUBLE, 48 -- Duration between the first and last counter value for the counter name. 49 dur DURATION, 50 -- Weighted avergate of all the counter values for the counter name. 51 wgt_avg DOUBLE 52) AS 53SELECT 54 name, 55 max(value) AS max, 56 min(value) AS min, 57 ( 58 max(ts) - min(ts) 59 ) AS dur, 60 ( 61 sum(dur * value) / sum(dur) 62 ) AS wgt_avg 63FROM android_dvfs_counters 64WHERE 65 android_dvfs_counters.dur > 0 66GROUP BY 67 name; 68 69-- Aggregates dvfs counter slice for residency 70CREATE PERFETTO VIEW android_dvfs_counter_residency ( 71 -- Counter name. 72 name STRING, 73 -- Counter value. 74 value DOUBLE, 75 -- Counter duration. 76 dur DURATION, 77 -- Counter duration as a percentage of total duration. 78 pct DOUBLE 79) AS 80WITH 81 total AS ( 82 SELECT 83 name, 84 sum(dur) AS dur 85 FROM android_dvfs_counters 86 WHERE 87 dur > 0 88 GROUP BY 89 name 90 ) 91SELECT 92 android_dvfs_counters.name, 93 android_dvfs_counters.value, 94 sum(android_dvfs_counters.dur) AS dur, 95 ( 96 sum(android_dvfs_counters.dur) * 100.0 / total.dur 97 ) AS pct 98FROM android_dvfs_counters 99JOIN total 100 USING (name) 101WHERE 102 android_dvfs_counters.dur > 0 103GROUP BY 104 1, 105 2; 106