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 INT, 22 -- Counter value. 23 value INT, 24 -- Counter duration. 25 dur INT 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 ( 37 'domain@0 Frequency', 38 'domain@1 Frequency', 39 'domain@2 Frequency', 40 '17000010.devfreq_mif Frequency', 41 '17000020.devfreq_int Frequency', 42 '17000090.devfreq_dsu Frequency', 43 '170000a0.devfreq_bci Frequency', 44 'dsu_throughput Frequency', 45 'bus_throughput Frequency', 46 'cpu0dsu Frequency', 47 'cpu1dsu Frequency', 48 'cpu2dsu Frequency', 49 'cpu3dsu Frequency', 50 'cpu4dsu Frequency', 51 'cpu5dsu Frequency', 52 'cpu6dsu Frequency', 53 'cpu7dsu Frequency', 54 'cpu8dsu Frequency', 55 'gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010 Frequency', 56 'gs_memlat_devfreq:devfreq_mif_cpu1_memlat@17000010 Frequency', 57 'gs_memlat_devfreq:devfreq_mif_cpu2_memlat@17000010 Frequency', 58 'gs_memlat_devfreq:devfreq_mif_cpu3_memlat@17000010 Frequency', 59 'gs_memlat_devfreq:devfreq_mif_cpu4_memlat@17000010 Frequency', 60 'gs_memlat_devfreq:devfreq_mif_cpu5_memlat@17000010 Frequency', 61 'gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010 Frequency', 62 'gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010 Frequency', 63 'gs_memlat_devfreq:devfreq_mif_cpu8_memlat@17000010 Frequency') 64ORDER BY ts; 65 66-- Aggregates dvfs counter slice for statistic. 67CREATE PERFETTO TABLE android_dvfs_counter_stats( 68 -- Counter name on which all the other values are aggregated on. 69 name STRING, 70 -- Max of all counter values for the counter name. 71 max INT, 72 -- Min of all counter values for the counter name. 73 min INT, 74 -- Duration between the first and last counter value for the counter name. 75 dur INT, 76 -- Weighted avergate of all the counter values for the counter name. 77 wgt_avg FLOAT 78) AS 79SELECT 80 name, 81 MAX(value) AS max, 82 MIN(value) AS min, 83 (MAX(ts) - MIN(ts)) AS dur, 84 (SUM(dur * value) / SUM(dur)) AS wgt_avg 85FROM android_dvfs_counters 86WHERE android_dvfs_counters.dur > 0 87GROUP BY name; 88 89 90-- Aggregates dvfs counter slice for residency 91CREATE PERFETTO VIEW android_dvfs_counter_residency( 92 -- Counter name. 93 name STRING, 94 -- Counter value. 95 value INT, 96 -- Counter duration. 97 dur INT, 98 -- Counter duration as a percentage of total duration. 99 pct FLOAT 100) AS 101WITH 102total AS ( 103 SELECT 104 name, 105 SUM(dur) AS dur 106 FROM android_dvfs_counters 107 WHERE dur > 0 108 GROUP BY name 109) 110SELECT 111 android_dvfs_counters.name, 112 android_dvfs_counters.value, 113 SUM(android_dvfs_counters.dur) AS dur, 114 (SUM(android_dvfs_counters.dur) * 100.0 / total.dur) AS pct 115FROM android_dvfs_counters 116JOIN total 117 USING (name) 118WHERE android_dvfs_counters.dur > 0 119GROUP BY 1, 2; 120