@memlab/heap-analysis 1.0.39 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -188,7 +188,7 @@ class ObjectUnboundGrowthAnalysis extends BaseAnalysis_1.default {
188
188
  core_1.info.topLevel('\n' + str);
189
189
  // save results to file
190
190
  const csv = core_1.serializer.summarizeUnboundedObjectsToCSV(ids);
191
- fs_1.default.writeFileSync(core_1.config.unboundObjectCSV, csv, 'UTF-8');
191
+ fs_1.default.writeFileSync(core_1.config.unboundObjectCSV, csv, { encoding: 'utf8' });
192
192
  });
193
193
  }
194
194
  calculateRetainedSizes(snapshot) {
@@ -1 +1 @@
1
- {"version":3,"file":"StringAnalysis.d.ts","sourceRoot":"","sources":["../../src/plugins/StringAnalysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAC,qBAAqB,EAAE,mBAAmB,EAAC,MAAM,gBAAgB,CAAC;AAG/E,OAAO,EAAc,UAAU,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAuB3C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,qDAAqD;IACrD,CAAC,EAAE,MAAM,CAAC;IACV,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,gCAAgC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IACtD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,sBAAsB,CAAM;IACpC,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,uBAAuB,CAAM;IACrC,OAAO,CAAC,kBAAkB,CAAyB;IAEnD;;;OAGG;IACI,8BAA8B,IAAI,YAAY,EAAE;IAIvD;;;OAG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,OAAO,CAAC,uBAAuB,CAAM;IACrC,OAAO,CAAC,kBAAkB,CAAyB;IAEnD;;;OAGG;IACI,8BAA8B,IAAI,YAAY,EAAE;IAIvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAmCpC;IAEF;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B,gBAAgB;IAChB,UAAU,IAAI,UAAU,EAAE;IAI1B,gBAAgB;IACH,2BAA2B,CACtC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,CAAC;IAQjC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAc/B,gBAAgB;IACV,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAa1D,OAAO,CAAC,wBAAwB;IA8BhC,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,oCAAoC;IAS5C,OAAO,CAAC,mCAAmC;IAS3C,OAAO,CAAC,iCAAiC;IAyCzC,OAAO,CAAC,KAAK;CA4Cd"}
@@ -88,13 +88,14 @@ class StringAnalysis extends BaseAnalysis_1.default {
88
88
  return __awaiter(this, void 0, void 0, function* () {
89
89
  const snapshot = yield PluginUtils_1.default.loadHeapSnapshot(options);
90
90
  const stringMap = this.getPreprocessedStringMap(snapshot);
91
- this.calculateStringPatternsStatistics(stringMap);
91
+ const sourceCodeStringMap = this.getPreprocessedStringMap(snapshot, core_1.utils.isJSSourceStringNode);
92
+ this.calculateStringPatternsStatistics(stringMap, sourceCodeStringMap);
92
93
  this.calculateTopDuplicatedStringsInCount(stringMap);
93
94
  this.calculateTopDuplicatedStringsInSize(stringMap);
94
95
  this.print();
95
96
  });
96
97
  }
97
- getPreprocessedStringMap(snapshot) {
98
+ getPreprocessedStringMap(snapshot, filter = null) {
98
99
  core_1.info.overwrite('building string map...');
99
100
  const stringMap = Object.create(null);
100
101
  // going through string nodes
@@ -102,6 +103,9 @@ class StringAnalysis extends BaseAnalysis_1.default {
102
103
  if (StringAnalysis.shouldIgnoreNode(node)) {
103
104
  return;
104
105
  }
106
+ if (filter && filter(node) === false) {
107
+ return;
108
+ }
105
109
  const strValue = core_1.utils.getStringNodeValue(node);
106
110
  stringMap[strValue] = stringMap[strValue] || {
107
111
  n: 0,
@@ -144,29 +148,38 @@ class StringAnalysis extends BaseAnalysis_1.default {
144
148
  core_1.info.overwrite('calculating top duplicated strings in size...');
145
149
  this.topDupStrInSize = this.rankRecords(stringMap, (item1, item2) => item1.size - item2.size, this.topDupStrInSizeListSize);
146
150
  }
147
- calculateStringPatternsStatistics(stringMap) {
151
+ calculateStringPatternsStatistics(stringMap, sourceStringMap) {
148
152
  core_1.info.overwrite('calculating statistics for specified string patterns...');
149
153
  const strPatternStat = Object.create(null);
154
+ function aggregatePatternStat(patternName, record) {
155
+ strPatternStat[patternName] = strPatternStat[patternName] || {
156
+ n: 0,
157
+ dupN: 0,
158
+ size: 0,
159
+ dupSize: 0,
160
+ };
161
+ const item = strPatternStat[patternName];
162
+ item.n += record.n;
163
+ item.size += record.size;
164
+ if (record.n > 1) {
165
+ item.dupN += record.n - 1;
166
+ item.dupSize += (record.size * (record.n - 1)) / record.n;
167
+ }
168
+ }
169
+ // calculate pattern stats for normal strings
150
170
  for (const [str, record] of Object.entries(stringMap)) {
151
171
  patternLoop: for (const [patternName, patternCheck] of Object.entries(StringAnalysis.stringPatternsToObserve)) {
152
172
  if (!patternCheck(str)) {
153
173
  continue patternLoop;
154
174
  }
155
- strPatternStat[patternName] = strPatternStat[patternName] || {
156
- n: 0,
157
- dupN: 0,
158
- size: 0,
159
- dupSize: 0,
160
- };
161
- const item = strPatternStat[patternName];
162
- item.n += record.n;
163
- item.size += record.size;
164
- if (record.n > 1) {
165
- item.dupN += record.n - 1;
166
- item.dupSize += (record.size * (record.n - 1)) / record.n;
167
- }
175
+ aggregatePatternStat(patternName, record);
168
176
  }
169
177
  }
178
+ // calculate pattern stats for source code strings
179
+ for (const [, record] of Object.entries(sourceStringMap)) {
180
+ const patternName = 'JS code string';
181
+ aggregatePatternStat(patternName, record);
182
+ }
170
183
  this.stringPatternsStat = strPatternStat;
171
184
  }
172
185
  print() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memlab/heap-analysis",
3
- "version": "1.0.39",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "description": "heap analysis plugins for memlab",
6
6
  "author": "Liang Gong <lgong@meta.com>",
@@ -20,15 +20,15 @@
20
20
  "LICENSE"
21
21
  ],
22
22
  "dependencies": {
23
- "@memlab/core": "^1.1.42",
24
- "@memlab/e2e": "^1.0.42",
23
+ "@memlab/core": "^2.0.0",
24
+ "@memlab/e2e": "^2.0.0",
25
25
  "ansi": "^0.3.1",
26
26
  "babar": "^0.2.0",
27
27
  "chalk": "^4.0.0",
28
28
  "fs-extra": "^4.0.2",
29
29
  "minimist": "^1.2.8",
30
- "puppeteer": "^22.12.1",
31
- "puppeteer-core": "^22.12.1",
30
+ "puppeteer": "^24.2.0",
31
+ "puppeteer-core": "^24.2.0",
32
32
  "string-width": "^4.2.0",
33
33
  "util.promisify": "^1.1.1",
34
34
  "xvfb": "^0.4.0"
@@ -37,10 +37,10 @@
37
37
  "@types/fs-extra": "^9.0.3",
38
38
  "@types/jest": "^27.4.1",
39
39
  "@types/minimist": "^1.2.5",
40
- "@types/node": "^12.16.3",
40
+ "@types/node": "^25.0.0",
41
41
  "jest": "^29.6.2",
42
42
  "ts-jest": "^29.1.1",
43
- "typescript": "^5.7.2"
43
+ "typescript": "^5.9.3"
44
44
  },
45
45
  "repository": {
46
46
  "type": "git",