blob: 3b9cd00862ce4d2336dc286021f12fdef6bddd3a [file]
// Copyright (C) 2026 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 m from 'mithril';
import {PerfettoPlugin} from '../../public/plugin';
import {Trace} from '../../public/trace';
import {NUM} from '../../trace_processor/query_result';
import HeapProfilePlugin from '../dev.perfetto.HeapProfile';
import {HeapDumpPage} from './heap_dump_page';
import {HeapDumpExplorerSession} from './session';
export default class implements PerfettoPlugin {
static readonly id = 'com.android.HeapDumpExplorer';
static readonly dependencies = [HeapProfilePlugin];
async onTraceLoad(ctx: Trace): Promise<void> {
const res = await ctx.engine.query(
'SELECT count(*) AS cnt FROM heap_graph_object LIMIT 1',
);
if (res.iter({cnt: NUM}).cnt === 0) return;
const session = new HeapDumpExplorerSession(ctx, ctx.engine);
await session.loadDumps();
ctx.pages.registerPage({
route: '/heapdump',
render: (subpage) => m(HeapDumpPage, {session, subpage}),
});
ctx.plugins
.getPlugin(HeapProfilePlugin)
.registerOnNodeSelectedListener(({pathHashes, isDominator, upid, ts}) =>
session.openFlamegraph({pathHashes, isDominator, upid, ts}),
);
ctx.sidebar.addMenuItem({
section: 'current_trace',
sortOrder: 30,
text: 'Heapdump Explorer',
href: '#!/heapdump',
icon: 'memory',
});
}
}