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