• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2020 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
17INCLUDE PERFETTO MODULE android.startup.startups;
18
19-- Must be invoked after populating launches table in android_startup.
20DROP VIEW IF EXISTS functions;
21CREATE PERFETTO VIEW functions AS
22SELECT
23  slices.ts AS ts,
24  slices.dur AS dur,
25  process.name AS process_name,
26  thread.name AS thread_name,
27  slices.name AS function_name
28FROM slices
29JOIN thread_track ON slices.track_id = thread_track.id
30JOIN thread USING(utid)
31JOIN process USING(upid);
32
33-- Animators don't occur on threads, so add them here.
34DROP VIEW IF EXISTS animators;
35CREATE PERFETTO VIEW animators AS
36SELECT
37  slices.ts AS ts,
38  slices.dur AS dur,
39  thread.name AS process_name,
40  slices.name AS animator_name
41FROM slices
42JOIN process_track ON slices.track_id = process_track.id
43JOIN thread USING(upid)
44WHERE slices.name GLOB "animator*";
45
46DROP VIEW IF EXISTS android_frame_times;
47CREATE PERFETTO VIEW android_frame_times AS
48SELECT
49  functions.ts AS ts,
50  functions.ts + functions.dur AS ts_end,
51  launches.package AS name,
52  launches.startup_id,
53  ROW_NUMBER() OVER(PARTITION BY launches.startup_id ORDER BY functions.ts ASC) AS number
54FROM functions
55JOIN android_startups launches ON launches.package GLOB '*' || functions.process_name || '*'
56WHERE functions.function_name GLOB "Choreographer#doFrame*" AND functions.ts > launches.ts;
57
58DROP VIEW IF EXISTS android_render_frame_times;
59CREATE PERFETTO VIEW android_render_frame_times AS
60SELECT
61  functions.ts AS ts,
62  functions.ts + functions.dur AS ts_end,
63  launches.package AS name,
64  launches.startup_id,
65  ROW_NUMBER() OVER(PARTITION BY launches.startup_id ORDER BY functions.ts ASC) AS number
66FROM functions
67JOIN android_startups launches ON launches.package GLOB '*' || functions.process_name || '*'
68WHERE functions.function_name GLOB "DrawFrame*" AND functions.ts > launches.ts;
69
70DROP VIEW IF EXISTS frame_times;
71CREATE PERFETTO VIEW frame_times AS
72SELECT startup_id AS launch_id, * FROM android_frame_times;
73
74DROP TABLE IF EXISTS hsc_based_startup_times;
75CREATE TABLE hsc_based_startup_times(package STRING, id INT, ts_total INT);
76
77-- Calculator
78INSERT INTO hsc_based_startup_times
79SELECT
80  launches.package AS package,
81  launches.startup_id AS id,
82  android_frame_times.ts_end - launches.ts AS ts_total
83FROM android_frame_times
84JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
85WHERE android_frame_times.number = 2 AND android_frame_times.name GLOB "*roid.calcul*" AND android_frame_times.startup_id = launches.startup_id;
86
87-- Calendar
88-- Using the DrawFrame slice from the render thread due to Calendar delaying its rendering
89INSERT INTO hsc_based_startup_times
90SELECT
91  launches.package AS package,
92  launches.startup_id AS id,
93  android_render_frame_times.ts_end - launches.ts AS ts_total
94FROM android_render_frame_times
95JOIN android_startups launches ON launches.package GLOB '*' || android_render_frame_times.name || '*'
96WHERE android_render_frame_times.number = 5 AND android_render_frame_times.name GLOB "*id.calendar*" AND android_render_frame_times.startup_id = launches.startup_id;
97
98-- Camera
99INSERT INTO hsc_based_startup_times
100SELECT
101  launches.package AS package,
102  launches.startup_id AS id,
103  android_frame_times.ts_end - launches.ts AS ts_total
104FROM android_frame_times
105JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
106WHERE android_frame_times.number = 2 AND android_frame_times.name GLOB "*GoogleCamera*" AND android_frame_times.startup_id = launches.startup_id;
107
108-- Chrome
109INSERT INTO hsc_based_startup_times
110SELECT
111  launches.package AS package,
112  launches.startup_id AS id,
113  android_frame_times.ts_end - launches.ts AS ts_total
114FROM android_frame_times
115JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
116WHERE android_frame_times.number = 4 AND android_frame_times.name GLOB "*chrome*" AND android_frame_times.startup_id = launches.startup_id;
117
118-- Clock
119INSERT INTO hsc_based_startup_times
120SELECT
121  launches.package AS package,
122  launches.startup_id AS id,
123  android_frame_times.ts_end - launches.ts AS ts_total
124FROM android_frame_times
125JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
126WHERE android_frame_times.ts > (SELECT ts + dur FROM animators WHERE animator_name = "animator:translationZ" AND process_name GLOB "*id.deskclock" ORDER BY (ts + dur) DESC LIMIT 1) AND android_frame_times.name GLOB "*id.deskclock" AND android_frame_times.startup_id = launches.startup_id
127ORDER BY ts_total LIMIT 1;
128
129-- Contacts
130INSERT INTO hsc_based_startup_times
131SELECT
132  launches.package AS package,
133  launches.startup_id AS id,
134  android_frame_times.ts_end - launches.ts AS ts_total
135FROM android_frame_times
136JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
137WHERE android_frame_times.number = 3 AND android_frame_times.name GLOB "*id.contacts" AND android_frame_times.startup_id = launches.startup_id;
138
139-- Dialer
140-- Dialer only runs one animation at startup, use the last animation frame to indicate startup.
141INSERT INTO hsc_based_startup_times
142SELECT
143  launches.package AS package,
144  launches.startup_id AS id,
145  android_frame_times.ts_end - launches.ts AS ts_total
146FROM android_frame_times
147JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
148WHERE android_frame_times.ts > (SELECT ts + dur FROM animators WHERE process_name GLOB "*id.dialer" AND animator_name GLOB "*animator*" ORDER BY (ts + dur) DESC LIMIT 1) AND android_frame_times.name GLOB "*id.dialer" AND android_frame_times.startup_id = launches.startup_id LIMIT 1;
149
150-- Facebook
151INSERT INTO hsc_based_startup_times
152SELECT
153  launches.package AS package,
154  launches.startup_id AS id,
155  android_frame_times.ts_end - launches.ts AS ts_total
156FROM android_frame_times
157JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
158WHERE android_frame_times.ts > (SELECT ts + dur FROM slices WHERE slices.name GLOB "fb_startup_complete" ORDER BY ts LIMIT 1) AND android_frame_times.name GLOB "*ok.katana" AND android_frame_times.startup_id = launches.startup_id
159ORDER BY ts_total LIMIT 1;
160
161-- Facebook Messenger
162INSERT INTO hsc_based_startup_times
163SELECT
164  launches.package AS package,
165  launches.startup_id AS id,
166  android_frame_times.ts_end - launches.ts AS ts_total
167FROM android_frame_times
168JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
169WHERE android_frame_times.ts > (SELECT ts + dur FROM slices WHERE slices.name GLOB "msgr_cold_start_to_cached_content" ORDER BY ts LIMIT 1) AND android_frame_times.name GLOB "*book.orca" AND android_frame_times.startup_id = launches.startup_id
170ORDER BY ts_total LIMIT 1;
171
172-- Gmail
173INSERT INTO hsc_based_startup_times
174SELECT
175  launches.package AS package,
176  launches.startup_id AS id,
177  android_frame_times.ts_end - launches.ts AS ts_total
178FROM android_frame_times
179JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
180WHERE android_frame_times.ts > (SELECT ts + dur FROM animators WHERE animator_name = "animator:elevation" AND process_name GLOB "*android.gm" ORDER BY (ts + dur) DESC LIMIT 1) AND android_frame_times.name GLOB "*android.gm" AND android_frame_times.startup_id = launches.startup_id
181ORDER BY ts_total LIMIT 1;
182
183-- Instagram
184INSERT INTO hsc_based_startup_times
185SELECT
186  launches.package AS package,
187  launches.startup_id AS id,
188  android_frame_times.ts_end - launches.ts AS ts_total
189FROM android_frame_times
190JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
191WHERE android_frame_times.ts > (SELECT ts + dur FROM slices WHERE slices.name GLOB "ig_cold_start_to_cached_content" ORDER BY ts LIMIT 1) AND android_frame_times.name GLOB "*gram.android" AND android_frame_times.startup_id = launches.startup_id
192ORDER BY ts_total LIMIT 1;
193
194-- Maps
195-- Use the 8th choreographer frame to indicate startup.
196INSERT INTO hsc_based_startup_times
197SELECT
198  launches.package AS package,
199  launches.startup_id AS id,
200  android_frame_times.ts_end - launches.ts AS ts_total
201FROM android_frame_times
202JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
203WHERE android_frame_times.number = 8 AND android_frame_times.name GLOB "*maps*" AND android_frame_times.startup_id = launches.startup_id;
204
205-- Messages
206-- Use the first choreographer frame that is emitted after all animator:translationZ slices end.
207INSERT INTO hsc_based_startup_times
208SELECT
209  launches.package AS package,
210  launches.startup_id AS id,
211  android_frame_times.ts_end - launches.ts AS ts_total
212FROM android_frame_times
213JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
214WHERE android_frame_times.ts_end > (SELECT ts + dur FROM animators WHERE animator_name = "animator:translationZ" AND process_name GLOB "*apps.messaging*" ORDER BY (ts + dur) DESC LIMIT 1) AND android_frame_times.name GLOB "*apps.messaging*" AND android_frame_times.startup_id = launches.startup_id
215ORDER BY ts_total LIMIT 1;
216
217-- Netflix
218INSERT INTO hsc_based_startup_times
219SELECT
220  launches.package AS package,
221  launches.startup_id AS id,
222  android_frame_times.ts_end - launches.ts AS ts_total
223FROM android_frame_times
224JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
225WHERE android_frame_times.ts < (SELECT ts FROM animators WHERE animator_name GLOB "animator*" AND process_name GLOB "*lix.mediaclient" ORDER BY ts LIMIT 1) AND android_frame_times.name GLOB "*lix.mediaclient*" AND android_frame_times.startup_id = launches.startup_id
226ORDER BY ts_total DESC LIMIT 1;
227
228-- Photos
229-- Use the animator:translationZ slice as startup indicator.
230INSERT INTO hsc_based_startup_times
231SELECT
232  launches.package AS package,
233  launches.startup_id AS id,
234  android_frame_times.ts_end - launches.ts AS ts_total
235FROM android_frame_times
236JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
237WHERE android_frame_times.ts > (SELECT ts + dur FROM animators WHERE process_name GLOB "*apps.photos" AND animator_name GLOB "animator:translationZ" ORDER BY (ts + dur) DESC LIMIT 1) AND android_frame_times.name GLOB "*apps.photos*" AND android_frame_times.startup_id = launches.startup_id LIMIT 1;
238
239-- Settings was deprecated in favor of reportFullyDrawn b/169694037.
240
241-- Snapchat
242INSERT INTO hsc_based_startup_times
243SELECT
244  launches.package AS package,
245  launches.startup_id AS id,
246  android_frame_times.ts_end - launches.ts AS ts_total
247FROM android_frame_times
248JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
249WHERE android_frame_times.number = 1 AND android_frame_times.name GLOB "*napchat.android" AND android_frame_times.startup_id = launches.startup_id;
250
251-- Twitter
252INSERT INTO hsc_based_startup_times
253SELECT
254  launches.package AS package,
255  launches.startup_id AS id,
256  android_frame_times.ts_end - launches.ts AS ts_total
257FROM android_frame_times
258JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
259WHERE android_frame_times.ts_end > (SELECT ts FROM animators WHERE animator_name = "animator" AND process_name GLOB "*tter.android" ORDER BY ts LIMIT 1) AND android_frame_times.name GLOB "*tter.android" AND android_frame_times.startup_id = launches.startup_id
260ORDER BY ts_total LIMIT 1;
261
262-- WhatsApp
263INSERT INTO hsc_based_startup_times
264SELECT
265  launches.package AS package,
266  launches.startup_id AS id,
267  android_frame_times.ts_end - launches.ts AS ts_total
268FROM android_frame_times
269JOIN android_startups launches ON launches.package GLOB '*' || android_frame_times.name || '*'
270WHERE android_frame_times.ts > (SELECT ts + dur FROM slices WHERE slices.name GLOB "wa_startup_complete" ORDER BY ts LIMIT 1) AND android_frame_times.name GLOB "*om.whatsapp" AND android_frame_times.startup_id = launches.startup_id
271ORDER BY ts_total LIMIT 1;
272
273-- Youtube
274-- Use the 10th frame that is rendered
275INSERT INTO hsc_based_startup_times
276SELECT
277  launches.package AS package,
278  launches.startup_id AS id,
279  android_render_frame_times.ts_end - launches.ts AS ts_total
280FROM android_render_frame_times
281JOIN android_startups launches ON launches.package GLOB '*' || android_render_frame_times.name || '*'
282WHERE android_render_frame_times.number = 10 AND android_render_frame_times.name GLOB "*id.youtube" AND android_render_frame_times.startup_id = launches.startup_id;
283