• 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
67DROP VIEW IF EXISTS all_chrome_processes;
68CREATE VIEW all_chrome_processes AS
69SELECT upid, m.type AS process_type
70FROM process JOIN chrome_process_name_type_mapping m
71ON name GLOB original_name_pattern;
72
73-- A view of all Chrome threads.
74DROP VIEW IF EXISTS all_chrome_threads;
75CREATE VIEW all_chrome_threads AS
76  SELECT utid, thread.upid, thread.name
77  FROM thread, all_chrome_processes
78  WHERE thread.upid = all_chrome_processes.upid;
79
80-- For sandboxed and privileged processes (found in Android system traces), use
81-- the main thread name to type of process.
82DROP VIEW IF EXISTS chrome_subprocess_types;
83CREATE VIEW chrome_subprocess_types AS
84-- Sometimes you can get multiple threads in a trace marked main_thread, but
85-- they appear to have the same name so just use one of them.
86SELECT DISTINCT p.upid,
87  SUBSTR(t.name, 3, LENGTH(t.name) - 6) AS sandbox_type
88FROM all_chrome_processes p
89  JOIN all_chrome_threads t ON p.upid = t.upid
90WHERE process_type IN ("Sandboxed", "Privileged")
91  AND t.name GLOB "Cr*Main";
92
93-- Contains all the chrome processes from process with an extra column,
94-- process_type.
95DROP VIEW IF EXISTS chrome_process;
96CREATE VIEW chrome_process AS
97SELECT PROCESS.*,
98  IIF(sandbox_type IS NULL, process_type, sandbox_type) AS process_type
99FROM PROCESS
100  JOIN (
101    SELECT a.upid,
102      sandbox_type,
103      process_type
104    FROM all_chrome_processes a
105      LEFT JOIN chrome_subprocess_types s ON a.upid = s.upid
106  ) c ON PROCESS.upid = c.upid;
107
108-- Contains all the chrome threads from thread with an extra column,
109-- canonical_name, that should contain a thread that's the same in both chrome
110-- and system traces.
111DROP VIEW IF EXISTS chrome_thread;
112
113CREATE VIEW chrome_thread AS
114SELECT thread.*,
115  CASE
116    WHEN thread.name GLOB "Cr*Main" THEN "CrProcessMain"
117    WHEN thread.name IS NULL THEN "Unknown"
118    ELSE thread.name
119  END AS canonical_name
120FROM (
121    SELECT t.utid,
122      p.*
123    FROM all_chrome_threads t
124      JOIN chrome_process p ON t.upid = p.upid
125  ) c
126  JOIN thread ON thread.utid = c.utid;
127