| // Copyright (C) 2024 The Android Open Source Project | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| import type {Trace} from './trace'; | |
| import type {App} from './app'; | |
| import type {RouteArgs} from './route_schema'; | |
| /** | |
| * Indicates the maturity/stability of a plugin. | |
| * | |
| * - 'experimental': The plugin is in development and may contain unstable or | |
| * incomplete features. Users will see a warning when enabling such plugins. | |
| * - 'preview': The plugin is in preview and may contain unstable or | |
| * incomplete features. Users will see a warning when enabling such plugins. | |
| */ | |
| export type PluginStatus = 'experimental' | 'preview'; | |
| /** | |
| * This interface defines the shape of the plugins's class constructor (i.e. the | |
| * the constructor and all static members of the plugin's class. | |
| * | |
| * This class constructor is registered with the core. | |
| * | |
| * On trace load, the core will create a new class instance by calling new on | |
| * this constructor and then call its onTraceLoad() function. | |
| */ | |
| export interface PerfettoPluginStatic<T extends PerfettoPlugin> { | |
| readonly id: string; | |
| readonly description?: string; | |
| /** | |
| * Optional status flag indicating the maturity of this plugin. | |
| * When set to 'experimental' or 'preview', users will see a warning that | |
| * enabling this plugin may expose experimental or preview features. | |
| * Defaults to stable (no warning) when not specified. | |
| */ | |
| readonly status?: PluginStatus; | |
| readonly dependencies?: ReadonlyArray<PerfettoPluginStatic<PerfettoPlugin>>; | |
| onActivate?(app: App, args: RouteArgs): void; | |
| new (trace: Trace): T; | |
| } | |
| /** | |
| * This interface defines the shape of a plugin's trace-scoped instance, which | |
| * is created from the class constructor above at trace load time. | |
| */ | |
| export interface PerfettoPlugin { | |
| onTraceLoad?(ctx: Trace, args?: {[key: string]: unknown}): Promise<void>; | |
| } | |
| export interface PluginManager { | |
| getPlugin<T extends PerfettoPlugin>(plugin: PerfettoPluginStatic<T>): T; | |
| isPluginEnabled(id: string): boolean; | |
| } |