• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {LONG, Plugin, PluginContextTrace, PluginDescriptor} from '../../public';
16import {
17  SimpleSliceTrack,
18  SimpleSliceTrackConfig,
19} from '../../frontend/simple_slice_track';
20
21class AndroidStartup implements Plugin {
22  async onTraceLoad(ctx: PluginContextTrace): Promise<void> {
23    const e = ctx.engine;
24    await e.query(`include perfetto module android.startup.startups;`);
25
26    const cnt = await e.query('select count() cnt from android_startups');
27    if (cnt.firstRow({cnt: LONG}).cnt === 0n) {
28      return;
29    }
30
31    const config: SimpleSliceTrackConfig = {
32      data: {
33        sqlSource: `
34          SELECT l.ts AS ts, l.dur AS dur, l.package AS name
35          FROM android_startups l
36        `,
37        columns: ['ts', 'dur', 'name'],
38      },
39      columns: {ts: 'ts', dur: 'dur', name: 'name'},
40      argColumns: [],
41    };
42    ctx.registerStaticTrack({
43      uri: `dev.perfetto.AndroidStartup#startups`,
44      displayName: 'Android App Startups',
45      trackFactory: (trackCtx) => {
46        return new SimpleSliceTrack(ctx.engine, trackCtx, config);
47      },
48    });
49  }
50}
51
52export const plugin: PluginDescriptor = {
53  pluginId: 'dev.perfetto.AndroidStartup',
54  plugin: AndroidStartup,
55};
56