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 17INCLUDE PERFETTO MODULE android.monitor_contention; 18 19DROP VIEW IF EXISTS amc_process_agg; 20CREATE PERFETTO VIEW amc_process_agg AS 21WITH full_contention AS ( 22 Select process_name, COUNT(*) as total_contention_count, SUM(dur) 23 as total_contention_dur from android_monitor_contention group by process_name 24), 25main_thread_contention AS 26( 27 Select process_name, COUNT(*) as main_thread_contention_count, SUM(dur) 28 as main_thread_contention_dur from android_monitor_contention 29 where is_blocked_thread_main=1 group by process_name 30) 31SELECT f.process_name, total_contention_count, total_contention_dur, 32 main_thread_contention_count, main_thread_contention_dur 33 from full_contention as f left join main_thread_contention as m on f.process_name = m.process_name; 34 35DROP VIEW IF EXISTS android_monitor_contention_agg_output; 36CREATE PERFETTO VIEW android_monitor_contention_agg_output AS 37SELECT AndroidMonitorContentionAggMetric( 38 'process_aggregation', ( 39 SELECT RepeatedField( 40 AndroidMonitorContentionAggMetric_ProcessAggregation( 41 'name', process_name, 42 'total_contention_count', total_contention_count, 43 'total_contention_dur', total_contention_dur, 44 'main_thread_contention_count', main_thread_contention_count, 45 'main_thread_contention_dur', main_thread_contention_dur 46 ) 47 ) 48 FROM amc_process_agg 49 ) 50);