• 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
17-- Table to map any of the various chrome process names to a type (e.g. Browser,
18-- Renderer, GPU Process, etc).
19DROP TABLE IF EXISTS chrome_process_name_type_mapping;
20CREATE TABLE chrome_process_name_type_mapping (
21  original_name_pattern TEXT UNIQUE,
22  type TEXT
23);
24
25WITH prefix (value) AS (
26  SELECT *
27  FROM (
28      VALUES ("org.chromium.chrome"),
29        ("com.google.android.apps.chrome"),
30        ("com.android.chrome"),
31        ("com.chrome.beta"),
32        ("com.chrome.canary"),
33        ("com.chrome.dev")
34    )
35),
36suffix (value, TYPE) AS (
37  SELECT *
38  FROM (
39      VALUES ("", "Browser"),
40        (
41          ":sandboxed_process*:org.chromium.content.app.SandboxedProcessService*",
42          "Sandboxed"
43        ),
44        (":privileged_process*", "Privileged"),
45        ("_zygote", "Zygote")
46    )
47)
48-- Insert the Chrome process names for a normal chrome trace
49INSERT INTO chrome_process_name_type_mapping
50VALUES ('Browser', 'Browser'),
51  ('Renderer', 'Renderer'),
52  ('GPU Process', 'Gpu'),
53  ('Gpu', 'Gpu'),
54  ('Zygote', 'Zygote'),
55  ('Utility', 'Utility'),
56  ('SandboxHelper', 'SandboxHelper'),
57  ('PpapiPlugin', 'PpapiPlugin'),
58  ('PpapiBroker', 'PpapiBroker')
59UNION ALL
60-- Construct all the possible Chrome process names for an Android system chrome
61-- trace.
62SELECT prefix.value || suffix.value AS name,
63  suffix.type AS type
64FROM prefix,
65  suffix;
66
67-- Use GLOB here instead of LIKE as it's case-sensitive which means we don't
68-- match the Android system zygote.
69DROP VIEW IF EXISTS all_chrome_processes;
70CREATE VIEW all_chrome_processes AS
71SELECT upid, m.type AS process_type
72FROM process JOIN chrome_process_name_type_mapping m
73ON name GLOB original_name_pattern;
74
75-- A view of all Chrome threads.
76DROP VIEW IF EXISTS all_chrome_threads;
77CREATE VIEW all_chrome_threads AS
78  SELECT utid, thread.upid, thread.name
79  FROM thread, all_chrome_processes
80  WHERE thread.upid = all_chrome_processes.upid;
81
82-- For sandboxed and privileged processes (found in Android system traces), use
83-- the main thread name to type of process.
84DROP VIEW IF EXISTS chrome_subprocess_types;
85CREATE VIEW chrome_subprocess_types AS
86-- Sometimes you can get multiple threads in a trace marked main_thread, but
87-- they appear to have the same name so just use one of them.
88SELECT DISTINCT p.upid,
89  SUBSTR(t.name, 3, LENGTH(t.name) - 6) AS sandbox_type
90FROM all_chrome_processes p
91  JOIN all_chrome_threads t ON p.upid = t.upid
92WHERE process_type IN ("Sandboxed", "Privileged")
93  AND t.name GLOB "Cr*Main";
94
95-- Contains all the chrome processes from process with an extra column,
96-- process_type.
97DROP VIEW IF EXISTS chrome_process;
98CREATE VIEW chrome_process AS
99SELECT PROCESS.*,
100  IIF(sandbox_type IS NULL, process_type, sandbox_type) AS process_type
101FROM PROCESS
102  JOIN (
103    SELECT a.upid,
104      sandbox_type,
105      process_type
106    FROM all_chrome_processes a
107      LEFT JOIN chrome_subprocess_types s ON a.upid = s.upid
108  ) c ON PROCESS.upid = c.upid;
109
110-- Contains all the chrome threads from thread with an extra column,
111-- canonical_name, that should contain a thread that's the same in both chrome
112-- and system traces.
113DROP VIEW IF EXISTS chrome_thread;
114
115CREATE VIEW chrome_thread AS
116SELECT thread.*,
117  CASE
118    WHEN thread.name GLOB "Cr*Main" THEN "CrProcessMain"
119    WHEN thread.name IS NULL THEN "Unknown"
120    ELSE thread.name
121  END AS canonical_name
122FROM (
123    SELECT t.utid,
124      p.*
125    FROM all_chrome_threads t
126      JOIN chrome_process p ON t.upid = p.upid
127  ) c
128  JOIN thread ON thread.utid = c.utid;
129