trace_processor: Add a helper for finding Chrome processes and threads

Usage: SELECT RUN_METRIC("chrome/chrome_processes.sql");

Bug: 152840173
Change-Id: Iff270e01172be2ead08c6e934fe2a6aab84fe23d
diff --git a/Android.bp b/Android.bp
index fa38157..7609f8e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -49,6 +49,7 @@
     "src/trace_processor/metrics/android/unmapped_java_symbols.sql",
     "src/trace_processor/metrics/android/unsymbolized_frames.sql",
     "src/trace_processor/metrics/android/upid_span_view.sql",
+    "src/trace_processor/metrics/chrome/chrome_processes.sql",
     "src/trace_processor/metrics/trace_metadata.sql",
   ],
   cmd: "$(location tools/gen_merged_sql_metrics.py) --cpp_out=$(out) $(in)",
diff --git a/BUILD b/BUILD
index 33c1a8e..bf63e4c 100644
--- a/BUILD
+++ b/BUILD
@@ -767,6 +767,7 @@
         "src/trace_processor/metrics/android/unmapped_java_symbols.sql",
         "src/trace_processor/metrics/android/unsymbolized_frames.sql",
         "src/trace_processor/metrics/android/upid_span_view.sql",
+        "src/trace_processor/metrics/chrome/chrome_processes.sql",
         "src/trace_processor/metrics/trace_metadata.sql",
     ],
     outs = [
diff --git a/src/trace_processor/metrics/BUILD.gn b/src/trace_processor/metrics/BUILD.gn
index b6595b9..01649da 100644
--- a/src/trace_processor/metrics/BUILD.gn
+++ b/src/trace_processor/metrics/BUILD.gn
@@ -48,6 +48,7 @@
   "android/upid_span_view.sql",
   "android/unmapped_java_symbols.sql",
   "android/unsymbolized_frames.sql",
+  "chrome/chrome_processes.sql",
 ]
 
 config("gen_config") {
diff --git a/src/trace_processor/metrics/chrome/chrome_processes.sql b/src/trace_processor/metrics/chrome/chrome_processes.sql
new file mode 100644
index 0000000..9287082
--- /dev/null
+++ b/src/trace_processor/metrics/chrome/chrome_processes.sql
@@ -0,0 +1,48 @@
+--
+-- Copyright 2020 The Android Open Source Project
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--     https://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+-- A view of all Chrome processes.
+-- TODO(skyostil): Create this table in the trace processor internally so we
+-- can expose the process type.
+DROP VIEW IF EXISTS chrome_process;
+
+CREATE VIEW chrome_process AS
+  SELECT *
+  FROM process WHERE (
+    -- Chrome package names.
+    name like 'com.android.chrome%' OR
+    name like 'com.chrome.beta%' OR
+    name like 'com.chrome.dev%' OR
+    name like 'com.chrome.canary%' OR
+    name like 'com.google.android.apps.chrome%' OR
+    name like 'org.chromium.chrome%' OR
+    -- Chrome process descriptor names.
+    name = 'Browser' OR
+    name = 'Renderer' OR
+    name = 'Utility' OR
+    name = 'Zygote' OR
+    name = 'SandboxHelper' OR
+    name = 'Gpu' OR
+    name = 'PpapiPlugin' OR
+    name = 'PpapiBroker');
+
+-- A view of all Chrome threads.
+DROP VIEW IF EXISTS chrome_thread;
+
+CREATE VIEW chrome_thread AS
+  SELECT thread.*
+  FROM thread, chrome_process
+  WHERE thread.upid = chrome_process.upid;