xref: /aosp_15_r20/external/perfetto/src/trace_processor/metrics/sql/webview/webview_jank_approximation.sql (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1--
2-- Copyright 2023 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-- We approximate WebView-related app janks by selecting WebView renderer
17-- slices and overlapping them with app jank slices for known apps.
18
19-- Select all WebView processes
20DROP VIEW IF EXISTS webview_processes;
21CREATE PERFETTO VIEW webview_processes AS
22SELECT * FROM process
23WHERE name IN ('com.google.android.gm',
24  'com.google.android.googlequicksearchbox',
25  'com.google.android.apps.searchlite',
26  'com.google.android.apps.magazines');
27
28-- Select all system processes
29DROP VIEW IF EXISTS system_processes;
30CREATE PERFETTO VIEW system_processes AS
31SELECT * FROM process
32WHERE name IN ('com.android.systemui',
33  '/system/bin/surfaceflinger',
34  'system_server');
35
36-- Select all slices related to startup
37DROP TABLE IF EXISTS webview_browser_startup_slices;
38CREATE PERFETTO TABLE webview_browser_startup_slices AS
39SELECT slice.id AS browser_startup_id, slice.ts, slice.dur
40FROM slice
41WHERE name = 'WebViewChromium.init';
42
43-- Select all scheduler slices from WebView renderer processes
44DROP TABLE IF EXISTS webview_renderer_slices;
45CREATE PERFETTO TABLE webview_renderer_slices AS
46SELECT sched_slice.id as renderer_id, sched_slice.ts, sched_slice.dur
47FROM sched_slice
48JOIN thread
49USING(utid)
50JOIN process
51USING (upid)
52WHERE process.name GLOB '*webview*Sand*';
53
54-- Select all jank slices
55DROP TABLE IF EXISTS all_self_jank_slices;
56CREATE PERFETTO TABLE all_self_jank_slices AS
57SELECT *
58FROM actual_frame_timeline_slice
59WHERE jank_type NOT IN ('None', 'Buffer Stuffing')
60  AND jank_tag = 'Self Jank';
61
62-- Select all jank slices from WebView processes
63-- @column id Id of jank slice from a WebView process
64-- @column ts Timestamp of the start of jank slice in a WebView process (in nanoseconds)
65-- @column dur Duration of jank slice in a WebView process (in nanoseconds)
66DROP VIEW IF EXISTS webview_app_jank_slices;
67CREATE PERFETTO VIEW webview_app_jank_slices AS
68SELECT * FROM all_self_jank_slices
69WHERE upid IN (SELECT upid FROM webview_processes);
70
71-- Select all jank slices from all processes except system processes
72-- @column id Id of jank slice from all processes except system processes
73-- @column ts Timestamp of the start of jank slice from all processes except system processes (in nanoseconds)
74-- @column dur Duration of the jank slice from all processes except system processes (in nanoseconds)
75DROP VIEW IF EXISTS webview_all_app_jank_slices;
76CREATE PERFETTO VIEW webview_all_app_jank_slices AS
77SELECT * FROM all_self_jank_slices
78WHERE upid NOT IN (SELECT upid FROM system_processes);
79
80-- Select jank slices from WebView processes overlapping WebView renderer
81-- scheduler slices
82-- @column id Id of jank slice from WebView processes overlapping WebView renderer
83-- @column ts Timestamp of the start of jank slice from WebView processes overlapping WebView renderer (in nanoseconds)
84-- @column dur Duration of jank slice from WebView processes overlapping WebView renderer (in nanoseconds)
85DROP TABLE IF EXISTS webview_jank_slices;
86CREATE VIRTUAL TABLE webview_jank_slices
87USING SPAN_JOIN(webview_renderer_slices,
88                webview_app_jank_slices);
89
90-- Select jank slices overlapping WebView startup slices
91-- @column id Id of jank slice overlapping WebView startup slices
92-- @column ts Timestamp of the start of jank slice overlapping WebView startup slices (in nanoseconds)
93-- @column dur Duration of jank slice overlapping WebView startup slices (in nanoseconds)
94DROP TABLE IF EXISTS webview_browser_startup_jank_slices;
95CREATE VIRTUAL TABLE webview_browser_startup_jank_slices
96USING SPAN_JOIN(webview_browser_startup_slices,
97               webview_app_jank_slices);
98
99-- Select jank slices from all processes except system processes overlapping
100-- WebView renderer scheduler slices
101-- @column id Id of jank slice from all processes except system processes overlapping WebView renderer scheduler slices
102-- @column ts Timestamp of the start of jank slice from all processes except system processes overlapping WebView renderer scheduler slices (in nanoseconds)
103-- @column dur Duration of jank slice from all processes except system processes overlapping WebView renderer scheduler slices (in nanoseconds)
104DROP TABLE IF EXISTS webview_total_jank_slices;
105CREATE VIRTUAL TABLE webview_total_jank_slices
106USING SPAN_JOIN(webview_renderer_slices,
107                webview_all_app_jank_slices);
108
109-- Select jank slices from WebView processes overlapping WebView renderer
110-- scheduler slices excluding WebView startup slices
111-- @column id Id of jank slice from WebView processes overlapping WebView renderer scheduler slices excluding WebView startup slices
112-- @column ts Timestamp of the start of jank slice from WebView processes overlapping WebView renderer scheduler slices excluding WebView startup slices (in nanoseconds)
113-- @column dur Duration of jank slice from WebView processes overlapping WebView renderer scheduler slices excluding WebView startup slices (in nanoseconds)
114DROP VIEW IF EXISTS webview_janks_slices_without_startup;
115CREATE PERFETTO VIEW webview_janks_slices_without_startup AS
116SELECT * FROM webview_jank_slices
117WHERE id NOT IN (SELECT id FROM webview_browser_startup_jank_slices);
118
119-- Summary for all types of janks
120-- @column webview_janks janks in WebView apps that overlap with WebView renderer
121-- @column webview_janks_without_startup same as above but excluding startup
122-- @column webview_app_janks janks in WebView apps
123-- @column webview_total_janks janks in all apps (except system) that overlap with WebView renderer
124-- @column total_janks janks in all apps (except system)
125DROP VIEW IF EXISTS webview_jank_approximation_summary;
126CREATE PERFETTO VIEW webview_jank_approximation_summary AS
127WITH wvj AS (SELECT COUNT(DISTINCT(id)) AS webview_janks
128  FROM webview_jank_slices),
129wvjwos AS (SELECT COUNT(DISTINCT(id))
130  AS webview_janks_without_startup FROM webview_janks_slices_without_startup),
131wvaj AS (SELECT COUNT(DISTINCT(id))
132  AS webview_app_janks FROM webview_app_jank_slices),
133wvtj AS (SELECT COUNT(DISTINCT(id)) AS webview_total_janks
134  FROM webview_total_jank_slices),
135tj AS (SELECT COUNT(DISTINCT(id))
136  AS total_janks FROM webview_all_app_jank_slices)
137SELECT *
138from wvj, wvjwos, wvaj, wvtj, tj;
139
140DROP VIEW IF EXISTS webview_jank_approximation_output;
141CREATE PERFETTO VIEW webview_jank_approximation_output AS
142SELECT WebViewJankApproximation(
143  'webview_janks', (SELECT webview_janks FROM webview_jank_approximation_summary),
144  'webview_janks_without_startup', (SELECT webview_janks_without_startup FROM webview_jank_approximation_summary),
145  'webview_app_janks', (SELECT webview_app_janks FROM webview_jank_approximation_summary),
146  'webview_total_janks', (SELECT webview_total_janks FROM webview_jank_approximation_summary),
147  'total_janks', (SELECT total_janks FROM webview_jank_approximation_summary)
148);