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 16INCLUDE PERFETTO MODULE android.frames.timeline; 17 18INCLUDE PERFETTO MODULE android.startup.startup_events; 19 20INCLUDE PERFETTO MODULE slices.with_context; 21 22CREATE PERFETTO TABLE _startups_maxsdk28 AS 23-- Warm and cold starts only are based on the launching slice 24WITH 25 warm_and_cold AS ( 26 SELECT 27 le.ts, 28 le.ts_end AS ts_end, 29 package_name AS package, 30 NULL AS startup_type 31 FROM _startup_events AS le 32 ), 33 -- Hot starts don’t have a launching slice so we use activityResume as a 34 -- proxy. 35 -- 36 -- Note that this implementation will also count warm and cold starts but 37 -- we will remove those below. 38 maybe_hot AS ( 39 SELECT 40 sl.ts, 41 rs.ts + rs.dur AS ts_end, 42 -- We use the process name as the package as we have no better option. 43 coalesce(process_name, thread_name, 'unknown') AS package, 44 "hot" AS startup_type 45 FROM thread_slice AS sl, android_first_frame_after(sl.ts) AS rs 46 WHERE 47 name = 'activityResume' 48 AND sl.is_main_thread 49 -- Remove any launches here where the activityResume slices happens during 50 -- a warm/cold startup. 51 AND NOT EXISTS( 52 SELECT 53 1 54 FROM warm_and_cold AS wac 55 WHERE 56 sl.ts BETWEEN wac.ts AND wac.ts_end 57 LIMIT 1 58 ) 59 ), 60 cold_warm_hot AS ( 61 SELECT 62 * 63 FROM warm_and_cold 64 UNION ALL 65 SELECT 66 * 67 FROM maybe_hot 68 ) 69SELECT 70 ts, 71 ts_end, 72 ts_end - ts AS dur, 73 package, 74 startup_type 75FROM cold_warm_hot 76ORDER BY 77 ts; 78