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