xref: /aosp_15_r20/external/perfetto/ui/src/plugins/com.google.android.GoogleCamera/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 {Trace} from '../../public/trace';
16import {PerfettoPlugin} from '../../public/plugin';
17import * as cameraConstants from './googleCameraConstants';
18
19export default class implements PerfettoPlugin {
20  static readonly id = 'com.google.android.GoogleCamera';
21  async onTraceLoad(ctx: Trace): Promise<void> {
22    ctx.commands.registerCommand({
23      id: 'com.google.android.GoogleCamera#LoadGoogleCameraStartupView',
24      name: 'Load google camera startup view',
25      callback: () => {
26        this.loadGCAStartupView(ctx);
27      },
28    });
29
30    ctx.commands.registerCommand({
31      id: 'com.google.android.GoogleCamera#PinCameraRelatedTracks',
32      name: 'Pin camera related tracks',
33      callback: (trackNames) => {
34        trackNames = prompt(
35          'List of additional track names that you would like to pin separated by commas',
36          '',
37        );
38        const trackNameList = trackNames.split(',').map(function (
39          item: string,
40        ) {
41          return item.trim();
42        });
43        this.pinTracks(ctx, trackNameList);
44      },
45    });
46  }
47
48  private loadGCAStartupView(ctx: Trace) {
49    this.pinTracks(ctx, cameraConstants.MAIN_THREAD_TRACK);
50    this.pinTracks(ctx, cameraConstants.STARTUP_RELATED_TRACKS);
51  }
52
53  private pinTracks(ctx: Trace, trackNames: ReadonlyArray<string>) {
54    ctx.workspace.flatTracks.forEach((track) => {
55      trackNames.forEach((trackName) => {
56        if (track.title.match(trackName)) {
57          track.pin();
58        }
59      });
60    });
61  }
62}
63