xref: /aosp_15_r20/external/perfetto/ui/src/core_plugins/example_traces/index.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 {AppImpl} from '../../core/app_impl';
16import {App} from '../../public/app';
17import {PerfettoPlugin} from '../../public/plugin';
18
19const EXAMPLE_ANDROID_TRACE_URL =
20  'https://storage.googleapis.com/perfetto-misc/example_android_trace_15s';
21
22const EXAMPLE_CHROME_TRACE_URL =
23  'https://storage.googleapis.com/perfetto-misc/chrome_example_wikipedia.perfetto_trace.gz';
24
25function openTraceUrl(app: App, url: string): void {
26  app.analytics.logEvent('Trace Actions', 'Open example trace');
27  AppImpl.instance.openTraceFromUrl(url);
28}
29
30export default class implements PerfettoPlugin {
31  static readonly id = 'perfetto.ExampleTraces';
32  static onActivate(ctx: App) {
33    const OPEN_EXAMPLE_ANDROID_TRACE_COMMAND_ID =
34      'perfetto.CoreCommands#openExampleAndroidTrace';
35    ctx.commands.registerCommand({
36      id: OPEN_EXAMPLE_ANDROID_TRACE_COMMAND_ID,
37      name: 'Open Android example',
38      callback: () => {
39        openTraceUrl(ctx, EXAMPLE_ANDROID_TRACE_URL);
40      },
41    });
42    ctx.sidebar.addMenuItem({
43      section: 'example_traces',
44      commandId: OPEN_EXAMPLE_ANDROID_TRACE_COMMAND_ID,
45      icon: 'description',
46    });
47
48    const OPEN_EXAMPLE_CHROME_TRACE_COMMAND_ID =
49      'perfetto.CoreCommands#openExampleChromeTrace';
50    ctx.commands.registerCommand({
51      id: OPEN_EXAMPLE_CHROME_TRACE_COMMAND_ID,
52      name: 'Open Chrome example',
53      callback: () => {
54        openTraceUrl(ctx, EXAMPLE_CHROME_TRACE_URL);
55      },
56    });
57    ctx.sidebar.addMenuItem({
58      section: 'example_traces',
59      commandId: OPEN_EXAMPLE_CHROME_TRACE_COMMAND_ID,
60      icon: 'description',
61    });
62  }
63}
64