@@ -8,13 +8,24 @@ import fsSync from 'node:fs';
88import path from 'node:path' ;
99
1010import { DevTools } from './third_party/index.js' ;
11+ import {
12+ createIdGenerator ,
13+ stableIdSymbol ,
14+ type WithSymbolId ,
15+ } from './utils/id.js' ;
16+
17+ export type AggregatedInfoWithUid =
18+ WithSymbolId < DevTools . HeapSnapshotModel . HeapSnapshotModel . AggregatedInfo > ;
1119
1220export class HeapSnapshotManager {
1321 #snapshots = new Map <
1422 string ,
1523 {
1624 snapshot : DevTools . HeapSnapshotModel . HeapSnapshotProxy . HeapSnapshotProxy ;
1725 worker : DevTools . HeapSnapshotModel . HeapSnapshotProxy . HeapSnapshotWorkerProxy ;
26+ uidToClassKey : Map < number , string > ;
27+ classKeyToUid : Map < string , number > ;
28+ idGenerator : ( ) => number ;
1829 }
1930 > ( ) ;
2031
@@ -28,20 +39,35 @@ export class HeapSnapshotManager {
2839 }
2940
3041 const { snapshot, worker} = await this . #loadSnapshot( absolutePath ) ;
31- this . #snapshots. set ( absolutePath , { snapshot, worker} ) ;
42+ this . #snapshots. set ( absolutePath , {
43+ snapshot,
44+ worker,
45+ uidToClassKey : new Map < number , string > ( ) ,
46+ classKeyToUid : new Map < string , number > ( ) ,
47+ idGenerator : createIdGenerator ( ) ,
48+ } ) ;
3249
3350 return snapshot ;
3451 }
3552
3653 async getAggregates (
3754 filePath : string ,
38- ) : Promise <
39- Record < string , DevTools . HeapSnapshotModel . HeapSnapshotModel . AggregatedInfo >
40- > {
55+ ) : Promise < Record < string , AggregatedInfoWithUid > > {
4156 const snapshot = await this . getSnapshot ( filePath ) ;
4257 const filter =
4358 new DevTools . HeapSnapshotModel . HeapSnapshotModel . NodeFilter ( ) ;
44- return await snapshot . aggregatesWithFilter ( filter ) ;
59+ const aggregates : Record < string , AggregatedInfoWithUid > =
60+ await snapshot . aggregatesWithFilter ( filter ) ;
61+
62+ for ( const key of Object . keys ( aggregates ) ) {
63+ const uid = await this . getOrCreateUidForClassKey ( filePath , key ) ;
64+ const aggregate = aggregates [ key ] ;
65+ if ( aggregate ) {
66+ aggregate [ stableIdSymbol ] = uid ;
67+ }
68+ }
69+
70+ return aggregates ;
4571 }
4672
4773 async getStats (
0 commit comments