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