Skip to content

Chrome DevTools for coding agents

feat: Support truncation in get_heapsnapshot_details (#3137)

Dominik Inführf827e067b0ce
diff --git a/docs/tool-reference.md b/docs/tool-reference.md
index 40061bc7..b3168993 100644
--- a/docs/tool-reference.md
+++ b/docs/tool-reference.md
@@ -578,6 +578,7 @@ in the DevTools Elements panel (if any).
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to read.
- **filterName** (enum: "objectsRetainedByDetachedDomNodes", "objectsRetainedByConsole", "objectsRetainedByEventHandlers", "objectsRetainedByContexts", "sharedNativeContext", "noNativeContext", "attributedToSpecificNativeContext") _(optional)_: An optional filter to apply to the aggregates.
+- **maxNameLength** (integer) _(optional)_: Maximum length of names before truncation. Defaults to 100.
- **objectId** (number) _(optional)_: The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.
- **pageIdx** (number) _(optional)_: The page index for pagination of aggregates.
- **pageSize** (number) _(optional)_: The page size for pagination of aggregates.
diff --git a/src/McpResponse.ts b/src/McpResponse.ts
index 84e3b985..41111a13 100644
--- a/src/McpResponse.ts
+++ b/src/McpResponse.ts
@@ -378,13 +378,14 @@ export class McpResponse implements Response {
setHeapSnapshotAggregates(
aggregateData: HeapSnapshotAggregateData,
- options?: PaginationOptions,
+ options?: PaginationOptions & HeapSnapshotFormatOptions,
): void {
this.#heapSnapshotOptions = {
...this.#heapSnapshotOptions,
include: true,
aggregateData,
pagination: options,
+ formatOptions: options,
};
}
@@ -917,7 +918,7 @@ export class McpResponse implements Response {
totalSelfSize: number;
};
};
- heapSnapshotData?: object[];
+ heapSnapshotAggregates?: readonly object[];
heapSnapshotNodes?: readonly object[];
heapSnapshotRetainingPaths?: object;
heapSnapshotDominators?: readonly object[];
@@ -1355,12 +1356,8 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
}
const aggregateData = this.#heapSnapshotOptions.aggregateData;
if (aggregateData) {
- const sortedEntries = HeapSnapshotFormatter.sort(
- aggregateData.aggregates,
- );
-
const paginationData = this.#dataWithPagination(
- sortedEntries,
+ aggregateData.aggregates,
this.#heapSnapshotOptions.pagination,
);
@@ -1376,14 +1373,19 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
structuredContent.pagination = paginationData.pagination;
response.push(...paginationData.info);
- const paginatedRecord = Object.fromEntries(paginationData.items);
- const formatter = new HeapSnapshotFormatter(paginatedRecord);
-
- structuredContent.heapSnapshotData = formatter.toJSON();
+ structuredContent.heapSnapshotAggregates = paginationData.items;
response.push(
compactEncode
- ? compactEncode(structuredContent.heapSnapshotData)
- : formatter.toString(),
+ ? compactEncode(
+ paginationData.items.map(aggregate => ({
+ ...aggregate,
+ className: formatName(aggregate.className, formatOptions),
+ })),
+ )
+ : HeapSnapshotFormatter.formatAggregates(
+ paginationData.items,
+ formatOptions,
+ ),
);
}
const nodes = this.#heapSnapshotOptions.nodes;
diff --git a/src/config/cli-options.ts b/src/config/cli-options.ts
index c0a15d19..5db98bd3 100644
--- a/src/config/cli-options.ts
+++ b/src/config/cli-options.ts
@@ -629,6 +629,13 @@ export const commands: Commands = {
'The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.',
required: false,
},
+ maxNameLength: {
+ name: 'maxNameLength',
+ type: 'integer',
+ description:
+ 'Maximum length of names before truncation. Defaults to 100.',
+ required: false,
+ },
pageIdx: {
name: 'pageIdx',
type: 'number',
diff --git a/src/formatters/HeapSnapshotFormatter.ts b/src/formatters/HeapSnapshotFormatter.ts
index f87b90fc..245e4fbc 100644
--- a/src/formatters/HeapSnapshotFormatter.ts
+++ b/src/formatters/HeapSnapshotFormatter.ts
@@ -5,14 +5,13 @@
*/
import type {
- AggregatedInfoWithId,
+ HeapSnapshotAggregate,
HeapSnapshotClassDiff,
HeapSnapshotDetailedClassDiff,
DuplicateStringGroup,
} from '../processors/HeapSnapshotManager.js';
import {DevTools} from '../third_party/index.js';
import type {ByteSizeRange} from '../utils/bytes.js';
-import {stableIdSymbol} from '../utils/id.js';
const {formatBytesToKb} = DevTools.I18n.ByteUtilities;
@@ -49,14 +48,6 @@ function truncateValue(value: string, maxLength = MAX_NAME_LENGTH): string {
return value.slice(0, maxLength) + '...';
}
-export interface FormattedSnapshotEntry {
- className: string;
- id?: number;
- count: number;
- selfSize: string;
- retainedSize: string;
-}
-
export interface ContextAnalysisReport {
contexts: readonly ScopedContext[];
scriptsWithoutScopes: readonly DevTools.HeapSnapshotModel.HeapSnapshotModel.ScriptWithoutScopes[];
@@ -133,12 +124,6 @@ export function isEdgeLike(
}
export class HeapSnapshotFormatter {
- #aggregates: Record<string, AggregatedInfoWithId>;
-
- constructor(aggregates: Record<string, AggregatedInfoWithId>) {
- this.#aggregates = aggregates;
- }
-
static formatNodes(
items: ReadonlyArray<
| DevTools.HeapSnapshotModel.HeapSnapshotModel.Node
@@ -265,47 +250,22 @@ export class HeapSnapshotFormatter {
return lines.join('\n');
}
- #getSortedAggregates(): AggregatedInfoWithId[] {
- return Object.values(this.#aggregates).sort((a, b) => b.maxRet - a.maxRet);
- }
-
- toString(): string {
- const sorted = this.#getSortedAggregates();
+ static formatAggregates(
+ aggregates: readonly HeapSnapshotAggregate[],
+ options: HeapSnapshotFormatOptions,
+ ): string {
const lines: string[] = [];
- lines.push('id,name,count,selfSize,retainedSize');
+ lines.push('id,className,count,selfSize,retainedSize');
- for (const info of sorted) {
- const id = info[stableIdSymbol] ?? '';
+ for (const info of aggregates) {
lines.push(
- `${id},${info.name},${info.count},${formatBytesToKb(info.self)},${formatBytesToKb(info.maxRet)}`,
+ `${info.id},${formatName(info.className, options)},${info.count},${formatBytesToKb(info.selfSize)},${formatBytesToKb(info.retainedSize)}`,
);
}
return lines.join('\n');
}
- toJSON(): FormattedSnapshotEntry[] {
- const sorted = this.#getSortedAggregates();
- return sorted.map(info => ({
- id: info[stableIdSymbol],
- className: info.name,
- count: info.count,
- selfSize: formatBytesToKb(info.self),
- retainedSize: formatBytesToKb(info.maxRet),
- }));
- }
-
- static sort(
- aggregates: Record<
- string,
- DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo
- >,
- ): Array<
- [string, DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo]
- > {
- return Object.entries(aggregates).sort((a, b) => b[1].maxRet - a[1].maxRet);
- }
-
static formatDiffSummary(
diffs: HeapSnapshotClassDiff[],
options: HeapSnapshotFormatOptions,
diff --git a/src/processors/HeapSnapshotManager.ts b/src/processors/HeapSnapshotManager.ts
index fcd7a326..665c6c0c 100644
--- a/src/processors/HeapSnapshotManager.ts
+++ b/src/processors/HeapSnapshotManager.ts
@@ -8,17 +8,18 @@ import fsSync from 'node:fs';
import path from 'node:path';
import {DevTools} from '../third_party/index.js';
-import {
- createIdGenerator,
- stableIdSymbol,
- type WithSymbolId,
-} from '../utils/id.js';
+import {createIdGenerator} from '../utils/id.js';
-export type AggregatedInfoWithId =
- WithSymbolId<DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>;
+export interface HeapSnapshotAggregate {
+ id: number;
+ className: string;
+ count: number;
+ selfSize: number;
+ retainedSize: number;
+}
export interface HeapSnapshotAggregateData {
- aggregates: Record<string, AggregatedInfoWithId>;
+ aggregates: HeapSnapshotAggregate[];
objectCount: number;
totalSelfSize: number;
}
@@ -141,18 +142,29 @@ export class HeapSnapshotManager {
const filter =
new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();
await this.#applyNodeFilter(snapshot.proxy, filter, filterName, objectId);
- const aggregates: Record<string, AggregatedInfoWithId> =
- await snapshot.proxy.aggregatesWithFilter(filter);
+ const rawAggregates = await snapshot.proxy.aggregatesWithFilter(filter);
let objectCount = 0;
let totalSelfSize = 0;
+ const aggregates: HeapSnapshotAggregate[] = [];
- for (const [key, aggregate] of Object.entries(aggregates)) {
+ for (const [key, aggregate] of Object.entries(rawAggregates)) {
const id = snapshot.resolveIdFromClassKey(key);
- aggregate[stableIdSymbol] = id;
+ if (id === undefined) {
+ throw new Error(`No class ID found for class key ${key}`);
+ }
objectCount += aggregate.count;
totalSelfSize += aggregate.self;
+ aggregates.push({
+ id,
+ className: aggregate.name,
+ count: aggregate.count,
+ selfSize: aggregate.self,
+ retainedSize: aggregate.maxRet,
+ });
}
+ aggregates.sort((a, b) => b.retainedSize - a.retainedSize);
+
return {
aggregates,
objectCount,
diff --git a/src/telemetry/tool_call_metrics.json b/src/telemetry/tool_call_metrics.json
index 43dd1d53..d6a0cd59 100644
--- a/src/telemetry/tool_call_metrics.json
+++ b/src/telemetry/tool_call_metrics.json
@@ -886,6 +886,10 @@
{
"name": "object_id",
"argType": "number"
+ },
+ {
+ "name": "max_name_length",
+ "argType": "number"
}
]
},
diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.ts
index 41cf4eb4..233173a0 100644
--- a/src/tools/ToolDefinition.ts
+++ b/src/tools/ToolDefinition.ts
@@ -193,7 +193,7 @@ export interface Response {
appendResponseLine(value: string): void;
setHeapSnapshotAggregates(
aggregateData: HeapSnapshotAggregateData,
- options?: PaginationOptions,
+ options?: PaginationOptions & HeapSnapshotFormatOptions,
): void;
setHeapSnapshotStats(
stats: DevTools.HeapSnapshotModel.HeapSnapshotModel.Statistics,
diff --git a/src/tools/memory.ts b/src/tools/memory.ts
index 63952799..d0eed16e 100644
--- a/src/tools/memory.ts
+++ b/src/tools/memory.ts
@@ -124,6 +124,7 @@ export const getHeapSnapshotDetails = defineTool(() => ({
.describe(
'The object ID (nodeId) of the specific native context to filter by when filterName is attributedToSpecificNativeContext.',
),
+ maxNameLength: maxNameLengthSchema,
pageIdx: zod
.number()
.optional()
@@ -147,6 +148,7 @@ export const getHeapSnapshotDetails = defineTool(() => ({
response.setHeapSnapshotAggregates(aggregates, {
pageIdx: request.params.pageIdx,
pageSize: request.params.pageSize,
+ maxNameLength: request.params.maxNameLength,
});
},
}));
diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts
index e50ee4e9..e3a96935 100644
--- a/tests/McpResponse.test.ts
+++ b/tests/McpResponse.test.ts
@@ -18,7 +18,6 @@ import {TextSnapshot} from '../src/TextSnapshot.js';
import {DevTools, type Extension} from '../src/third_party/index.js';
import type {TextSnapshotNode} from '../src/types.js';
import {parseByteSizeRange} from '../src/utils/bytes.js';
-import {stableIdSymbol} from '../src/utils/id.js';
import {
closePage,
listPages,
@@ -36,7 +35,7 @@ import {serverHooks} from './server.js';
import {loadTraceAsBuffer} from './trace-processing/fixtures/load.js';
import {
createHandlerMocks,
- createMockAggregatedInfo,
+ createMockHeapSnapshotAggregate,
createMockCSSMatchedStyles,
createMockCSSProperty,
createMockCSSStyleDeclaration,
@@ -1486,26 +1485,22 @@ describe('McpResponse heap snapshot formatting', () => {
it('formats aggregate data with shallow size and pagination summaries', async () => {
const response = new McpResponse(createMockParsedArguments());
const aggregates = {
- aggregates: {
- ObjectA: createMockAggregatedInfo({
- name: 'ObjectA',
+ aggregates: [
+ createMockHeapSnapshotAggregate({
+ id: 1,
+ className: 'ObjectA',
count: 10,
- self: 100,
- maxRet: 1000,
- distance: 1,
- idxs: [],
- [stableIdSymbol]: 1,
+ selfSize: 100,
+ retainedSize: 1000,
}),
- ObjectB: createMockAggregatedInfo({
- name: 'ObjectB',
+ createMockHeapSnapshotAggregate({
+ id: 2,
+ className: 'ObjectB',
count: 5,
- self: 50,
- maxRet: 500,
- distance: 2,
- idxs: [],
- [stableIdSymbol]: 2,
+ selfSize: 50,
+ retainedSize: 500,
}),
- },
+ ],
objectCount: 15,
totalSelfSize: 150,
};
@@ -1532,6 +1527,10 @@ describe('McpResponse heap snapshot formatting', () => {
objectCount: 15,
totalSelfSize: 150,
});
+ assert.deepStrictEqual(
+ Reflect.get(structuredContent, 'heapSnapshotAggregates'),
+ [aggregates.aggregates[0]],
+ );
});
it('sorts nodes descending by retainedSize and formats pagination summaries', async () => {
diff --git a/tests/formatters/HeapSnapshotFormatter.test.js.snapshot b/tests/formatters/HeapSnapshotFormatter.test.js.snapshot
index f3b917ce..ab60b99d 100644
--- a/tests/formatters/HeapSnapshotFormatter.test.js.snapshot
+++ b/tests/formatters/HeapSnapshotFormatter.test.js.snapshot
@@ -1,3 +1,9 @@
+exports[`HeapSnapshotFormatter > formatAggregates > formats data as CSV 1`] = `
+id,className,count,selfSize,retainedSize
+1,ObjectA,10,0.1 kB,1.0 kB
+2,ObjectB,5,0.1 kB,0.5 kB
+`;
+
exports[`HeapSnapshotFormatter > formatContextAnalysis > formats contexts in ranked order with their scope 1`] = `
#### Context @101 in \`createClosure (test.js)\` — 2.0 kB
Script @301, ScopeInfo @303, offsets 14-104, 2 context fields
@@ -12,272 +18,11 @@ Script @301, ScopeInfo @303, offsets 14-104, 2 context fields
- \`alsoDead\` (Array @204) — 0.5 kB
Scripts without scope metadata could not be analyzed:
-- \`other.js\` (@401) — 2 contexts
-`;
-
-exports[`HeapSnapshotFormatter > toString > formats data as CSV and sorts by retained size 1`] = `
-id,name,count,selfSize,retainedSize
-1,ObjectA,10,0.1 kB,1.0 kB
-2,ObjectB,5,0.1 kB,0.5 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats detailed diff comparing heap-1 to heap-2 with classIndex filter 1`] = `
-NewObject: # new: 2, # deleted: 0, # delta: +2, alloc size: +0.1 kB, freed size: 0.0 kB, size delta: +0.1 kB
-Objects:
- + @35179 (self_size: 0.1 kB)
- + @35181 (self_size: 0.1 kB)
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats diff summary comparing heap-1 to heap-2 1`] = `
-index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
-0,(object shape),11,1,10,0.4 kB,0.0 kB,0.4 kB
-1,(compiled code),7,1,6,0.3 kB,0.0 kB,0.2 kB
-2,NewObject,2,0,2,0.1 kB,0.0 kB,0.1 kB
-3,(concatenated string),45,43,2,0.9 kB,0.9 kB,0.0 kB
-4,Array,2,0,2,0.0 kB,0.0 kB,0.0 kB
-5,{constructor},1,0,1,0.0 kB,0.0 kB,0.0 kB
-6,(string),4,4,0,0.1 kB,0.1 kB,0.0 kB
-7,(number),0,2,-2,0.0 kB,0.0 kB,-0.0 kB
-8,Object,0,2,-2,0.0 kB,0.0 kB,-0.0 kB
-9,InitialObject,0,2,-2,0.0 kB,0.1 kB,-0.1 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats diff summary comparing heap-2 to heap-3 1`] = `
-index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
-0,(concatenated string),105,0,105,2.1 kB,0.0 kB,2.1 kB
-1,(object shape),7,1,6,0.3 kB,0.1 kB,0.3 kB
-2,(string),10,0,10,0.2 kB,0.0 kB,0.2 kB
-3,NewObject,5,0,5,0.1 kB,0.0 kB,0.1 kB
-4,Array,5,0,5,0.1 kB,0.0 kB,0.1 kB
-5,system / PropertyArray,1,0,1,0.0 kB,0.0 kB,0.0 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatDominators > formats dominator chain for a valid nodeId 1`] = `
-nodeId,nodeName,selfSize,retainedSize
-25341,String,0.2 kB,1.6 kB
-7199,system / NativeContext,1.2 kB,84.4 kB
-1,,0.0 kB,802 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatDuplicateStrings > formats duplicate strings with default options 1`] = `
-value,count,totalSelfSize,totalRetainedSize,truncated,nodeIds
-"get disposed",8,0.2 kB,0.2 kB,false,@30685 @30731 @33713 @33781 @42891 @42947 @45203 @45233
-"WebAssembly.Suspending",4,0.1 kB,0.1 kB,false,@44967 @45473 @46069 @46195
-"extensions::SafeBuiltins",2,0.1 kB,0.1 kB,false,@25155 @26209
-"WebAssembly",2,0.0 kB,0.0 kB,false,@7495 @15037
-"EventTarget",2,0.0 kB,0.0 kB,false,@25089 @26185
-"v8/LoadTimes",2,0.0 kB,0.0 kB,false,@25159 @26365
-"Document",2,0.0 kB,0.0 kB,false,@25969 @26603
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNativeContextSizes > formats native context sizes from fixture 1`] = `
-nodeId,nodeName,selfSize,retainedSize,attributedSize
-7249,system / NativeContext / https://example.com,1.2 kB,350 kB,350 kB
-7195,system / NativeContext / https://example.com,1.2 kB,60.1 kB,215 kB
-7307,system / NativeContext,1.2 kB,84.4 kB,84.6 kB
-7199,system / NativeContext,1.2 kB,84.4 kB,84.4 kB
-Shared Size: 22.9 kB
-Unattributed Size: 44.8 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with class nodes > formats class nodes with default options 1`] = `
-nodeId,nodeName,type,distance,selfSize,retainedSize
-25307,Array,object,2,0.2 kB,2.1 kB
-33187,Array,object,2,0.2 kB,1.7 kB
-36255,Array,object,2,0.2 kB,1.7 kB
-45899,Array,object,5,0.1 kB,0.1 kB
-45901,Array,object,5,0.1 kB,0.1 kB
-46149,Array,object,5,0.1 kB,0.1 kB
-46151,Array,object,5,0.1 kB,0.1 kB
-46355,Array,object,2,0.2 kB,2.1 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with class nodes > formats class nodes with objectsRetainedByContexts filterName 1`] = `
-nodeId,nodeName,type,distance,selfSize,retainedSize
-45893,Apply,closure,5,0.0 kB,0.0 kB
-45895,Save,closure,5,0.0 kB,0.0 kB
-45897,makeCallable,closure,5,0.0 kB,0.2 kB
-46143,Apply,closure,5,0.0 kB,0.0 kB
-46145,Save,closure,5,0.0 kB,0.0 kB
-46147,makeCallable,closure,5,0.0 kB,0.2 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges for a valid nodeId 1`] = `
-name,type,nodeId,nodeName,selfSize,retainedSize
-constructor,property,25575,String,0.1 kB,0.4 kB
-anchor,property,29295,anchor,0.0 kB,0.0 kB
-at,property,29297,at,0.0 kB,0.0 kB
-big,property,29299,big,0.0 kB,0.0 kB
-blink,property,29301,blink,0.0 kB,0.0 kB
-bold,property,29303,bold,0.0 kB,0.0 kB
-charAt,property,29305,charAt,0.0 kB,0.0 kB
-charCodeAt,property,29307,charCodeAt,0.0 kB,0.0 kB
-codePointAt,property,29309,codePointAt,0.0 kB,0.0 kB
-concat,property,29311,concat,0.0 kB,0.0 kB
-endsWith,property,29313,endsWith,0.0 kB,0.0 kB
-fontcolor,property,29315,fontcolor,0.0 kB,0.0 kB
-fontsize,property,29317,fontsize,0.0 kB,0.0 kB
-fixed,property,29319,fixed,0.0 kB,0.0 kB
-includes,property,29321,includes,0.0 kB,0.0 kB
-indexOf,property,29323,indexOf,0.0 kB,0.0 kB
-isWellFormed,property,29325,isWellFormed,0.0 kB,0.0 kB
-italics,property,29327,italics,0.0 kB,0.0 kB
-lastIndexOf,property,29329,lastIndexOf,0.0 kB,0.0 kB
-link,property,29331,link,0.0 kB,0.0 kB
-localeCompare,property,29333,localeCompare,0.0 kB,0.0 kB
-match,property,29335,match,0.0 kB,0.0 kB
-matchAll,property,29337,matchAll,0.0 kB,0.0 kB
-normalize,property,29339,normalize,0.0 kB,0.0 kB
-padEnd,property,29341,padEnd,0.0 kB,0.0 kB
-padStart,property,29343,padStart,0.0 kB,0.0 kB
-repeat,property,29345,repeat,0.0 kB,0.0 kB
-replace,property,29347,replace,0.0 kB,0.0 kB
-replaceAll,property,29349,replaceAll,0.0 kB,0.0 kB
-search,property,29351,search,0.0 kB,0.0 kB
-slice,property,29353,slice,0.0 kB,0.0 kB
-small,property,29355,small,0.0 kB,0.0 kB
-split,property,29357,split,0.0 kB,0.0 kB
-strike,property,29359,strike,0.0 kB,0.0 kB
-sub,property,29361,sub,0.0 kB,0.0 kB
-substr,property,29363,substr,0.0 kB,0.0 kB
-substring,property,29365,substring,0.0 kB,0.0 kB
-sup,property,29367,sup,0.0 kB,0.0 kB
-startsWith,property,29369,startsWith,0.0 kB,0.0 kB
-toString,property,29371,toString,0.0 kB,0.0 kB
-toWellFormed,property,29373,toWellFormed,0.0 kB,0.0 kB
-trim,property,29375,trim,0.0 kB,0.0 kB
-trimStart,property,29377,trimStart,0.0 kB,0.0 kB
-trimLeft,property,29377,trimStart,0.0 kB,0.0 kB
-trimEnd,property,29379,trimEnd,0.0 kB,0.0 kB
-trimRight,property,29379,trimEnd,0.0 kB,0.0 kB
-toLocaleLowerCase,property,29381,toLocaleLowerCase,0.0 kB,0.0 kB
-toLocaleUpperCase,property,29383,toLocaleUpperCase,0.0 kB,0.0 kB
-toLowerCase,property,29385,toLowerCase,0.0 kB,0.0 kB
-toUpperCase,property,29387,toUpperCase,0.0 kB,0.0 kB
-valueOf,property,29389,valueOf,0.0 kB,0.0 kB
-<symbol Symbol.iterator>,property,29391,[Symbol.iterator],0.0 kB,0.0 kB
-__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
-properties,internal,29393,system / PropertyArray,0.0 kB,0.0 kB
-map,internal,25577,system / Map,0.0 kB,0.7 kB
-1,hidden,71,,0.0 kB,0.0 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges with pagination 1`] = `
-name,type,nodeId,nodeName,selfSize,retainedSize
-constructor,property,25575,String,0.1 kB,0.4 kB
-anchor,property,29295,anchor,0.0 kB,0.0 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges with retainedSize range 1`] = `
-name,type,nodeId,nodeName,selfSize,retainedSize
-constructor,property,25575,String,0.1 kB,0.4 kB
-__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
-map,internal,25577,system / Map,0.0 kB,0.7 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with an unbounded retainedSize filter 1`] = `
-nodeId,nodeName,type,distance,selfSize,retainedSize
-1,,synthetic,100000000,0.0 kB,802 kB
-7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
-7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
-49547,,array,2,4.1 kB,41.0 kB
-36241,,array,2,4.1 kB,41.0 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with className filter 1`] = `
-nodeId,nodeName,type,distance,selfSize,retainedSize
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
-42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
-32995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
-41995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
-16321,Window / https://example.com,native,2,0.9 kB,1.9 kB
-16329,Window,closure,3,0.1 kB,0.4 kB
-16341,Window,closure,3,0.1 kB,0.4 kB
-30975,Window (prototype) / https://example.com,object,3,0.0 kB,0.2 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with default options 1`] = `
-nodeId,nodeName,type,distance,selfSize,retainedSize
-1,,synthetic,100000000,0.0 kB,802 kB
-7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
-7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
-7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
-49547,,array,2,4.1 kB,41.0 kB
-36241,,array,2,4.1 kB,41.0 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with sortBy selfSize and pagination 1`] = `
-nodeId,nodeName,type,distance,selfSize,retainedSize
-27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
-30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
-30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
-42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
-32657,system / DescriptorArray,object shape,5,9.8 kB,9.8 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with retainers > formats retainers for a valid nodeId 1`] = `
-name,type,nodeId,nodeName,selfSize,retainedSize
-prototype,internal,29287,system / Map,0.0 kB,0.1 kB
-prototype,property,25575,String,0.1 kB,0.4 kB
-initial_string_prototype,internal,7199,system / NativeContext,1.2 kB,84.4 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatObjectInfo > formats object details for a valid nodeId 1`] = `
-id: @25341
-name: String
-type: object
-detachedness: unknown
-selfSize: 0.2 kB
-retainedSize: 1.6 kB
-distance: 2
-edgeCount: 56
-retainerCount: 3
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatRetainedByContextSummary > formats retained by context summary from fixture 1`] = `
-Context count: 116
-Retained by context size: 3.5 kB (148 objects)
-Not retained by context size: 798 kB (11792 objects)
-Total size: 802 kB
-`;
-
-exports[`HeapSnapshotFormatter > with real fixtures > formatRetainingPaths > formats retaining paths for a valid nodeId 1`] = `
-<- @45891 system / Context via context builtinToJSONs (distance: 4)
- <- @34237 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Promise> (distance: 2)
- <- @34235 system / PropertyCell via internal value (distance: 4)
- <- @50423 (object properties) via internal 1912 (distance: 3)
- <- @27635 Window (global*) / https://example.com via internal properties (distance: 2)
- <- @34213 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Error> (distance: 2)
- <- @34197 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::RegExp> (distance: 2)
- <- @34185 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::String> (distance: 2)
- <- @34145 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Array> (distance: 2)
- <- @34069 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Function> (distance: 2)
- <- @34047 safe via internal context (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Object> (distance: 2)
- <- @46063 stringify via internal context (distance: 4)
- <- @34247 {parse, stringify} via property stringify (distance: 3)
- <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::JSON> (distance: 2)
+- \`other.js\` (@401) — 2 contexts
`;
-exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with attributedToSpecificNativeContext filterName and objectId 1`] = `
-id,name,count,selfSize,retainedSize
+exports[`HeapSnapshotFormatter > with real fixtures > formatAggregates > formats aggregates with attributedToSpecificNativeContext filterName and objectId 1`] = `
+id,className,count,selfSize,retainedSize
2,(system),1739,115 kB,350 kB
11,Function,1095,34.9 kB,72.2 kB
16,(object shape),769,52.6 kB,53.3 kB
@@ -291,7 +36,7 @@ id,name,count,selfSize,retainedSize
10,HTMLDocument,1,3.3 kB,6.2 kB
105,HTMLElement,1,4.7 kB,4.8 kB
104,Element,1,4.2 kB,4.5 kB
-55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, setDate, getDay},1,0.2 kB,2.2 kB
+55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, ...,1,0.2 kB,2.2 kB
49,TypedArray,12,0.4 kB,2.2 kB
50,Error,12,0.3 kB,2.0 kB
47,Math,1,0.2 kB,1.9 kB
@@ -300,18 +45,18 @@ id,name,count,selfSize,retainedSize
19,Array,3,0.3 kB,1.8 kB
103,Node,1,1.8 kB,1.8 kB
126,Performance,1,1.0 kB,1.8 kB
-39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, get length},1,0.2 kB,1.8 kB
+39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, ge...,1,0.2 kB,1.8 kB
89,system / Context,57,1.3 kB,1.7 kB
32,String,1,0.2 kB,1.4 kB
68,DataView,1,0.1 kB,1.4 kB
106,HTMLBodyElement (prototype) / https://example.com,1,1.2 kB,1.2 kB
62,Intl.Locale,1,0.1 kB,1.2 kB
-76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getFileName, getFunction},1,0.1 kB,1.1 kB
+76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getF...,1,0.1 kB,1.1 kB
130,StyleEngine,1,0.9 kB,1.1 kB
45,Intl,1,0.1 kB,1.0 kB
118,CSSStyleRule,8,0.6 kB,1.0 kB
119,CSSStyleSheet,3,0.5 kB,1.0 kB
-25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, some, every, find},1,0.1 kB,0.9 kB
+25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, ...,1,0.1 kB,0.9 kB
43,Atomics,1,0.1 kB,0.8 kB
91,DisposableStack,1,0.1 kB,0.8 kB
92,AsyncDisposableStack,1,0.1 kB,0.8 kB
@@ -320,7 +65,7 @@ id,name,count,selfSize,retainedSize
72,ArrayBuffer,1,0.0 kB,0.5 kB
110,Text,6,0.5 kB,0.5 kB
37,WebAssembly,1,0.1 kB,0.5 kB
-58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get first, next, get next},1,0.0 kB,0.5 kB
+58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get fir...,1,0.0 kB,0.5 kB
40,{constructor},4,0.1 kB,0.4 kB
30,Set,1,0.1 kB,0.4 kB
135,EventListener,10,0.4 kB,0.4 kB
@@ -331,7 +76,7 @@ id,name,count,selfSize,retainedSize
27,Map,1,0.1 kB,0.4 kB
48,Number,1,0.1 kB,0.4 kB
70,Symbol,1,0.0 kB,0.3 kB
-67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, keys, toReversed},1,0.1 kB,0.3 kB
+67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, k...,1,0.1 kB,0.3 kB
134,FontFaceSet,1,0.3 kB,0.3 kB
133,StylePropertyMap,8,0.3 kB,0.3 kB
139,MutationObserver,2,0.3 kB,0.3 kB
@@ -341,8 +86,8 @@ id,name,count,selfSize,retainedSize
60,Intl.RelativeTimeFormat,1,0.0 kB,0.3 kB
61,Intl.ListFormat,1,0.0 kB,0.3 kB
65,Intl.DurationFormat,1,0.0 kB,0.3 kB
-17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedderData, console},1,0.0 kB,0.3 kB
-28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__, isPrototypeOf},1,0.1 kB,0.3 kB
+17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedd...,1,0.0 kB,0.3 kB
+28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__...,1,0.1 kB,0.3 kB
115,<style>,1,0.1 kB,0.3 kB
21,Generator,1,0.0 kB,0.3 kB
23,AsyncGenerator,1,0.0 kB,0.3 kB
@@ -394,7 +139,7 @@ id,name,count,selfSize,retainedSize
81,WebAssembly.Global,1,0.0 kB,0.1 kB
98,HTMLDocument (prototype) / https://example.com,1,0.1 kB,0.1 kB
93,WebAssembly.Suspending,1,0.0 kB,0.1 kB
-36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasIndices, ignoreCase},1,0.1 kB,0.1 kB
+36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasInd...,1,0.1 kB,0.1 kB
102,WindowProperties,1,0.0 kB,0.1 kB
83,WebAssembly.Exception,1,0.0 kB,0.1 kB
78,WebAssembly.Instance,1,0.0 kB,0.1 kB
@@ -430,8 +175,8 @@ id,name,count,selfSize,retainedSize
108,HTMLBodyElement (internal cache) / https://example.com,1,0.0 kB,0.0 kB
`;
-exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with default options 1`] = `
-id,name,count,selfSize,retainedSize
+exports[`HeapSnapshotFormatter > with real fixtures > formatAggregates > formats aggregates with default options 1`] = `
+id,className,count,selfSize,retainedSize
2,(system),3205,199 kB,655 kB
11,Function,3581,111 kB,237 kB
16,(object shape),2878,181 kB,184 kB
@@ -442,13 +187,13 @@ id,name,count,selfSize,retainedSize
6,(string),846,27.9 kB,27.9 kB
96,Window (internal cache) / https://example.com,4,0.4 kB,20.3 kB
15,Object (global*),2,3.9 kB,13.5 kB
-55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, setDate, getDay},4,0.8 kB,8.8 kB
+55,{constructor, toString, toDateString, toTimeString, toISOString, toUTCString, toGMTString, getDate, ...,4,0.8 kB,8.8 kB
49,TypedArray,48,1.4 kB,8.8 kB
109,Document,1,8.4 kB,8.7 kB
50,Error,48,1.3 kB,7.9 kB
47,Math,4,0.8 kB,7.8 kB
19,Array,8,1.1 kB,7.7 kB
-39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, get length},4,0.6 kB,7.0 kB
+39,{constructor, buffer, get buffer, byteLength, get byteLength, byteOffset, get byteOffset, length, ge...,4,0.6 kB,7.0 kB
10,HTMLDocument,1,3.3 kB,6.2 kB
44,console,4,0.5 kB,6.2 kB
32,String,4,1.0 kB,6.1 kB
@@ -456,9 +201,9 @@ id,name,count,selfSize,retainedSize
105,HTMLElement,1,4.7 kB,4.8 kB
62,Intl.Locale,4,0.3 kB,4.7 kB
104,Element,1,4.2 kB,4.5 kB
-76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getFileName, getFunction},4,0.5 kB,4.4 kB
+76,{constructor, getColumnNumber, getEnclosingColumnNumber, getEnclosingLineNumber, getEvalOrigin, getF...,4,0.5 kB,4.4 kB
45,Intl,4,0.3 kB,4.2 kB
-25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, some, every, find},4,0.3 kB,3.6 kB
+25,{<symbol Symbol.iterator>, constructor, get constructor, set constructor, reduce, toArray, forEach, ...,4,0.3 kB,3.6 kB
89,system / Context,116,2.5 kB,3.5 kB
43,Atomics,4,0.3 kB,3.1 kB
91,DisposableStack,4,0.2 kB,3.0 kB
@@ -467,7 +212,7 @@ id,name,count,selfSize,retainedSize
72,ArrayBuffer,4,0.2 kB,2.2 kB
9,Window / https://example.com,1,0.9 kB,1.9 kB
37,WebAssembly,4,0.4 kB,1.9 kB
-58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get first, next, get next},4,0.1 kB,1.8 kB
+58,{constructor, <symbol Symbol.toStringTag>, resolvedOptions, adoptText, get adoptText, first, get fir...,4,0.1 kB,1.8 kB
103,Node,1,1.8 kB,1.8 kB
126,Performance,1,1.0 kB,1.8 kB
30,Set,4,0.4 kB,1.6 kB
@@ -478,7 +223,7 @@ id,name,count,selfSize,retainedSize
27,Map,4,0.3 kB,1.5 kB
48,Number,4,0.2 kB,1.5 kB
70,Symbol,4,0.2 kB,1.4 kB
-67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, keys, toReversed},4,0.3 kB,1.3 kB
+67,{at, copyWithin, entries, fill, find, findIndex, findLast, findLastIndex, flat, flatMap, includes, k...,4,0.3 kB,1.3 kB
106,HTMLBodyElement (prototype) / https://example.com,1,1.2 kB,1.2 kB
54,Object,22,0.9 kB,1.2 kB
59,Intl.PluralRules,4,0.2 kB,1.2 kB
@@ -486,8 +231,8 @@ id,name,count,selfSize,retainedSize
61,Intl.ListFormat,4,0.2 kB,1.2 kB
65,Intl.DurationFormat,4,0.2 kB,1.2 kB
69,BigInt,4,0.2 kB,1.2 kB
-28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__, isPrototypeOf},4,0.3 kB,1.1 kB
-17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedderData, console},4,0.2 kB,1.1 kB
+28,{constructor, __defineGetter__, __defineSetter__, hasOwnProperty, __lookupGetter__, __lookupSetter__...,4,0.3 kB,1.1 kB
+17,{isTraceCategoryEnabled, trace, getContinuationPreservedEmbedderData, setContinuationPreservedEmbedd...,4,0.2 kB,1.1 kB
130,StyleEngine,1,0.9 kB,1.1 kB
118,CSSStyleRule,8,0.6 kB,1.0 kB
21,Generator,4,0.2 kB,1.0 kB
@@ -522,7 +267,7 @@ id,name,count,selfSize,retainedSize
81,WebAssembly.Global,4,0.1 kB,0.6 kB
93,WebAssembly.Suspending,4,0.1 kB,0.6 kB
100,{loadTimes, csi},2,0.1 kB,0.6 kB
-36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasIndices, ignoreCase},4,0.2 kB,0.6 kB
+36,{constructor, exec, dotAll, get dotAll, flags, get flags, global, get global, hasIndices, get hasInd...,4,0.2 kB,0.6 kB
78,WebAssembly.Instance,4,0.1 kB,0.5 kB
83,WebAssembly.Exception,4,0.1 kB,0.5 kB
110,Text,6,0.5 kB,0.5 kB
@@ -591,19 +336,274 @@ id,name,count,selfSize,retainedSize
108,HTMLBodyElement (internal cache) / https://example.com,1,0.0 kB,0.0 kB
`;
-exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with objectsRetainedByContexts filterName 1`] = `
-id,name,count,selfSize,retainedSize
+exports[`HeapSnapshotFormatter > with real fixtures > formatAggregates > formats aggregates with objectsRetainedByContexts filterName 1`] = `
+id,className,count,selfSize,retainedSize
89,system / Context,116,2.5 kB,3.5 kB
11,Function,6,0.2 kB,0.7 kB
1,(compiled code),22,0.5 kB,0.5 kB
19,Array,4,0.3 kB,0.3 kB
`;
-exports[`HeapSnapshotFormatter > with real fixtures > toString with aggregates > formats aggregates with sharedNativeContext filterName 1`] = `
-id,name,count,selfSize,retainedSize
+exports[`HeapSnapshotFormatter > with real fixtures > formatAggregates > formats aggregates with sharedNativeContext filterName 1`] = `
+id,className,count,selfSize,retainedSize
6,(string),443,16.6 kB,16.6 kB
1,(compiled code),85,5.9 kB,9.8 kB
2,(system),12,0.2 kB,0.6 kB
7,(number),16,0.2 kB,0.2 kB
41,(concatenated string),2,0.0 kB,0.1 kB
`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats detailed diff comparing heap-1 to heap-2 with classIndex filter 1`] = `
+NewObject: # new: 2, # deleted: 0, # delta: +2, alloc size: +0.1 kB, freed size: 0.0 kB, size delta: +0.1 kB
+Objects:
+ + @35179 (self_size: 0.1 kB)
+ + @35181 (self_size: 0.1 kB)
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats diff summary comparing heap-1 to heap-2 1`] = `
+index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
+0,(object shape),11,1,10,0.4 kB,0.0 kB,0.4 kB
+1,(compiled code),7,1,6,0.3 kB,0.0 kB,0.2 kB
+2,NewObject,2,0,2,0.1 kB,0.0 kB,0.1 kB
+3,(concatenated string),45,43,2,0.9 kB,0.9 kB,0.0 kB
+4,Array,2,0,2,0.0 kB,0.0 kB,0.0 kB
+5,{constructor},1,0,1,0.0 kB,0.0 kB,0.0 kB
+6,(string),4,4,0,0.1 kB,0.1 kB,0.0 kB
+7,(number),0,2,-2,0.0 kB,0.0 kB,-0.0 kB
+8,Object,0,2,-2,0.0 kB,0.0 kB,-0.0 kB
+9,InitialObject,0,2,-2,0.0 kB,0.1 kB,-0.1 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDiffSummary and formatDiffDetails > formats diff summary comparing heap-2 to heap-3 1`] = `
+index,className,addedCount,removedCount,countDelta,addedSize,removedSize,sizeDelta
+0,(concatenated string),105,0,105,2.1 kB,0.0 kB,2.1 kB
+1,(object shape),7,1,6,0.3 kB,0.1 kB,0.3 kB
+2,(string),10,0,10,0.2 kB,0.0 kB,0.2 kB
+3,NewObject,5,0,5,0.1 kB,0.0 kB,0.1 kB
+4,Array,5,0,5,0.1 kB,0.0 kB,0.1 kB
+5,system / PropertyArray,1,0,1,0.0 kB,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDominators > formats dominator chain for a valid nodeId 1`] = `
+nodeId,nodeName,selfSize,retainedSize
+25341,String,0.2 kB,1.6 kB
+7199,system / NativeContext,1.2 kB,84.4 kB
+1,,0.0 kB,802 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatDuplicateStrings > formats duplicate strings with default options 1`] = `
+value,count,totalSelfSize,totalRetainedSize,truncated,nodeIds
+"get disposed",8,0.2 kB,0.2 kB,false,@30685 @30731 @33713 @33781 @42891 @42947 @45203 @45233
+"WebAssembly.Suspending",4,0.1 kB,0.1 kB,false,@44967 @45473 @46069 @46195
+"extensions::SafeBuiltins",2,0.1 kB,0.1 kB,false,@25155 @26209
+"WebAssembly",2,0.0 kB,0.0 kB,false,@7495 @15037
+"EventTarget",2,0.0 kB,0.0 kB,false,@25089 @26185
+"v8/LoadTimes",2,0.0 kB,0.0 kB,false,@25159 @26365
+"Document",2,0.0 kB,0.0 kB,false,@25969 @26603
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNativeContextSizes > formats native context sizes from fixture 1`] = `
+nodeId,nodeName,selfSize,retainedSize,attributedSize
+7249,system / NativeContext / https://example.com,1.2 kB,350 kB,350 kB
+7195,system / NativeContext / https://example.com,1.2 kB,60.1 kB,215 kB
+7307,system / NativeContext,1.2 kB,84.4 kB,84.6 kB
+7199,system / NativeContext,1.2 kB,84.4 kB,84.4 kB
+Shared Size: 22.9 kB
+Unattributed Size: 44.8 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with class nodes > formats class nodes with default options 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+25307,Array,object,2,0.2 kB,2.1 kB
+33187,Array,object,2,0.2 kB,1.7 kB
+36255,Array,object,2,0.2 kB,1.7 kB
+45899,Array,object,5,0.1 kB,0.1 kB
+45901,Array,object,5,0.1 kB,0.1 kB
+46149,Array,object,5,0.1 kB,0.1 kB
+46151,Array,object,5,0.1 kB,0.1 kB
+46355,Array,object,2,0.2 kB,2.1 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with class nodes > formats class nodes with objectsRetainedByContexts filterName 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+45893,Apply,closure,5,0.0 kB,0.0 kB
+45895,Save,closure,5,0.0 kB,0.0 kB
+45897,makeCallable,closure,5,0.0 kB,0.2 kB
+46143,Apply,closure,5,0.0 kB,0.0 kB
+46145,Save,closure,5,0.0 kB,0.0 kB
+46147,makeCallable,closure,5,0.0 kB,0.2 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges for a valid nodeId 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+constructor,property,25575,String,0.1 kB,0.4 kB
+anchor,property,29295,anchor,0.0 kB,0.0 kB
+at,property,29297,at,0.0 kB,0.0 kB
+big,property,29299,big,0.0 kB,0.0 kB
+blink,property,29301,blink,0.0 kB,0.0 kB
+bold,property,29303,bold,0.0 kB,0.0 kB
+charAt,property,29305,charAt,0.0 kB,0.0 kB
+charCodeAt,property,29307,charCodeAt,0.0 kB,0.0 kB
+codePointAt,property,29309,codePointAt,0.0 kB,0.0 kB
+concat,property,29311,concat,0.0 kB,0.0 kB
+endsWith,property,29313,endsWith,0.0 kB,0.0 kB
+fontcolor,property,29315,fontcolor,0.0 kB,0.0 kB
+fontsize,property,29317,fontsize,0.0 kB,0.0 kB
+fixed,property,29319,fixed,0.0 kB,0.0 kB
+includes,property,29321,includes,0.0 kB,0.0 kB
+indexOf,property,29323,indexOf,0.0 kB,0.0 kB
+isWellFormed,property,29325,isWellFormed,0.0 kB,0.0 kB
+italics,property,29327,italics,0.0 kB,0.0 kB
+lastIndexOf,property,29329,lastIndexOf,0.0 kB,0.0 kB
+link,property,29331,link,0.0 kB,0.0 kB
+localeCompare,property,29333,localeCompare,0.0 kB,0.0 kB
+match,property,29335,match,0.0 kB,0.0 kB
+matchAll,property,29337,matchAll,0.0 kB,0.0 kB
+normalize,property,29339,normalize,0.0 kB,0.0 kB
+padEnd,property,29341,padEnd,0.0 kB,0.0 kB
+padStart,property,29343,padStart,0.0 kB,0.0 kB
+repeat,property,29345,repeat,0.0 kB,0.0 kB
+replace,property,29347,replace,0.0 kB,0.0 kB
+replaceAll,property,29349,replaceAll,0.0 kB,0.0 kB
+search,property,29351,search,0.0 kB,0.0 kB
+slice,property,29353,slice,0.0 kB,0.0 kB
+small,property,29355,small,0.0 kB,0.0 kB
+split,property,29357,split,0.0 kB,0.0 kB
+strike,property,29359,strike,0.0 kB,0.0 kB
+sub,property,29361,sub,0.0 kB,0.0 kB
+substr,property,29363,substr,0.0 kB,0.0 kB
+substring,property,29365,substring,0.0 kB,0.0 kB
+sup,property,29367,sup,0.0 kB,0.0 kB
+startsWith,property,29369,startsWith,0.0 kB,0.0 kB
+toString,property,29371,toString,0.0 kB,0.0 kB
+toWellFormed,property,29373,toWellFormed,0.0 kB,0.0 kB
+trim,property,29375,trim,0.0 kB,0.0 kB
+trimStart,property,29377,trimStart,0.0 kB,0.0 kB
+trimLeft,property,29377,trimStart,0.0 kB,0.0 kB
+trimEnd,property,29379,trimEnd,0.0 kB,0.0 kB
+trimRight,property,29379,trimEnd,0.0 kB,0.0 kB
+toLocaleLowerCase,property,29381,toLocaleLowerCase,0.0 kB,0.0 kB
+toLocaleUpperCase,property,29383,toLocaleUpperCase,0.0 kB,0.0 kB
+toLowerCase,property,29385,toLowerCase,0.0 kB,0.0 kB
+toUpperCase,property,29387,toUpperCase,0.0 kB,0.0 kB
+valueOf,property,29389,valueOf,0.0 kB,0.0 kB
+<symbol Symbol.iterator>,property,29391,[Symbol.iterator],0.0 kB,0.0 kB
+__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
+properties,internal,29393,system / PropertyArray,0.0 kB,0.0 kB
+map,internal,25577,system / Map,0.0 kB,0.7 kB
+1,hidden,71,,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges with pagination 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+constructor,property,25575,String,0.1 kB,0.4 kB
+anchor,property,29295,anchor,0.0 kB,0.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with edges > formats outgoing edges with retainedSize range 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+constructor,property,25575,String,0.1 kB,0.4 kB
+__proto__,property,25329,{constructor, __defineGetter__, __defineSetter__, …, get __proto__, set __proto__, toLocaleString},0.1 kB,0.3 kB
+map,internal,25577,system / Map,0.0 kB,0.7 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with an unbounded retainedSize filter 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+1,,synthetic,100000000,0.0 kB,802 kB
+7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
+7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
+49547,,array,2,4.1 kB,41.0 kB
+36241,,array,2,4.1 kB,41.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with className filter 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+32995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
+41995,Window (internal cache) / https://example.com,object,3,0.2 kB,10.1 kB
+16321,Window / https://example.com,native,2,0.9 kB,1.9 kB
+16329,Window,closure,3,0.1 kB,0.4 kB
+16341,Window,closure,3,0.1 kB,0.4 kB
+30975,Window (prototype) / https://example.com,object,3,0.0 kB,0.2 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with default options 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+1,,synthetic,100000000,0.0 kB,802 kB
+7249,system / NativeContext / https://example.com,hidden,1,1.2 kB,350 kB
+7199,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7307,system / NativeContext,hidden,1,1.2 kB,84.4 kB
+7195,system / NativeContext / https://example.com,hidden,1,1.2 kB,60.1 kB
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+3,(GC roots),synthetic,100000001,0.0 kB,45.6 kB
+49547,,array,2,4.1 kB,41.0 kB
+36241,,array,2,4.1 kB,41.0 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with queryObjects > formats queried objects with sortBy selfSize and pagination 1`] = `
+nodeId,nodeName,type,distance,selfSize,retainedSize
+27635,Window (global*) / https://example.com,object,2,40.5 kB,51.0 kB
+30887,Window (global*) / https://example.com,object,2,40.5 kB,50.9 kB
+30967,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+42085,Window (prototype) / https://example.com,object,4,26.6 kB,26.7 kB
+32657,system / DescriptorArray,object shape,5,9.8 kB,9.8 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatNodes with retainers > formats retainers for a valid nodeId 1`] = `
+name,type,nodeId,nodeName,selfSize,retainedSize
+prototype,internal,29287,system / Map,0.0 kB,0.1 kB
+prototype,property,25575,String,0.1 kB,0.4 kB
+initial_string_prototype,internal,7199,system / NativeContext,1.2 kB,84.4 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatObjectInfo > formats object details for a valid nodeId 1`] = `
+id: @25341
+name: String
+type: object
+detachedness: unknown
+selfSize: 0.2 kB
+retainedSize: 1.6 kB
+distance: 2
+edgeCount: 56
+retainerCount: 3
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatRetainedByContextSummary > formats retained by context summary from fixture 1`] = `
+Context count: 116
+Retained by context size: 3.5 kB (148 objects)
+Not retained by context size: 798 kB (11792 objects)
+Total size: 802 kB
+`;
+
+exports[`HeapSnapshotFormatter > with real fixtures > formatRetainingPaths > formats retaining paths for a valid nodeId 1`] = `
+<- @45891 system / Context via context builtinToJSONs (distance: 4)
+ <- @34237 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Promise> (distance: 2)
+ <- @34235 system / PropertyCell via internal value (distance: 4)
+ <- @50423 (object properties) via internal 1912 (distance: 3)
+ <- @27635 Window (global*) / https://example.com via internal properties (distance: 2)
+ <- @34213 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Error> (distance: 2)
+ <- @34197 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::RegExp> (distance: 2)
+ <- @34185 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::String> (distance: 2)
+ <- @34145 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Array> (distance: 2)
+ <- @34069 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Function> (distance: 2)
+ <- @34047 safe via internal context (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::Object> (distance: 2)
+ <- @46063 stringify via internal context (distance: 4)
+ <- @34247 {parse, stringify} via property stringify (distance: 3)
+ <- @27635 Window (global*) / https://example.com via property <symbol extensions::SafeBuiltins::JSON> (distance: 2)
+`;
diff --git a/tests/formatters/HeapSnapshotFormatter.test.ts b/tests/formatters/HeapSnapshotFormatter.test.ts
index 568034a4..9d8b3242 100644
--- a/tests/formatters/HeapSnapshotFormatter.test.ts
+++ b/tests/formatters/HeapSnapshotFormatter.test.ts
@@ -15,10 +15,12 @@ import {
HeapSnapshotFormatter,
MAX_NAME_LENGTH,
} from '../../src/formatters/HeapSnapshotFormatter.js';
-import {HeapSnapshotManager} from '../../src/processors/HeapSnapshotManager.js';
+import {
+ HeapSnapshotManager,
+ type HeapSnapshotAggregate,
+} from '../../src/processors/HeapSnapshotManager.js';
import {DevTools} from '../../src/third_party/index.js';
import {parseByteSizeRange} from '../../src/utils/bytes.js';
-import {stableIdSymbol} from '../../src/utils/id.js';
import {createMockContextAnalysisResult} from '../mocks.js';
const {formatBytesToKb} = DevTools.I18n.ByteUtilities;
@@ -33,29 +35,22 @@ describe('HeapSnapshotFormatter', () => {
},
});
DevTools.I18n.i18n.registerLocaleDataForTest('en-US', {});
- const mockAggregates: Record<
- string,
- DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo
- > = {
- ObjectA: {
- name: 'ObjectA',
+ const mockAggregates: HeapSnapshotAggregate[] = [
+ {
+ id: 1,
+ className: 'ObjectA',
count: 10,
- self: 100,
- maxRet: 1000,
- distance: 1,
- idxs: [],
- [stableIdSymbol]: 1,
- } as unknown as DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo,
- ObjectB: {
- name: 'ObjectB',
+ selfSize: 100,
+ retainedSize: 1000,
+ },
+ {
+ id: 2,
+ className: 'ObjectB',
count: 5,
- self: 50,
- maxRet: 500,
- distance: 2,
- idxs: [],
- [stableIdSymbol]: 2,
- } as unknown as DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo,
- };
+ selfSize: 50,
+ retainedSize: 500,
+ },
+ ];
describe('formatName', () => {
it('returns short name unchanged', () => {
@@ -83,34 +78,29 @@ describe('HeapSnapshotFormatter', () => {
});
});
- describe('toString', () => {
- it('formats data as CSV and sorts by retained size', t => {
- const formatter = new HeapSnapshotFormatter(mockAggregates);
- const result = formatter.toString();
+ describe('formatAggregates', () => {
+ it('formats data as CSV', t => {
+ const result = HeapSnapshotFormatter.formatAggregates(mockAggregates, {});
t.assert.snapshot(result);
});
- });
- describe('toJSON', () => {
- it('returns structured data sorted by retained size', () => {
- const formatter = new HeapSnapshotFormatter(mockAggregates);
- const result = formatter.toJSON();
- assert.deepStrictEqual(result, [
- {
- id: 1,
- className: 'ObjectA',
- count: 10,
- selfSize: formatBytesToKb(100),
- retainedSize: formatBytesToKb(1000),
- },
- {
- id: 2,
- className: 'ObjectB',
- count: 5,
- selfSize: formatBytesToKb(50),
- retainedSize: formatBytesToKb(500),
- },
- ]);
+ it('truncates class names to maxNameLength', () => {
+ const result = HeapSnapshotFormatter.formatAggregates(
+ [
+ {
+ id: 1,
+ className: 'abcdefghij',
+ count: 10,
+ selfSize: 100,
+ retainedSize: 1000,
+ },
+ ],
+ {maxNameLength: 5},
+ );
+ assert.strictEqual(
+ result.split('\n')[1],
+ `1,abcde...,10,${formatBytesToKb(100)},${formatBytesToKb(1000)}`,
+ );
});
});
@@ -280,34 +270,6 @@ describe('HeapSnapshotFormatter', () => {
});
});
- describe('sort', () => {
- it('sorts aggregates by retained size descending', () => {
- const unsortedAggregates: Record<
- string,
- DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo
- > = {
- ObjectB: {
- name: 'ObjectB',
- self: 50,
- maxRet: 500,
- },
- ObjectA: {
- name: 'ObjectA',
- self: 100,
- maxRet: 1000,
- },
- } as unknown as Record<
- string,
- DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo
- >;
-
- const result = HeapSnapshotFormatter.sort(unsortedAggregates);
- assert.strictEqual(result.length, 2);
- assert.strictEqual(result[0][0], 'ObjectA');
- assert.strictEqual(result[1][0], 'ObjectB');
- });
- });
-
describe('formatRetainingPaths', () => {
it('formats retaining paths correctly', () => {
const mockRetainingPaths = [
@@ -526,11 +488,12 @@ describe('HeapSnapshotFormatter', () => {
manager.dispose();
});
- describe('toString with aggregates', () => {
+ describe('formatAggregates', () => {
it('formats aggregates with default options', async t => {
const data = await manager.getAggregates(examplePath);
- const formatter = new HeapSnapshotFormatter(data.aggregates);
- t.assert.snapshot(formatter.toString());
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatAggregates(data.aggregates, {}),
+ );
});
it('formats aggregates with objectsRetainedByContexts filterName', async t => {
@@ -538,8 +501,9 @@ describe('HeapSnapshotFormatter', () => {
examplePath,
'objectsRetainedByContexts',
);
- const formatter = new HeapSnapshotFormatter(data.aggregates);
- t.assert.snapshot(formatter.toString());
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatAggregates(data.aggregates, {}),
+ );
});
it('formats aggregates with sharedNativeContext filterName', async t => {
@@ -547,8 +511,9 @@ describe('HeapSnapshotFormatter', () => {
examplePath,
'sharedNativeContext',
);
- const formatter = new HeapSnapshotFormatter(data.aggregates);
- t.assert.snapshot(formatter.toString());
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatAggregates(data.aggregates, {}),
+ );
});
it('formats aggregates with attributedToSpecificNativeContext filterName and objectId', async t => {
@@ -557,8 +522,9 @@ describe('HeapSnapshotFormatter', () => {
'attributedToSpecificNativeContext',
7249,
);
- const formatter = new HeapSnapshotFormatter(data.aggregates);
- t.assert.snapshot(formatter.toString());
+ t.assert.snapshot(
+ HeapSnapshotFormatter.formatAggregates(data.aggregates, {}),
+ );
});
});
@@ -592,17 +558,13 @@ describe('HeapSnapshotFormatter', () => {
examplePath,
'objectsRetainedByContexts',
);
- const aggregate = Object.values(aggregateData.aggregates).find(
- a => a.name === 'Function',
+ const aggregate = aggregateData.aggregates.find(
+ a => a.className === 'Function',
);
assert.ok(aggregate);
- const id = aggregate[stableIdSymbol];
- if (id === undefined) {
- assert.fail('Expected class ID to be defined');
- }
const nodes = await manager.getNodesById(
examplePath,
- id,
+ aggregate.id,
'objectsRetainedByContexts',
);
t.assert.snapshot(HeapSnapshotFormatter.formatNodes(nodes.items, {}));
diff --git a/tests/mocks.ts b/tests/mocks.ts
index c82cfd28..b2238efb 100644
--- a/tests/mocks.ts
+++ b/tests/mocks.ts
@@ -34,13 +34,12 @@ import {McpPage} from '../src/McpPage.js';
import {McpResponse} from '../src/McpResponse.js';
import {McpWorker, type WorkerType} from '../src/McpWorker.js';
import type {
- AggregatedInfoWithId,
DuplicateStringGroup,
+ HeapSnapshotAggregate,
HeapSnapshotAggregateData,
HeapSnapshotClassDiff,
HeapSnapshotDetailedClassDiff,
} from '../src/processors/HeapSnapshotManager.js';
-import {stableIdSymbol} from '../src/utils/id.js';
import {
CdpBrowser,
CdpExtension,
@@ -990,7 +989,7 @@ export function createMockRetainedByContextSummary(): DevTools.HeapSnapshotModel
export function createMockHeapSnapshotAggregateData(): HeapSnapshotAggregateData {
return {
- aggregates: {},
+ aggregates: [],
objectCount: 0,
totalSelfSize: 0,
};
@@ -1204,16 +1203,14 @@ export function createMockHeapSnapshotEdge(
};
}
-export function createMockAggregatedInfo(
- options: Partial<AggregatedInfoWithId> = {},
-): AggregatedInfoWithId {
+export function createMockHeapSnapshotAggregate(
+ options: Partial<HeapSnapshotAggregate> = {},
+): HeapSnapshotAggregate {
return {
+ id: options.id ?? 1,
+ className: options.className ?? 'Object',
count: options.count ?? 1,
- distance: options.distance ?? 1,
- self: options.self ?? 10,
- maxRet: options.maxRet ?? 100,
- name: options.name ?? 'Object',
- idxs: options.idxs ?? [],
- [stableIdSymbol]: options[stableIdSymbol] ?? 1,
+ selfSize: options.selfSize ?? 10,
+ retainedSize: options.retainedSize ?? 100,
};
}
diff --git a/tests/processors/HeapSnapshotManager.test.ts b/tests/processors/HeapSnapshotManager.test.ts
index ad95f0df..3d49ea27 100644
--- a/tests/processors/HeapSnapshotManager.test.ts
+++ b/tests/processors/HeapSnapshotManager.test.ts
@@ -11,7 +11,6 @@ import sinon from 'sinon';
import {HeapSnapshotManager} from '../../src/processors/HeapSnapshotManager.js';
import {DevTools} from '../../src/third_party/index.js';
-import {stableIdSymbol} from '../../src/utils/id.js';
describe('HeapSnapshotManager', () => {
afterEach(() => {
@@ -96,12 +95,11 @@ describe('HeapSnapshotManager', () => {
try {
const filePath = 'tests/fixtures/example.heapsnapshot';
const {aggregates} = await manager1.getAggregates(filePath);
- const functionAggregate = Object.values(aggregates).find(
- a => a.name === 'Function',
+ const functionAggregate = aggregates.find(
+ a => a.className === 'Function',
);
assert.ok(functionAggregate);
- const classId = functionAggregate[stableIdSymbol];
- assert.ok(classId !== undefined);
+ const classId = functionAggregate.id;
const expectedNodes = await manager1.getNodesById(filePath, classId);
const nodesWithoutPriorAggregates = await manager2.getNodesById(
@@ -127,6 +125,9 @@ describe('HeapSnapshotManager', () => {
const filePath = 'tests/fixtures/example.heapsnapshot';
const unfilteredFirst =
await unfilteredFirstManager.getAggregates(filePath);
+ const unfilteredById = new Map(
+ unfilteredFirst.aggregates.map(a => [a.id, a.className]),
+ );
const filteredFirst = await filteredFirstManager.getAggregates(
filePath,
@@ -135,21 +136,17 @@ describe('HeapSnapshotManager', () => {
const unfilteredSecond =
await filteredFirstManager.getAggregates(filePath);
- for (const [key, aggregate] of Object.entries(filteredFirst.aggregates)) {
+ for (const aggregate of filteredFirst.aggregates) {
assert.strictEqual(
- aggregate[stableIdSymbol],
- unfilteredFirst.aggregates[key]?.[stableIdSymbol],
+ aggregate.className,
+ unfilteredById.get(aggregate.id),
);
}
- for (const [key, aggregate] of Object.entries(
+ assert.deepStrictEqual(
unfilteredSecond.aggregates,
- )) {
- assert.strictEqual(
- aggregate[stableIdSymbol],
- unfilteredFirst.aggregates[key]?.[stableIdSymbol],
- );
- }
+ unfilteredFirst.aggregates,
+ );
} finally {
unfilteredFirstManager.dispose();
filteredFirstManager.dispose();
diff --git a/tests/tools/memory.test.ts b/tests/tools/memory.test.ts
index 1e2080e0..16134c65 100644
--- a/tests/tools/memory.test.ts
+++ b/tests/tools/memory.test.ts
@@ -166,7 +166,7 @@ describe('memory', () => {
sinon.assert.calledOnceWithExactly(
response.setHeapSnapshotAggregates,
aggregates,
- {pageIdx: undefined, pageSize: undefined},
+ {pageIdx: undefined, pageSize: undefined, maxNameLength: undefined},
);
});
@@ -183,6 +183,7 @@ describe('memory', () => {
objectId: 123,
pageIdx: 1,
pageSize: 10,
+ maxNameLength: 500,
},
},
response,
@@ -198,7 +199,7 @@ describe('memory', () => {
sinon.assert.calledOnceWithExactly(
response.setHeapSnapshotAggregates,
aggregates,
- {pageIdx: 1, pageSize: 10},
+ {pageIdx: 1, pageSize: 10, maxNameLength: 500},
);
});
});