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.startup.startup_events; 17 18-- Marks the beginning of the trace and is equivalent to when the statsd startup 19-- logging begins. 20CREATE PERFETTO VIEW _activity_intent_received AS 21SELECT ts FROM slice 22WHERE name = 'MetricsLogger:launchObserverNotifyIntentStarted'; 23 24-- We partition the trace into spans based on posted activity intents. 25-- We will refine these progressively in the next steps to only encompass 26-- activity starts. 27CREATE PERFETTO TABLE _activity_intent_recv_spans AS 28SELECT 29 ROW_NUMBER() 30 OVER(ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS startup_id, 31 ts, 32 LEAD(ts, 1, trace_end()) OVER(ORDER BY ts) - ts AS dur 33FROM _activity_intent_received 34ORDER BY ts; 35 36-- Filter activity_intent_recv_spans, keeping only the ones that triggered 37-- a startup. 38CREATE PERFETTO VIEW _startup_partitions AS 39SELECT * FROM _activity_intent_recv_spans AS spans 40WHERE 1 = ( 41 SELECT COUNT(1) 42 FROM _startup_events 43 WHERE _startup_events.ts BETWEEN spans.ts AND spans.ts + spans.dur); 44 45-- Successful activity startup. The end of the 'launching' event is not related 46-- to whether it actually succeeded or not. 47CREATE PERFETTO VIEW _activity_intent_startup_successful AS 48SELECT ts FROM slice 49WHERE name = 'MetricsLogger:launchObserverNotifyActivityLaunchFinished'; 50 51-- Use the starting event package name. The finish event package name 52-- is not reliable in the case of failed startups. 53CREATE PERFETTO TABLE _startups_minsdk29 AS 54SELECT 55 "minsdk29" as sdk, 56 lpart.startup_id, 57 lpart.ts, 58 le.ts_end, 59 le.ts_end - lpart.ts AS dur, 60 package_name AS package, 61 NULL AS startup_type 62FROM _startup_partitions AS lpart 63JOIN _startup_events le ON 64 (le.ts BETWEEN lpart.ts AND lpart.ts + lpart.dur) 65 AND (le.ts_end BETWEEN lpart.ts AND lpart.ts + lpart.dur) 66WHERE ( 67 SELECT COUNT(1) 68 FROM _activity_intent_startup_successful AS successful 69 WHERE successful.ts BETWEEN lpart.ts AND lpart.ts + lpart.dur 70) > 0; 71