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 {createQueryCounterTrack} from '../../components/tracks/query_counter_track'; 16import {PerfettoPlugin} from '../../public/plugin'; 17import {Trace} from '../../public/trace'; 18import {TrackNode} from '../../public/workspace'; 19 20export default class implements PerfettoPlugin { 21 static readonly id = 'dev.perfetto.AndroidCounterTracks'; 22 23 async onTraceLoad(ctx: Trace): Promise<void> { 24 const {engine} = ctx; 25 26 await engine.query(`include perfetto module android.binder;`); 27 28 const counterTrackSource = ` 29 select client_ts as ts, count(*) value 30 from android_binder_txns 31 group by ts 32 `; 33 34 const trackNode = await this.loadCounterTrack( 35 ctx, 36 counterTrackSource, 37 '/android_counter_track', 38 'Android Counter Track', 39 ); 40 ctx.workspace.addChildFirst(trackNode); 41 } 42 43 private async loadCounterTrack( 44 ctx: Trace, 45 sqlSource: string, 46 uri: string, 47 title: string, 48 ) { 49 const track = await createQueryCounterTrack({ 50 trace: ctx, 51 uri, 52 data: { 53 sqlSource, 54 columns: ['ts', 'value'], 55 }, 56 }); 57 58 ctx.tracks.registerTrack({ 59 uri, 60 title, 61 track, 62 }); 63 64 return new TrackNode({title, uri, sortOrder: -7}); 65 } 66} 67