1-- 2-- Copyright 2019 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-- Count packages by package UID. 18CREATE TABLE internal_uid_package_count AS 19SELECT uid, COUNT(1) AS cnt 20FROM package_list 21GROUP BY 1; 22 23-- Data about packages running on the process. 24-- 25-- @column upid Process upid. 26-- @column process_name Process name. 27-- @column package_name Name of the packages running in this process. 28-- @column version_code Package version code. 29-- @column debuggable Whether package is debuggable. 30CREATE TABLE android_process_metadata AS 31SELECT 32 process.upid, 33 -- workaround for b/169226092: the bug has been fixed it Android T, but 34 -- we support ingesting traces from older Android versions. 35 CASE 36 -- cmdline gets rewritten after fork, if these are still there we must 37 -- have seen a racy capture. 38 WHEN length(process.name) = 15 AND ( 39 process.cmdline IN ('zygote', 'zygote64', '<pre-initialized>') 40 OR process.cmdline GLOB '*' || process.name) 41 THEN process.cmdline 42 ELSE process.name 43 END AS process_name, 44 process.android_appid AS uid, 45 CASE WHEN internal_uid_package_count.cnt > 1 THEN TRUE ELSE NULL END AS shared_uid, 46 plist.package_name, 47 plist.version_code, 48 plist.debuggable 49FROM process 50LEFT JOIN internal_uid_package_count ON process.android_appid = internal_uid_package_count.uid 51LEFT JOIN package_list plist 52 ON ( 53 ( 54 process.android_appid = plist.uid 55 AND internal_uid_package_count.uid = plist.uid 56 AND ( 57 -- unique match 58 internal_uid_package_count.cnt = 1 59 -- or process name starts with the package name 60 OR process.name GLOB plist.package_name || '*') 61 ) 62 OR 63 ( 64 -- isolated processes can only be matched based on the name prefix 65 process.android_appid >= 90000 AND process.android_appid < 100000 66 AND STR_SPLIT(process.name, ':', 0) GLOB plist.package_name || '*' 67 ) 68 ); 69