ui: Delegate /heapdump route through HeapDumpExplorerPlugin to avoid double registration HeapDumpExplorerPlugin.onTraceLoad runs before MemscopePlugin.onTraceLoad (since Memscope depends on HeapDumpExplorer), so isPluginEnabled for Memscope returned false during HDE load and both plugins registered /heapdump. Have HeapDumpExplorerPlugin register /heapdump once and expose setUnifiedHost(renderer) so MemscopePlugin can take over rendering of /heapdump and hide HDE's standalone sidebar item cleanly.
diff --git a/ui/src/plugins/com.android.HeapDumpExplorer/index.ts b/ui/src/plugins/com.android.HeapDumpExplorer/index.ts index 352d7e7..c786316 100644 --- a/ui/src/plugins/com.android.HeapDumpExplorer/index.ts +++ b/ui/src/plugins/com.android.HeapDumpExplorer/index.ts
@@ -37,6 +37,7 @@ private readonly session: HeapDumpExplorerSession; private _hasHeapDumps = false; private _restoredFromPermalink = false; + private unifiedHostRenderer?: (subpage: string | undefined) => m.Children; static onActivate(app: App) { HeapDumpExplorerPlugin.defaultFlamegraphSetting = app.settings.register({ @@ -94,6 +95,13 @@ return this.session.selectDumpForProcess(upid, preferredTs) !== undefined; } + // Lets a unified host plugin (e.g. Memscope) take over rendering of the + // /heapdump route and hide the standalone Heapdump Explorer sidebar item + // without causing a duplicate /heapdump page registration. + setUnifiedHost(renderer: (subpage: string | undefined) => m.Children): void { + this.unifiedHostRenderer = renderer; + } + // Change which heap dump we're looking at from another plugin updateHeadDump(upid: number, ts: time): void { const dump = this.session.dumps.find((d) => d.upid === upid && d.ts === ts); @@ -118,16 +126,12 @@ session.openFlamegraph({pathHashes, isDominator, upid, ts}), ); - // When the Memory Workbench (Memscope) plugin is active, it embeds the - // Heap Dump Explorer lenses directly in the unified scope rail and owns - // the single Memory sidebar entry and routing (including #!/heapdump). - if (ctx.plugins.isPluginEnabled('dev.perfetto.Memscope')) { - return; - } - ctx.pages.registerPage({ route: '/heapdump', - render: (subpage) => m(HeapDumpPage, {session, subpage}), + render: (subpage) => + this.unifiedHostRenderer !== undefined + ? this.unifiedHostRenderer(subpage) + : m(HeapDumpPage, {session, subpage}), }); if (restored) { @@ -149,6 +153,7 @@ text: 'Heapdump Explorer', href: '#!/heapdump', icon: 'memory', + hidden: () => this.unifiedHostRenderer !== undefined, }); } }
diff --git a/ui/src/plugins/dev.perfetto.Memscope/index.ts b/ui/src/plugins/dev.perfetto.Memscope/index.ts index b39e2dd..06bb41e 100644 --- a/ui/src/plugins/dev.perfetto.Memscope/index.ts +++ b/ui/src/plugins/dev.perfetto.Memscope/index.ts
@@ -277,27 +277,36 @@ render: renderFromMemoryRoute, }); - // Legacy /heapdump alias (bookmarks, permalinks, HeapProfile timeline drill-down). - trace.pages.registerPage({ - route: '/heapdump', - render: (subpage) => { - const upid = hdeSession?.activeDump?.upid ?? bestUpid; - if (upid === undefined) { - return m(EmptyState, { - icon: 'memory', - title: 'No processes with memory data in this trace', - }); - } - const cleanedSubpage = subpage?.startsWith('/') - ? subpage.slice(1) - : subpage; - return renderWorkbench({ - upid, - section: 'heap', - hdeSubpage: cleanedSubpage || undefined, + // Legacy /heapdump alias (bookmarks, permalinks, HeapProfile timeline + // drill-down): delegate through HeapDumpExplorerPlugin when it registered + // /heapdump so we never double-register the route, and hide its standalone + // sidebar entry. + const renderHeapdumpAlias = (subpage: string | undefined): m.Children => { + const upid = hdeSession?.activeDump?.upid ?? bestUpid; + if (upid === undefined) { + return m(EmptyState, { + icon: 'memory', + title: 'No processes with memory data in this trace', }); - }, - }); + } + const cleanedSubpage = subpage?.startsWith('/') + ? subpage.slice(1) + : subpage; + return renderWorkbench({ + upid, + section: 'heap', + hdeSubpage: cleanedSubpage || undefined, + }); + }; + + if (hdePlugin.hasHeapDumps()) { + hdePlugin.setUnifiedHost(renderHeapdumpAlias); + } else { + trace.pages.registerPage({ + route: '/heapdump', + render: renderHeapdumpAlias, + }); + } if ( availability.hasSmapsSnapshots ||