1-- 2-- Copyright 2023 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 17CREATE PERFETTO FUNCTION _remove_lambda_name( 18-- Raw slice name containing at least one "$" 19 name STRING) 20-- Removes everything after the first "$" 21RETURNS STRING AS 22SELECT 23 substr($name, 0, instr($name, "$")) 24END; 25 26-- Some slice names have params in them. This functions removes them to make it 27-- possible to aggregate by name. 28-- Some examples are: 29-- - Lock/monitor contention slices. The name includes where the lock 30-- contention is in the code. That part is removed. 31-- - DrawFrames/ooFrame. The name also includes the frame number. 32-- - Apk/oat/dex loading: The name of the apk is removed 33CREATE PERFETTO FUNCTION android_standardize_slice_name( 34 -- The raw slice name. 35 name STRING) 36-- Simplified name. 37RETURNS STRING AS 38SELECT 39 CASE 40 WHEN $name GLOB "monitor contention with*" THEN "monitor contention with <...>" 41 WHEN $name GLOB "SuspendThreadByThreadId*" THEN "SuspendThreadByThreadId <...>" 42 WHEN $name GLOB "LoadApkAssetsFd*" THEN "LoadApkAssetsFd <...>" 43 WHEN $name GLOB "relayoutWindow*" THEN "relayoutWindow <...>" 44 WHEN $name GLOB "android.os.Handler: kotlinx.coroutines*" THEN "CoroutineContinuation" 45 WHEN $name GLOB "Choreographer#doFrame*" THEN "Choreographer#doFrame" 46 WHEN $name GLOB "DrawFrames*" THEN "DrawFrames" 47 WHEN $name GLOB "/data/app*.apk" THEN "APK load" 48 WHEN $name GLOB "OpenDexFilesFromOat*" THEN "OpenDexFilesFromOat" 49 WHEN $name GLOB "Open oat file*" THEN "Open oat file" 50 WHEN $name GLOB "GC: Wait For*" THEN "Garbage Collector" 51 -- E.g. Lock contention on thread list lock (owner tid: 1665) 52 -- To: Lock contention on thread list lock <...> 53 WHEN $name GLOB "Lock contention on* (*" THEN substr($name, 0, instr($name, "(")) || "<...>" 54 -- Top level handlers slices heuristics: 55 -- E.g. android.os.Handler: com.android.systemui.qs.external.TileServiceManager$1 56 -- To: Handler: com.android.systemui.qs.external.TileServiceManager 57 WHEN $name GLOB "*Handler: *$*" THEN _remove_lambda_name(substr($name, instr($name, "Handler:"))) 58 -- E.g. : android.view.ViewRootImpl$ViewRootHandler: com.android.systemui.someClass$enableMarquee$1 59 -- To: Handler: android.view.ViewRootImpl 60 WHEN $name GLOB "*.*.*: *$*" THEN "Handler: " || _remove_lambda_name(substr($name, ": ")) 61 -- E.g.: android.os.AsyncTask$InternalHandler: #1 62 -- To: Handler: android.os.AsyncTask 63 WHEN $name GLOB "*.*$*: #*" THEN "Handler: " || _remove_lambda_name($name) 64 ELSE $name 65 END; 66