1// Copyright (C) 2021 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 {TrackNode} from '../../public/workspace'; 16import {COUNTER_TRACK_KIND} from '../../public/track_kinds'; 17import {Trace} from '../../public/trace'; 18import {PerfettoPlugin} from '../../public/plugin'; 19import {NUM} from '../../trace_processor/query_result'; 20import {TraceProcessorCounterTrack} from '../dev.perfetto.TraceProcessorTrack/trace_processor_counter_track'; 21import TraceProcessorTrackPlugin from '../dev.perfetto.TraceProcessorTrack/index'; 22 23export default class implements PerfettoPlugin { 24 static readonly id = 'dev.perfetto.GpuFreq'; 25 static readonly dependencies = [TraceProcessorTrackPlugin]; 26 27 async onTraceLoad(ctx: Trace): Promise<void> { 28 const result = await ctx.engine.query(` 29 select id, gpu_id as gpuId 30 from gpu_counter_track 31 join _counter_track_summary using (id) 32 where name = 'gpufreq' 33 `); 34 const it = result.iter({id: NUM, gpuId: NUM}); 35 for (; it.valid(); it.next()) { 36 const uri = `/gpu_frequency_${it.gpuId}`; 37 const name = `Gpu ${it.gpuId} Frequency`; 38 ctx.tracks.registerTrack({ 39 uri, 40 title: name, 41 tags: { 42 kind: COUNTER_TRACK_KIND, 43 trackIds: [it.id], 44 }, 45 track: new TraceProcessorCounterTrack(ctx, uri, {}, it.id, name), 46 }); 47 const track = new TrackNode({uri, title: name, sortOrder: -20}); 48 ctx.workspace.addChildInOrder(track); 49 } 50 } 51} 52