• 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 VIEW IF EXISTS all_chrome_processes;
20CREATE PERFETTO VIEW all_chrome_processes AS
21SELECT upid, IFNULL(pt.string_value, '') AS process_type
22FROM process
23-- A process is a Chrome process if it has a chrome.process_type arg.
24-- The value of the arg may be NULL.
25-- All Chromium producers emit chrome_process field in their process track
26-- descriptor when Chromium track event data source is enabled.
27-- So this returns all processes in Chrome traces, and a subset of processes
28-- in system traces.
29JOIN
30  (SELECT arg_set_id, string_value FROM args WHERE key = 'chrome.process_type')
31  pt
32  ON process.arg_set_id = pt.arg_set_id;
33
34-- A view of all Chrome threads.
35DROP VIEW IF EXISTS all_chrome_threads;
36CREATE PERFETTO VIEW all_chrome_threads AS
37SELECT utid, thread.upid, thread.name
38FROM thread, all_chrome_processes
39WHERE thread.upid = all_chrome_processes.upid;
40
41-- For sandboxed and privileged processes (found in Android system traces), use
42-- the main thread name to type of process.
43DROP VIEW IF EXISTS chrome_subprocess_types;
44CREATE PERFETTO VIEW chrome_subprocess_types AS
45-- Sometimes you can get multiple threads in a trace marked main_thread, but
46-- they appear to have the same name so just use one of them.
47SELECT DISTINCT p.upid,
48  SUBSTR(t.name, 3, LENGTH(t.name) - 6) AS sandbox_type
49FROM all_chrome_processes p
50JOIN all_chrome_threads t ON p.upid = t.upid
51WHERE process_type IN ("Sandboxed", "Privileged")
52  AND t.name GLOB "Cr*Main";
53
54-- Contains all the chrome processes from process with an extra column,
55-- process_type.
56DROP VIEW IF EXISTS chrome_process;
57CREATE PERFETTO VIEW chrome_process AS
58SELECT PROCESS.*,
59  IIF(sandbox_type IS NULL, process_type, sandbox_type) AS process_type
60FROM PROCESS
61JOIN (
62    SELECT a.upid,
63      sandbox_type,
64      process_type
65    FROM all_chrome_processes a
66    LEFT JOIN chrome_subprocess_types s ON a.upid = s.upid
67  ) c ON PROCESS.upid = c.upid;
68
69-- Contains all the chrome threads from thread with an extra column,
70-- canonical_name, that should contain a thread that's the same in both chrome
71-- and system traces.
72DROP VIEW IF EXISTS chrome_thread;
73
74CREATE PERFETTO VIEW chrome_thread AS
75SELECT thread.*,
76  CASE
77    WHEN thread.name GLOB "Cr*Main" THEN "CrProcessMain"
78    WHEN thread.name IS NULL THEN "Unknown"
79    ELSE thread.name
80  END AS canonical_name
81FROM (
82    SELECT t.utid,
83      p.*
84    FROM all_chrome_threads t
85    JOIN chrome_process p ON t.upid = p.upid
86  ) c
87JOIN thread ON thread.utid = c.utid;
88