1// Copyright (C) 2024 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {Plugin, PluginContextTrace, PluginDescriptor} from '../../public'; 16 17// List of tracks to pin 18const TRACKS_TO_PIN: string[] = [ 19 'Actual Timeline', 20 'Expected Timeline', 21 'ndroid.systemui', 22 'IKeyguardService', 23 'Transition:', 24 'L<', 25 'UI Events', 26]; 27const SYSTEM_UI_PROCESS: string = 'com.android.systemui'; 28 29// Plugin that pins the tracks relevant to System UI 30class PinSysUITracks implements Plugin { 31 async onTraceLoad(ctx: PluginContextTrace): Promise<void> { 32 ctx.registerCommand({ 33 id: 'dev.perfetto.PinSysUITracks#PinSysUITracks', 34 name: 'Pin: System UI Related Tracks', 35 callback: () => { 36 ctx.timeline.pinTracksByPredicate((tags) => { 37 return !!( 38 TRACKS_TO_PIN.some((trackName) => 39 tags.name?.startsWith(trackName), 40 ) && tags.groupName?.startsWith(SYSTEM_UI_PROCESS) 41 ); 42 }); 43 44 // expand the sysui process tracks group 45 ctx.timeline.expandGroupsByPredicate((groupRef) => { 46 return groupRef.displayName?.startsWith(SYSTEM_UI_PROCESS) ?? false; 47 }); 48 }, 49 }); 50 } 51} 52 53export const plugin: PluginDescriptor = { 54 pluginId: 'dev.perfetto.PinSysUITracks', 55 plugin: PinSysUITracks, 56}; 57