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 {Trace} from '../../public/trace'; 16import {App} from '../../public/app'; 17import {addDebugSliceTrack} from '../../components/tracks/debug_tracks'; 18import {PerfettoPlugin} from '../../public/plugin'; 19 20export default class implements PerfettoPlugin { 21 static readonly id = 'dev.perfetto.Chaos'; 22 23 static onActivate(ctx: App): void { 24 ctx.commands.registerCommand({ 25 id: 'dev.perfetto.Chaos#CrashNow', 26 name: 'Chaos: crash now', 27 callback: () => { 28 throw new Error('Manual crash from dev.perfetto.Chaos#CrashNow'); 29 }, 30 }); 31 } 32 33 async onTraceLoad(ctx: Trace): Promise<void> { 34 ctx.commands.registerCommand({ 35 id: 'dev.perfetto.Chaos#CrashNowQuery', 36 name: 'Chaos: run crashing query', 37 callback: () => { 38 ctx.engine.query(`this is a 39 syntactically 40 invalid 41 query 42 over 43 many 44 lines 45 `); 46 }, 47 }); 48 49 ctx.commands.registerCommand({ 50 id: 'dev.perfetto.Chaos#AddCrashingDebugTrack', 51 name: 'Chaos: add crashing debug track', 52 callback: () => { 53 addDebugSliceTrack({ 54 trace: ctx, 55 data: { 56 sqlSource: ` 57 syntactically 58 invalid 59 query 60 over 61 many 62 `, 63 }, 64 title: `Chaos track`, 65 }); 66 }, 67 }); 68 } 69} 70