• 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-- Needed for the scroll_jank table to tell which updates were janky.
17SELECT RUN_METRIC('chrome/scroll_jank.sql');
18
19--------------------------------------------------------------------------------
20-- Get all the track ids relevant to the critical path.
21--------------------------------------------------------------------------------
22
23-- Grab the track of the browser. sendTouchEvent is a Java category event which
24-- only occurs on the browser. This saves us the trouble of dealing with all the
25-- different possible names of the browser (when including system tracing).
26DROP VIEW IF EXISTS browser_main_track_id;
27CREATE VIEW browser_main_track_id AS
28SELECT
29  track_id AS id
30FROM slice
31WHERE
32  name = "sendTouchEvent"
33LIMIT 1;
34
35--------------------------------------------------------------------------------
36-- Grab the last LatencyInfo.Flow for each trace_id on the browser main.
37--------------------------------------------------------------------------------
38DROP VIEW IF EXISTS browser_flows;
39CREATE VIEW browser_flows AS
40SELECT
41  EXTRACT_ARG(arg_set_id, "chrome_latency_info.trace_id") AS trace_id,
42  EXTRACT_ARG(arg_set_id, "chrome_latency_info.step") AS flow_step,
43  track_id,
44  max(ts) AS ts
45FROM slice
46WHERE
47  track_id = (
48    SELECT id FROM browser_main_track_id
49  ) AND
50  name = "LatencyInfo.Flow"
51  GROUP BY trace_id;
52
53--------------------------------------------------------------------------------
54-- Join the relevant tracks/flows to the individual scrolls.
55--------------------------------------------------------------------------------
56
57-- Keeping only the GestureScrollUpdates join the maximum flows on the browser
58-- thread.
59DROP VIEW IF EXISTS scroll_with_browser_flows;
60CREATE VIEW scroll_with_browser_flows AS
61SELECT
62  scroll.trace_id,
63  scroll.scroll_id,
64  scroll.ts,
65  scroll.dur,
66  scroll.track_id,
67  browser_flows.ts AS browser_flow_ts,
68  browser_flows.flow_step AS browser_flow_step,
69  browser_flows.track_id AS browser_track_id
70FROM (
71  SELECT
72    trace_id,
73    id AS scroll_id,
74    ts,
75    dur,
76    track_id
77  FROM scroll_jank
78) scroll JOIN browser_flows ON
79    scroll.trace_id = browser_flows.trace_id;
80
81--------------------------------------------------------------------------------
82-- Below we determine if there was any bitmaps taken on the browser main.
83--------------------------------------------------------------------------------
84DROP VIEW IF EXISTS get_bitmap_calls;
85CREATE VIEW get_bitmap_calls AS
86  SELECT
87    id,
88    ts,
89    dur,
90    track_id
91  FROM slice
92  WHERE
93    slice.name = "ViewResourceAdapter:getBitmap" AND
94    track_id = (SELECT id FROM browser_main_track_id);
95
96DROP VIEW IF EXISTS toolbar_bitmaps;
97CREATE VIEW toolbar_bitmaps AS
98  SELECT
99    slice.id,
100    slice.ts,
101    slice.dur,
102    slice.track_id,
103    ancestor.id AS ancestor_id
104  FROM
105    slice JOIN
106    ancestor_slice(slice.id) AS ancestor ON
107      ancestor.depth = slice.depth - 1
108  WHERE
109    slice.name = "ToolbarLayout.draw" AND
110    ancestor.name = "ViewResourceAdapter:getBitmap" AND
111    slice.track_id = (SELECT id FROM browser_main_track_id);
112
113DROP VIEW IF EXISTS get_bitmaps_and_toolbar;
114CREATE VIEW get_bitmaps_and_toolbar AS
115  SELECT
116    bitmap.id AS id,
117    bitmap.ts AS ts,
118    bitmap.dur AS dur,
119    bitmap.track_id AS track_id,
120    toolbar.id AS toolbar_id,
121    toolbar.ts AS toolbar_ts,
122    toolbar.dur AS toolbar_dur,
123    toolbar.track_id AS toolbar_track_id
124  FROM
125    get_bitmap_calls bitmap LEFT JOIN
126    toolbar_bitmaps toolbar ON
127      toolbar.ancestor_id = bitmap.id;
128
129--------------------------------------------------------------------------------
130-- Take bitmaps and determine if it could have been blocked by a scroll. I.E. if
131-- the bitmap occurred after the start of the GestureScrollUpdate but before the
132-- last flow on the browser thread (the GestureScrollUpdate can't be blocked
133-- by a browser thread slice once its done on the browser thread).
134--------------------------------------------------------------------------------
135DROP VIEW IF EXISTS blocking_bitmap_tasks;
136CREATE VIEW blocking_bitmap_tasks AS
137SELECT
138  scroll.scroll_id,
139  scroll.trace_id,
140  bitmap.id,
141  bitmap.ts,
142  bitmap.dur,
143  bitmap.track_id,
144  CASE WHEN
145      bitmap.track_id = scroll.browser_track_id AND
146      bitmap.ts < scroll.browser_flow_ts THEN
147    TRUE
148  ELSE
149    FALSE
150  END AS blocked_by_bitmap,
151  CASE WHEN
152      bitmap.track_id = scroll.browser_track_id AND
153      bitmap.toolbar_id IS NOT NULL AND
154      bitmap.ts < scroll.browser_flow_ts THEN
155    TRUE
156  ELSE
157    FALSE
158  END AS blocked_by_toolbar,
159  CASE WHEN
160      bitmap.track_id = scroll.browser_track_id AND
161      bitmap.toolbar_id IS NULL AND
162      bitmap.ts < scroll.browser_flow_ts THEN
163    TRUE
164  ELSE
165    FALSE
166  END AS blocked_by_bitmap_no_toolbar
167FROM
168  scroll_with_browser_flows scroll JOIN
169  get_bitmaps_and_toolbar bitmap ON
170  scroll.ts + scroll.dur >= bitmap.ts AND
171  bitmap.ts + bitmap.dur >= scroll.ts;
172
173
174--------------------------------------------------------------------------------
175-- Remove duplicate tasks blocking so that there is only a boolean per
176-- scroll_id.
177--------------------------------------------------------------------------------
178DROP VIEW IF EXISTS scroll_jank_cause_get_bitmap;
179CREATE VIEW scroll_jank_cause_get_bitmap AS
180SELECT
181  scroll_id,
182  trace_id,
183  SUM(blocked_by_bitmap) > 0 AS blocked_by_bitmap,
184  SUM(blocked_by_toolbar) > 0 AS blocked_by_toolbar,
185  SUM(blocked_by_bitmap_no_toolbar) > 0 AS blocked_by_bitmap_no_toolbar
186FROM blocking_bitmap_tasks
187GROUP BY 1, 2;
188