Skip to content

Commit 32dc50d

Browse files
chore(memory): update names and exposed information (#2079)
Update the tools to all include the `heapsnapshot` term for easier handling. Renames UID to ID to reduce confusion with the snapshot UIDs. Renames Id to NodeId to better differentiate from the base Id. Remove EdgeIndex as it was not useful. Closes: #1970
1 parent 2a79b42 commit 32dc50d

13 files changed

Lines changed: 272 additions & 195 deletions

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
515515
- [`screencast_start`](docs/tool-reference.md#screencast_start)
516516
- [`screencast_stop`](docs/tool-reference.md#screencast_stop)
517517
- **Memory** (5 tools)
518-
- [`take_memory_snapshot`](docs/tool-reference.md#take_memory_snapshot)
519-
- [`get_memory_snapshot_details`](docs/tool-reference.md#get_memory_snapshot_details)
520-
- [`get_node_retainers`](docs/tool-reference.md#get_node_retainers)
521-
- [`get_nodes_by_class`](docs/tool-reference.md#get_nodes_by_class)
522-
- [`load_memory_snapshot`](docs/tool-reference.md#load_memory_snapshot)
518+
- [`take_heapsnapshot`](docs/tool-reference.md#take_heapsnapshot)
519+
- [`get_heapsnapshot_class_nodes`](docs/tool-reference.md#get_heapsnapshot_class_nodes)
520+
- [`get_heapsnapshot_details`](docs/tool-reference.md#get_heapsnapshot_details)
521+
- [`get_heapsnapshot_retainers`](docs/tool-reference.md#get_heapsnapshot_retainers)
522+
- [`get_heapsnapshot_summary`](docs/tool-reference.md#get_heapsnapshot_summary)
523523
- **Extensions** (5 tools)
524524
- [`install_extension`](docs/tool-reference.md#install_extension)
525525
- [`list_extensions`](docs/tool-reference.md#list_extensions)

docs/tool-reference.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
- [`screencast_start`](#screencast_start)
4141
- [`screencast_stop`](#screencast_stop)
4242
- **[Memory](#memory)** (5 tools)
43-
- [`take_memory_snapshot`](#take_memory_snapshot)
44-
- [`get_memory_snapshot_details`](#get_memory_snapshot_details)
45-
- [`get_node_retainers`](#get_node_retainers)
46-
- [`get_nodes_by_class`](#get_nodes_by_class)
47-
- [`load_memory_snapshot`](#load_memory_snapshot)
43+
- [`take_heapsnapshot`](#take_heapsnapshot)
44+
- [`get_heapsnapshot_class_nodes`](#get_heapsnapshot_class_nodes)
45+
- [`get_heapsnapshot_details`](#get_heapsnapshot_details)
46+
- [`get_heapsnapshot_retainers`](#get_heapsnapshot_retainers)
47+
- [`get_heapsnapshot_summary`](#get_heapsnapshot_summary)
4848
- **[Extensions](#extensions)** (5 tools)
4949
- [`install_extension`](#install_extension)
5050
- [`list_extensions`](#list_extensions)
@@ -443,7 +443,7 @@ in the DevTools Elements panel (if any).
443443

444444
## Memory
445445

446-
### `take_memory_snapshot`
446+
### `take_heapsnapshot`
447447

448448
**Description:** Capture a heap snapshot of the currently selected page. Use to analyze the memory distribution of JavaScript objects and debug memory leaks.
449449

@@ -453,45 +453,45 @@ in the DevTools Elements panel (if any).
453453

454454
---
455455

456-
### `get_memory_snapshot_details`
456+
### `get_heapsnapshot_class_nodes`
457457

458-
**Description:** Loads a memory heapsnapshot and returns all available information including statistics, static data, and aggregated node information. Supports pagination for aggregates. (requires flag: --experimentalMemory=true)
458+
**Description:** Loads a memory heapsnapshot and returns instances of a specific class with their IDs. (requires flag: --experimentalMemory=true)
459459

460460
**Parameters:**
461461

462462
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
463-
- **pageIdx** (number) _(optional)_: The page index for pagination of aggregates.
464-
- **pageSize** (number) _(optional)_: The page size for pagination of aggregates.
463+
- **id** (number) **(required)**: The ID for the class, obtained from details.
464+
- **pageIdx** (number) _(optional)_: The page index for pagination.
465+
- **pageSize** (number) _(optional)_: The page size for pagination.
465466

466467
---
467468

468-
### `get_node_retainers`
469+
### `get_heapsnapshot_details`
469470

470-
**Description:** Loads a memory heapsnapshot and returns retainers for a specific node ID. (requires flag: --experimentalMemory=true)
471+
**Description:** Loads a memory heapsnapshot and returns all available information including statistics, static data, and aggregated node information. Supports pagination for aggregates. (requires flag: --experimentalMemory=true)
471472

472473
**Parameters:**
473474

474475
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
475-
- **nodeId** (number) **(required)**: The stable node ID to get retainers for.
476-
- **pageIdx** (number) _(optional)_: The page index for pagination.
477-
- **pageSize** (number) _(optional)_: The page size for pagination.
476+
- **pageIdx** (number) _(optional)_: The page index for pagination of aggregates.
477+
- **pageSize** (number) _(optional)_: The page size for pagination of aggregates.
478478

479479
---
480480

481-
### `get_nodes_by_class`
481+
### `get_heapsnapshot_retainers`
482482

483-
**Description:** Loads a memory heapsnapshot and returns instances of a specific class with their stable IDs. (requires flag: --experimentalMemory=true)
483+
**Description:** Loads a memory heapsnapshot and returns retainers for a specific node ID. (requires flag: --experimentalMemory=true)
484484

485485
**Parameters:**
486486

487487
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
488-
- **uid** (number) **(required)**: The unique UID for the class, obtained from aggregates listing.
488+
- **nodeId** (number) **(required)**: The node ID to get retainers for.
489489
- **pageIdx** (number) _(optional)_: The page index for pagination.
490490
- **pageSize** (number) _(optional)_: The page size for pagination.
491491

492492
---
493493

494-
### `load_memory_snapshot`
494+
### `get_heapsnapshot_summary`
495495

496496
**Description:** Loads a memory heapsnapshot and returns snapshot summary stats. (requires flag: --experimentalMemory=true)
497497

src/HeapSnapshotManager.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
type WithSymbolId,
1616
} from './utils/id.js';
1717

18-
export type AggregatedInfoWithUid =
18+
export type AggregatedInfoWithId =
1919
WithSymbolId<DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>;
2020

2121
export class HeapSnapshotManager {
@@ -25,8 +25,8 @@ export class HeapSnapshotManager {
2525
snapshot: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotProxy;
2626
worker: DevTools.HeapSnapshotModel.HeapSnapshotProxy.HeapSnapshotWorkerProxy;
2727
// TODO: use a multimap
28-
uidToClassKey: Map<number, string>;
29-
classKeyToUid: Map<string, number>;
28+
idToClassKey: Map<number, string>;
29+
classKeyToId: Map<string, number>;
3030
idGenerator: () => number;
3131
}
3232
>();
@@ -44,8 +44,8 @@ export class HeapSnapshotManager {
4444
this.#snapshots.set(absolutePath, {
4545
snapshot,
4646
worker,
47-
uidToClassKey: new Map<number, string>(),
48-
classKeyToUid: new Map<string, number>(),
47+
idToClassKey: new Map<number, string>(),
48+
classKeyToId: new Map<string, number>(),
4949
idGenerator: createIdGenerator(),
5050
});
5151

@@ -54,18 +54,18 @@ export class HeapSnapshotManager {
5454

5555
async getAggregates(
5656
filePath: string,
57-
): Promise<Record<string, AggregatedInfoWithUid>> {
57+
): Promise<Record<string, AggregatedInfoWithId>> {
5858
const snapshot = await this.getSnapshot(filePath);
5959
const filter =
6060
new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
61-
const aggregates: Record<string, AggregatedInfoWithUid> =
61+
const aggregates: Record<string, AggregatedInfoWithId> =
6262
await snapshot.aggregatesWithFilter(filter);
6363

6464
for (const key of Object.keys(aggregates)) {
65-
const uid = await this.getOrCreateUidForClassKey(filePath, key);
65+
const id = await this.getOrCreateIdForClassKey(filePath, key);
6666
const aggregate = aggregates[key];
6767
if (aggregate) {
68-
aggregate[stableIdSymbol] = uid;
68+
aggregate[stableIdSymbol] = id;
6969
}
7070
}
7171

@@ -86,30 +86,30 @@ export class HeapSnapshotManager {
8686
return snapshot.staticData;
8787
}
8888

89-
async getOrCreateUidForClassKey(
89+
async getOrCreateIdForClassKey(
9090
filePath: string,
9191
classKey: string,
9292
): Promise<number> {
9393
const cached = this.#getCachedSnapshot(filePath);
94-
let uid = cached.classKeyToUid.get(classKey);
95-
if (!uid) {
96-
uid = cached.idGenerator();
97-
cached.classKeyToUid.set(classKey, uid);
98-
cached.uidToClassKey.set(uid, classKey);
94+
let id = cached.classKeyToId.get(classKey);
95+
if (!id) {
96+
id = cached.idGenerator();
97+
cached.classKeyToId.set(classKey, id);
98+
cached.idToClassKey.set(id, classKey);
9999
}
100-
return uid;
100+
return id;
101101
}
102102

103-
async getNodesByUid(
103+
async getNodesById(
104104
filePath: string,
105-
uid: number,
105+
id: number,
106106
): Promise<DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange> {
107107
const snapshot = await this.getSnapshot(filePath);
108108
const filter =
109109
new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
110-
const className = await this.resolveClassKeyFromUid(filePath, uid);
110+
const className = await this.resolveClassKeyFromId(filePath, id);
111111
if (!className) {
112-
throw new Error(`Class with UID ${uid} not found in heap snapshot`);
112+
throw new Error(`Class with ID ${id} not found in heap snapshot`);
113113
}
114114
const provider = snapshot.createNodesProviderForClass(className, filter);
115115

@@ -159,12 +159,12 @@ export class HeapSnapshotManager {
159159
return cached;
160160
}
161161

162-
async resolveClassKeyFromUid(
162+
async resolveClassKeyFromId(
163163
filePath: string,
164-
uid: number,
164+
id: number,
165165
): Promise<string | undefined> {
166166
const cached = this.#getCachedSnapshot(filePath);
167-
return cached.uidToClassKey.get(uid);
167+
return cached.idToClassKey.get(id);
168168
}
169169

170170
async #loadSnapshot(absolutePath: string): Promise<{

src/McpContext.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {fileURLToPath, pathToFileURL} from 'node:url';
1212
import type {TargetUniverse} from './DevtoolsUtils.js';
1313
import {UniverseManager} from './DevtoolsUtils.js';
1414
import {HeapSnapshotManager} from './HeapSnapshotManager.js';
15-
import type {AggregatedInfoWithUid} from './HeapSnapshotManager.js';
15+
import type {AggregatedInfoWithId} from './HeapSnapshotManager.js';
1616
import {McpPage} from './McpPage.js';
1717
import {
1818
NetworkCollector,
@@ -804,7 +804,7 @@ export class McpContext implements Context {
804804

805805
async getHeapSnapshotAggregates(
806806
filePath: string,
807-
): Promise<Record<string, AggregatedInfoWithUid>> {
807+
): Promise<Record<string, AggregatedInfoWithId>> {
808808
this.validatePath(filePath);
809809
return await this.#heapSnapshotManager.getAggregates(filePath);
810810
}
@@ -823,12 +823,12 @@ export class McpContext implements Context {
823823
return await this.#heapSnapshotManager.getStaticData(filePath);
824824
}
825825

826-
async getHeapSnapshotNodesByUid(
826+
async getHeapSnapshotNodesById(
827827
filePath: string,
828-
uid: number,
828+
id: number,
829829
): Promise<DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange> {
830830
this.validatePath(filePath);
831-
return await this.#heapSnapshotManager.getNodesByUid(filePath, uid);
831+
return await this.#heapSnapshotManager.getNodesById(filePath, id);
832832
}
833833

834834
async getHeapSnapshotRetainers(

0 commit comments

Comments
 (0)