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 {NUM} from '../../trace_processor/query_result'; 16import {Trace} from '../../public/trace'; 17import {PerfettoPlugin} from '../../public/plugin'; 18import {createQuerySliceTrack} from '../../components/tracks/query_slice_track'; 19import {TrackNode} from '../../public/workspace'; 20import StandardGroupsPlugin from '../dev.perfetto.StandardGroups'; 21 22export default class implements PerfettoPlugin { 23 static readonly id = 'dev.perfetto.TraceMetadata'; 24 static readonly dependencies = [StandardGroupsPlugin]; 25 26 async onTraceLoad(ctx: Trace): Promise<void> { 27 const res = await ctx.engine.query(` 28 select count() as cnt from (select 1 from clock_snapshot limit 1) 29 `); 30 const row = res.firstRow({cnt: NUM}); 31 if (row.cnt === 0) { 32 return; 33 } 34 const uri = `/clock_snapshots`; 35 const title = 'Clock Snapshots'; 36 const track = await createQuerySliceTrack({ 37 trace: ctx, 38 uri, 39 data: { 40 sqlSource: ` 41 select ts, 0 as dur, 'Snapshot' as name 42 from clock_snapshot 43 `, 44 }, 45 }); 46 ctx.tracks.registerTrack({ 47 uri, 48 title, 49 track, 50 }); 51 const trackNode = new TrackNode({uri, title}); 52 const group = ctx.plugins 53 .getPlugin(StandardGroupsPlugin) 54 .getOrCreateStandardGroup(ctx.workspace, 'SYSTEM'); 55 group.addChildInOrder(trackNode); 56 } 57} 58