blob: 1cc2a401885a759d266a2b6a1f8363a49a5c347a [file] [log] [blame]
// 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 {
SimpleSliceTrack,
SimpleSliceTrackConfig,
} from '../../frontend/simple_slice_track';
import {PerfettoPlugin} from '../../public/plugin';
import {Trace} from '../../public/trace';
import {TrackNode} from '../../public/workspace';
const INCLUDE_DESKTOP_MODULE_QUERY = `INCLUDE PERFETTO MODULE android.desktop_mode`;
const QUERY = `
SELECT
ROW_NUMBER() OVER (ORDER BY ts) AS id,
ts,
dur,
ifnull(p.package_name, 'uid=' || dw.uid) AS name
FROM android_desktop_mode_windows dw
LEFT JOIN package_list p ON CAST (dw.uid AS INT) % 100000 = p.uid AND p.uid != 1000
`;
const COLUMNS = ['id', 'ts', 'dur', 'name'];
const TRACK_NAME = 'Desktop Mode Windows';
const TRACK_URI = '/desktop_windows';
export default class implements PerfettoPlugin {
static readonly id = 'dev.perfetto.AndroidDesktopMode';
async onTraceLoad(ctx: Trace): Promise<void> {
ctx.addEventListener('traceready', async () => {
await ctx.engine.query(INCLUDE_DESKTOP_MODULE_QUERY);
this.registerTrack(ctx, QUERY);
ctx.commands.registerCommand({
id: 'dev.perfetto.DesktopMode#AddTrackDesktopWindowss',
name: 'Add Track: ' + TRACK_NAME,
callback: () => this.addSimpleTrack(ctx),
});
});
}
private registerTrack(_ctx: Trace, sql: string) {
const config: SimpleSliceTrackConfig = {
data: {
sqlSource: sql,
columns: COLUMNS,
},
columns: {ts: 'ts', dur: 'dur', name: 'name'},
argColumns: [],
};
const track = new SimpleSliceTrack(_ctx, {trackUri: TRACK_URI}, config);
_ctx.tracks.registerTrack({
uri: TRACK_URI,
title: TRACK_NAME,
track,
});
}
private addSimpleTrack(_ctx: Trace) {
const trackNode = new TrackNode({uri: TRACK_URI, title: TRACK_NAME});
_ctx.workspace.addChildInOrder(trackNode);
trackNode.pin();
}
}