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 16-- Create the base table (`android_jank_cuj`) containing all completed CUJs 17-- found in the trace. 18SELECT RUN_METRIC('android/jank/cujs.sql'); 19 20-- Creates tables that store constant parameters for each CUJ - e.g. parameter 21-- that describes whether Choreographer callbacks run on a dedicated thread. 22SELECT RUN_METRIC('android/jank/params.sql'); 23 24-- Create tables to store each CUJs main, render, HWC release, 25-- and GPU completion threads. 26-- Also stores the (not CUJ-specific) threads of SF: main, render engine, 27-- and GPU completion threads. 28SELECT RUN_METRIC('android/jank/relevant_threads.sql'); 29 30-- Create tables to store the main slices on each of the relevant threads 31-- * `Choreographer#doFrame` on the main thread 32-- * `DrawFrames on the render` thread 33-- * `waiting for HWC release` on the HWC release thread 34-- * `Waiting for GPU completion` on the GPU completion thread 35-- * `commit` and `composite` on SF main thread. 36-- * `REThreaded::drawLayers` on SF RenderEngine thread. 37-- Also extracts vsync ids and GPU completion fence ids that allow us to match 38-- slices to concrete vsync IDs. 39-- Slices and vsyncs are matched between the app and SF processes by looking 40-- at the actual frame timeline data. 41-- We only store the slices that were produced for the vsyncs within the 42-- CUJ markers. 43SELECT RUN_METRIC('android/jank/relevant_slices.sql'); 44 45-- Computes the boundaries of specific frames and overall CUJ boundaries 46-- on specific important threads since each thread will work on a frame at a 47-- slightly different time. 48-- We also compute the corrected CUJ ts boundaries. This is necessary because 49-- the instrumentation logs begin/end CUJ markers *during* the first frame and 50-- typically *right at the start* of the last CUJ frame. The ts boundaries in 51-- `android_jank_cuj` table are based on these markers so do not actually 52-- contain the whole CUJ, but instead overlap with all Choreographer#doFrame 53-- slices that belong to a CUJ. 54SELECT RUN_METRIC('android/jank/cujs_boundaries.sql'); 55 56-- With relevant slices and corrected boundaries we can now estimate the ts 57-- boundaries of each frame within the CUJ. 58-- We also match with the data from the actual timeline to check which frames 59-- missed the deadline and whether this was due to the app or SF. 60SELECT RUN_METRIC('android/jank/frames.sql'); 61 62-- Creates tables with slices from various relevant threads that are within 63-- the CUJ boundaries. Used as data sources for further processing and 64-- jank cause analysis of traces. 65SELECT RUN_METRIC('android/jank/slices.sql'); 66 67-- Creates tables and functions to be used for manual investigations and 68-- jank cause analysis of traces. 69SELECT RUN_METRIC('android/jank/internal/query_base.sql'); 70SELECT RUN_METRIC('android/jank/query_functions.sql'); 71 72-- Creates a table that matches CUJ counters with the correct CUJs. 73-- After the CUJ ends FrameTracker emits counters with the number of total 74-- frames, missed frames, longest frame duration, etc. 75-- The same numbers are also reported by FrameTracker to statsd. 76SELECT RUN_METRIC('android/jank/internal/counters.sql'); 77 78DROP VIEW IF EXISTS android_jank_cuj_output; 79CREATE PERFETTO VIEW android_jank_cuj_output AS 80SELECT 81 AndroidJankCujMetric( 82 'cuj', ( 83 SELECT RepeatedField( 84 AndroidJankCujMetric_Cuj( 85 'id', cuj_id, 86 'name', cuj_name, 87 'process', process_metadata, 88 'layer_name', layer_name, 89 'ts', COALESCE(boundary.ts, cuj.ts), 90 'dur', COALESCE(boundary.dur, cuj.dur), 91 'counter_metrics', ( 92 SELECT AndroidJankCujMetric_Metrics( 93 'total_frames', total_frames, 94 'missed_frames', missed_frames, 95 'missed_app_frames', missed_app_frames, 96 'missed_sf_frames', missed_sf_frames, 97 'missed_frames_max_successive', missed_frames_max_successive, 98 'sf_callback_missed_frames', sf_callback_missed_frames, 99 'hwui_callback_missed_frames', hwui_callback_missed_frames, 100 'frame_dur_max', frame_dur_max) 101 FROM android_jank_cuj_counter_metrics cm 102 WHERE cm.cuj_id = cuj.cuj_id), 103 'trace_metrics', ( 104 SELECT AndroidJankCujMetric_Metrics( 105 'total_frames', COUNT(*), 106 'missed_frames', SUM(app_missed OR sf_missed), 107 'missed_app_frames', SUM(app_missed), 108 'missed_sf_frames', SUM(sf_missed), 109 'sf_callback_missed_frames', SUM(sf_callback_missed), 110 'hwui_callback_missed_frames', SUM(hwui_callback_missed), 111 'frame_dur_max', MAX(f.dur), 112 'frame_dur_avg', CAST(AVG(f.dur) AS INTEGER), 113 'frame_dur_p50', CAST(PERCENTILE(f.dur, 50) AS INTEGER), 114 'frame_dur_p90', CAST(PERCENTILE(f.dur, 90) AS INTEGER), 115 'frame_dur_p95', CAST(PERCENTILE(f.dur, 95) AS INTEGER), 116 'frame_dur_p99', CAST(PERCENTILE(f.dur, 99) AS INTEGER), 117 'frame_dur_ms_p50', PERCENTILE(f.dur / 1e6, 50), 118 'frame_dur_ms_p90', PERCENTILE(f.dur / 1e6, 90), 119 'frame_dur_ms_p95', PERCENTILE(f.dur / 1e6, 95), 120 'frame_dur_ms_p99', PERCENTILE(f.dur / 1e6, 99)) 121 FROM android_jank_cuj_frame f 122 WHERE f.cuj_id = cuj.cuj_id), 123 'timeline_metrics', ( 124 SELECT AndroidJankCujMetric_Metrics( 125 'total_frames', COUNT(*), 126 'missed_frames', SUM(app_missed OR sf_missed), 127 'missed_app_frames', SUM(app_missed), 128 'missed_sf_frames', SUM(sf_missed), 129 'sf_callback_missed_frames', SUM(sf_callback_missed), 130 'hwui_callback_missed_frames', SUM(hwui_callback_missed), 131 'frame_dur_max', MAX(f.dur), 132 'frame_dur_avg', CAST(AVG(f.dur) AS INTEGER), 133 'frame_dur_p50', CAST(PERCENTILE(f.dur, 50) AS INTEGER), 134 'frame_dur_p90', CAST(PERCENTILE(f.dur, 90) AS INTEGER), 135 'frame_dur_p95', CAST(PERCENTILE(f.dur, 95) AS INTEGER), 136 'frame_dur_p99', CAST(PERCENTILE(f.dur, 99) AS INTEGER), 137 'frame_dur_ms_p50', PERCENTILE(f.dur / 1e6, 50), 138 'frame_dur_ms_p90', PERCENTILE(f.dur / 1e6, 90), 139 'frame_dur_ms_p95', PERCENTILE(f.dur / 1e6, 95), 140 'frame_dur_ms_p99', PERCENTILE(f.dur / 1e6, 99)) 141 FROM android_jank_cuj_frame_timeline f 142 WHERE f.cuj_id = cuj.cuj_id), 143 'frame', ( 144 SELECT RepeatedField( 145 AndroidJankCujMetric_Frame( 146 'frame_number', f.frame_number, 147 'vsync', f.vsync, 148 'ts', f.ts, 149 'dur', f.dur, 150 'dur_expected', f.dur_expected, 151 'app_missed', f.app_missed, 152 'sf_missed', f.sf_missed, 153 'sf_callback_missed', f.sf_callback_missed, 154 'hwui_callback_missed', f.hwui_callback_missed)) 155 FROM android_jank_cuj_frame f 156 WHERE f.cuj_id = cuj.cuj_id 157 ORDER BY frame_number ASC), 158 'sf_frame', ( 159 SELECT RepeatedField( 160 AndroidJankCujMetric_Frame( 161 'frame_number', f.frame_number, 162 'vsync', f.vsync, 163 'ts', f.ts, 164 'dur', f.dur, 165 'dur_expected', f.dur_expected, 166 'sf_missed', f.sf_missed)) 167 FROM android_jank_cuj_sf_frame f 168 WHERE f.cuj_id = cuj.cuj_id 169 ORDER BY frame_number ASC) 170 )) 171 FROM android_jank_cuj cuj 172 LEFT JOIN android_jank_cuj_boundary boundary USING (cuj_id) 173 LEFT JOIN android_jank_cuj_layer_name cuj_layer USING (cuj_id) 174 ORDER BY cuj.cuj_id ASC)); 175