• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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 {TrackNode} from '../../public/workspace';
16import {NUM} from '../../trace_processor/query_result';
17import {Trace} from '../../public/trace';
18import {PerfettoPlugin} from '../../public/plugin';
19import {createScreenshotsTrack} from './screenshots_track';
20
21export default class implements PerfettoPlugin {
22  static readonly id = 'dev.perfetto.Screenshots';
23  async onTraceLoad(ctx: Trace): Promise<void> {
24    const res = await ctx.engine.query(`
25      INCLUDE PERFETTO MODULE android.screenshots;
26      select
27        count() as count
28      from android_screenshots
29    `);
30    const {count} = res.firstRow({count: NUM});
31
32    if (count > 0) {
33      const title = 'Screenshots';
34      const uri = '/screenshots';
35      ctx.tracks.registerTrack({
36        uri,
37        title,
38        track: createScreenshotsTrack(ctx, uri),
39      });
40      const trackNode = new TrackNode({uri, title, sortOrder: -60});
41      ctx.workspace.addChildInOrder(trackNode);
42    }
43  }
44}
45