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 { 16 Plugin, 17 PluginContext, 18 PluginContextTrace, 19 PluginDescriptor, 20 addDebugSliceTrack, 21} from '../../public'; 22 23class Chaos implements Plugin { 24 onActivate(ctx: PluginContext): void { 25 ctx.registerCommand({ 26 id: 'dev.perfetto.Chaos#CrashNow', 27 name: 'Chaos: crash now', 28 callback: () => { 29 throw new Error('Manual crash from dev.perfetto.Chaos#CrashNow'); 30 }, 31 }); 32 } 33 34 async onTraceLoad(ctx: PluginContextTrace): Promise<void> { 35 ctx.registerCommand({ 36 id: 'dev.perfetto.Chaos#CrashNowQuery', 37 name: 'Chaos: run crashing query', 38 callback: () => { 39 ctx.engine.query(`this is a 40 syntactically 41 invalid 42 query 43 over 44 many 45 lines 46 `); 47 }, 48 }); 49 50 ctx.registerCommand({ 51 id: 'dev.perfetto.Chaos#AddCrashingDebugTrack', 52 name: 'Chaos: add crashing debug track', 53 callback: () => { 54 addDebugSliceTrack( 55 ctx, 56 { 57 sqlSource: ` 58 syntactically 59 invalid 60 query 61 over 62 many 63 `, 64 }, 65 `Chaos track`, 66 {ts: 'ts', dur: 'dur', name: 'name'}, 67 [], 68 ); 69 }, 70 }); 71 } 72 73 async onTraceUnload(_: PluginContextTrace): Promise<void> {} 74 75 onDeactivate(_: PluginContext): void {} 76} 77 78export const plugin: PluginDescriptor = { 79 pluginId: 'dev.perfetto.Chaos', 80 plugin: Chaos, 81}; 82