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 {LONG} from '../../trace_processor/query_result'; 16import {PerfettoPlugin} from '../../public/plugin'; 17import {Trace} from '../../public/trace'; 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 = 'com.android.InputEvents'; 24 static readonly dependencies = [StandardGroupsPlugin]; 25 26 async onTraceLoad(ctx: Trace): Promise<void> { 27 const cnt = await ctx.engine.query(` 28 SELECT 29 count(*) as cnt 30 FROM slice 31 WHERE name GLOB 'UnwantedInteractionBlocker::notifyMotion*' 32 `); 33 if (cnt.firstRow({cnt: LONG}).cnt == 0n) { 34 return; 35 } 36 37 const SQL_SOURCE = ` 38 SELECT 39 read_time as ts, 40 end_to_end_latency_dur as dur, 41 CONCAT(event_type, ' ', event_action, ': ', process_name, ' (', input_event_id, ')') as name 42 FROM android_input_events 43 WHERE end_to_end_latency_dur IS NOT NULL 44 `; 45 46 await ctx.engine.query('INCLUDE PERFETTO MODULE android.input;'); 47 const uri = 'com.android.InputEvents#InputEventsTrack'; 48 const title = 'Input Events'; 49 const track = await createQuerySliceTrack({ 50 trace: ctx, 51 uri, 52 data: { 53 sqlSource: SQL_SOURCE, 54 }, 55 }); 56 ctx.tracks.registerTrack({ 57 uri, 58 title: title, 59 track, 60 }); 61 const node = new TrackNode({uri, title}); 62 const group = ctx.plugins 63 .getPlugin(StandardGroupsPlugin) 64 .getOrCreateStandardGroup(ctx.workspace, 'USER_INTERACTION'); 65 group.addChildInOrder(node); 66 } 67} 68