• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16-- The start of the launching event corresponds to the end of the AM handling
17-- the startActivity intent, whereas the end corresponds to the first frame drawn.
18-- Only successful app launches have a launching event.
19DROP TABLE IF EXISTS launching_events;
20CREATE TABLE launching_events AS
21SELECT
22  ts,
23  dur,
24  ts + dur AS ts_end,
25  STR_SPLIT(s.name, ": ", 1) AS package_name
26FROM slice s
27JOIN process_track t ON s.track_id = t.id
28JOIN process USING(upid)
29WHERE s.name GLOB 'launching: *'
30AND (process.name IS NULL OR process.name = 'system_server');
31
32SELECT CREATE_FUNCTION(
33  'SLICE_COUNT(slice_glob STRING)',
34  'INT',
35  'SELECT COUNT(1) FROM slice WHERE name GLOB $slice_glob'
36);
37
38-- All activity launches in the trace, keyed by ID.
39-- Populated by different scripts depending on the platform version / contents.
40-- See android/startup/launches*.sql
41DROP TABLE IF EXISTS launches;
42CREATE TABLE launches(
43  id INTEGER PRIMARY KEY,
44  ts BIG INT,
45  ts_end BIG INT,
46  dur BIG INT,
47  package STRING
48);
49
50-- Note: on Q, we didn't have Android fingerprints but we *did*
51-- have ActivityMetricsLogger events so we will use this approach
52-- if we see any such events.
53SELECT CASE
54  WHEN SLICE_COUNT('launchingActivity#*:*') > 0
55    THEN RUN_METRIC('android/startup/launches_minsdk33.sql')
56  WHEN SLICE_COUNT('MetricsLogger:*') > 0
57    THEN RUN_METRIC('android/startup/launches_minsdk29.sql')
58  ELSE RUN_METRIC('android/startup/launches_maxsdk28.sql')
59END;
60
61-- Maps a launch to the corresponding set of processes that handled the
62-- activity start. The vast majority of cases should be a single process.
63-- However it is possible that the process dies during the activity launch
64-- and is respawned.
65DROP TABLE IF EXISTS launch_processes;
66CREATE TABLE launch_processes(launch_id INT, upid BIG INT, launch_type STRING);
67
68SELECT CREATE_FUNCTION(
69  'STARTUP_SLICE_COUNT(start_ts LONG, end_ts LONG, utid INT, name STRING)',
70  'INT',
71  '
72    SELECT COUNT(1)
73    FROM thread_track t
74    JOIN slice s ON s.track_id = t.id
75    WHERE
76      t.utid = $utid AND
77      s.ts >= $start_ts AND
78      s.ts < $end_ts AND
79      s.name = $name
80  '
81);
82
83INSERT INTO launch_processes(launch_id, upid, launch_type)
84SELECT
85  l.id AS launch_id,
86  p.upid,
87  CASE
88    WHEN STARTUP_SLICE_COUNT(l.ts, l.ts_end, t.utid, 'bindApplication') > 0
89      THEN 'cold'
90    WHEN STARTUP_SLICE_COUNT(l.ts, l.ts_end, t.utid, 'activityStart') > 0
91      THEN 'warm'
92    WHEN STARTUP_SLICE_COUNT(l.ts, l.ts_end, t.utid, 'activityResume') > 0
93      THEN 'hot'
94    ELSE NULL
95  END AS launch_type
96FROM launches l
97LEFT JOIN package_list ON (l.package = package_list.package_name)
98JOIN process p ON (l.package = p.name OR p.uid = package_list.uid)
99JOIN thread t ON (p.upid = t.upid AND t.is_main_thread)
100WHERE launch_type IS NOT NULL;
101