@memlab/heap-analysis 1.0.15 → 1.0.17

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.
@@ -8,7 +8,7 @@
8
8
  * @oncall web_perf_infra
9
9
  */
10
10
  import type { AnyValue, BaseOption } from '@memlab/core';
11
- import type { AnalyzeSnapshotResult, HeapAnalysisOptions } from './PluginUtils';
11
+ import type { AnalyzeSnapshotResult, HeapAnalysisOptions, RunHeapAnalysisOptions } from './PluginUtils';
12
12
  declare abstract class Analysis {
13
13
  process(_options: HeapAnalysisOptions): Promise<void>;
14
14
  /**
@@ -26,6 +26,7 @@ declare abstract class Analysis {
26
26
  /**
27
27
  * Run heap analysis for a single heap snapshot file
28
28
  * @param file the absolute path of a `.heapsnapshot` file.
29
+ * @param options optional configuration for the heap analysis run
29
30
  * @returns this API returns {@link AnalyzeSnapshotResult}, which contains
30
31
  * the logging file of analysis console output. Alternatively, to get more
31
32
  * structured analysis results, check out the documentation of the hosting
@@ -35,17 +36,29 @@ declare abstract class Analysis {
35
36
  * ```typescript
36
37
  * const analysis = new StringAnalysis();
37
38
  * // analysis console output is saved in result.analysisOutputFile
38
- * const result = await anaysis.analyzeSnapshotFromFile(snapshotFile);
39
+ * const result = await analysis.analyzeSnapshotFromFile(snapshotFile);
39
40
  * // query analysis-specific and structured results
40
41
  * const stringPatterns = analysis.getTopDuplicatedStringsInCount();
41
42
  * ```
43
+ * Additionally, you can specify a working directory to where
44
+ * the intermediate, logging, and final output files will be dumped:
45
+ * ```typescript
46
+ * const analysis = new StringAnalysis();
47
+ * // analysis console output is saved in result.analysisOutputFile
48
+ * // which is inside the specified working directory
49
+ * const result = await analysis.analyzeSnapshotFromFile(snapshotFile, {
50
+ * // if the specified directory doesn't exist, memlab will create it
51
+ * workDir: '/tmp/your/work/dir',
52
+ * });
53
+ * ```
42
54
  */
43
- analyzeSnapshotFromFile(file: string): Promise<AnalyzeSnapshotResult>;
55
+ analyzeSnapshotFromFile(file: string, options?: RunHeapAnalysisOptions): Promise<AnalyzeSnapshotResult>;
44
56
  /**
45
57
  * Run heap analysis for a series of heap snapshot files
46
58
  * @param directory the absolute path of the directory holding a series of
47
59
  * `.heapsnapshot` files, all snapshot files will be loaded and analyzed
48
60
  * in the alphanumerically ascending order of those snapshot file names.
61
+ * @param options optional configuration for the heap analysis run
49
62
  * @returns this API returns {@link AnalyzeSnapshotResult}, which contains
50
63
  * the logging file of analysis console output. Alternatively, to get more
51
64
  * structured analysis results, check out the documentation of the hosting
@@ -55,12 +68,23 @@ declare abstract class Analysis {
55
68
  * ```typescript
56
69
  * const analysis = new ShapeUnboundGrowthAnalysis();
57
70
  * // analysis console output is saved in result.analysisOutputFile
58
- * const result = await anaysis.analyzeSnapshotsInDirectory(snapshotDirectory);
71
+ * const result = await analysis.analyzeSnapshotsInDirectory(snapshotDirectory);
59
72
  * // query analysis-specific and structured results
60
73
  * const shapes = analysis.getShapesWithUnboundGrowth();
61
74
  * ```
75
+ * * Additionally, you can specify a working directory to where
76
+ * the intermediate, logging, and final output files will be dumped:
77
+ * ```typescript
78
+ * const analysis = new ShapeUnboundGrowthAnalysis();
79
+ * // analysis console output is saved in result.analysisOutputFile
80
+ * // which is inside the specified working directory
81
+ * const result = await analysis.analyzeSnapshotsInDirectory(snapshotDirectory, {
82
+ * // if the specified directory doesn't exist, memlab will create it
83
+ * workDir: '/tmp/your/work/dir',
84
+ * });
85
+ * ```
62
86
  */
63
- analyzeSnapshotsInDirectory(directory: string): Promise<AnalyzeSnapshotResult>;
87
+ analyzeSnapshotsInDirectory(directory: string, options?: RunHeapAnalysisOptions): Promise<AnalyzeSnapshotResult>;
64
88
  }
65
89
  /**
66
90
  *
@@ -68,6 +68,7 @@ class Analysis {
68
68
  /**
69
69
  * Run heap analysis for a single heap snapshot file
70
70
  * @param file the absolute path of a `.heapsnapshot` file.
71
+ * @param options optional configuration for the heap analysis run
71
72
  * @returns this API returns {@link AnalyzeSnapshotResult}, which contains
72
73
  * the logging file of analysis console output. Alternatively, to get more
73
74
  * structured analysis results, check out the documentation of the hosting
@@ -77,13 +78,28 @@ class Analysis {
77
78
  * ```typescript
78
79
  * const analysis = new StringAnalysis();
79
80
  * // analysis console output is saved in result.analysisOutputFile
80
- * const result = await anaysis.analyzeSnapshotFromFile(snapshotFile);
81
+ * const result = await analysis.analyzeSnapshotFromFile(snapshotFile);
81
82
  * // query analysis-specific and structured results
82
83
  * const stringPatterns = analysis.getTopDuplicatedStringsInCount();
83
84
  * ```
85
+ * Additionally, you can specify a working directory to where
86
+ * the intermediate, logging, and final output files will be dumped:
87
+ * ```typescript
88
+ * const analysis = new StringAnalysis();
89
+ * // analysis console output is saved in result.analysisOutputFile
90
+ * // which is inside the specified working directory
91
+ * const result = await analysis.analyzeSnapshotFromFile(snapshotFile, {
92
+ * // if the specified directory doesn't exist, memlab will create it
93
+ * workDir: '/tmp/your/work/dir',
94
+ * });
95
+ * ```
84
96
  */
85
- analyzeSnapshotFromFile(file) {
97
+ analyzeSnapshotFromFile(file, options = {}) {
86
98
  return __awaiter(this, void 0, void 0, function* () {
99
+ if (options.workDir) {
100
+ // set and init the new work dir
101
+ core_1.config.defaultFileManagerOption = options;
102
+ }
87
103
  const analysisOutputFile = core_1.fileManager.initNewHeapAnalysisLogFile();
88
104
  core_1.info.registerLogFile(analysisOutputFile);
89
105
  yield this.process({
@@ -102,6 +118,7 @@ class Analysis {
102
118
  * @param directory the absolute path of the directory holding a series of
103
119
  * `.heapsnapshot` files, all snapshot files will be loaded and analyzed
104
120
  * in the alphanumerically ascending order of those snapshot file names.
121
+ * @param options optional configuration for the heap analysis run
105
122
  * @returns this API returns {@link AnalyzeSnapshotResult}, which contains
106
123
  * the logging file of analysis console output. Alternatively, to get more
107
124
  * structured analysis results, check out the documentation of the hosting
@@ -111,13 +128,28 @@ class Analysis {
111
128
  * ```typescript
112
129
  * const analysis = new ShapeUnboundGrowthAnalysis();
113
130
  * // analysis console output is saved in result.analysisOutputFile
114
- * const result = await anaysis.analyzeSnapshotsInDirectory(snapshotDirectory);
131
+ * const result = await analysis.analyzeSnapshotsInDirectory(snapshotDirectory);
115
132
  * // query analysis-specific and structured results
116
133
  * const shapes = analysis.getShapesWithUnboundGrowth();
117
134
  * ```
135
+ * * Additionally, you can specify a working directory to where
136
+ * the intermediate, logging, and final output files will be dumped:
137
+ * ```typescript
138
+ * const analysis = new ShapeUnboundGrowthAnalysis();
139
+ * // analysis console output is saved in result.analysisOutputFile
140
+ * // which is inside the specified working directory
141
+ * const result = await analysis.analyzeSnapshotsInDirectory(snapshotDirectory, {
142
+ * // if the specified directory doesn't exist, memlab will create it
143
+ * workDir: '/tmp/your/work/dir',
144
+ * });
145
+ * ```
118
146
  */
119
- analyzeSnapshotsInDirectory(directory) {
147
+ analyzeSnapshotsInDirectory(directory, options = {}) {
120
148
  return __awaiter(this, void 0, void 0, function* () {
149
+ if (options.workDir) {
150
+ // set and init the new work dir
151
+ core_1.config.defaultFileManagerOption = options;
152
+ }
121
153
  const analysisOutputFile = core_1.fileManager.initNewHeapAnalysisLogFile();
122
154
  core_1.info.registerLogFile(analysisOutputFile);
123
155
  yield this.process({
@@ -25,6 +25,17 @@ export declare type HeapAnalysisOptions = {
25
25
  /** @internal */
26
26
  config?: MemLabConfig;
27
27
  };
28
+ /**
29
+ * This is the input option for {@link analyzeSnapshotFromFile}
30
+ * and {@link analyzeSnapshotsInDirectory}.
31
+ */
32
+ export declare type RunHeapAnalysisOptions = {
33
+ /**
34
+ * specify the working directory to where the intermediate, logging,
35
+ * and output files should be saved
36
+ */
37
+ workDir?: string;
38
+ };
28
39
  /**
29
40
  * This is the return type from calling {@link analyzeSnapshotFromFile}
30
41
  * or {@link analyzeSnapshotsInDirectory}.
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare function registerPackage(): Promise<void>;
12
12
  export declare const getDominatorNodes: (ids: Set<number>, snapshot: import("@memlab/core").IHeapSnapshot) => Set<number>,
13
13
  /** @deprecated */
14
14
  getHeapFromFile: (file: string) => Promise<import("@memlab/core").IHeapSnapshot>, getFullHeapFromFile: (file: string) => Promise<import("@memlab/core").IHeapSnapshot>, getSnapshotDirForAnalysis: (options: import("./PluginUtils").HeapAnalysisOptions) => import("@memlab/core").Nullable<string>, getSnapshotFileForAnalysis: (options: import("./PluginUtils").HeapAnalysisOptions) => string, loadHeapSnapshot: (options: import("./PluginUtils").HeapAnalysisOptions) => Promise<import("@memlab/core").IHeapSnapshot>, snapshotMapReduce: <T1, T2>(mapCallback: (snapshot: import("@memlab/core").IHeapSnapshot, i: number, file: string) => T1, reduceCallback: (results: T1[]) => T2, options: import("./PluginUtils").HeapAnalysisOptions) => Promise<T2>, takeNodeFullHeap: () => Promise<import("@memlab/core").IHeapSnapshot>;
15
- export type { HeapAnalysisOptions } from './PluginUtils';
15
+ export type { AnalyzeSnapshotResult, HeapAnalysisOptions, RunHeapAnalysisOptions, } from './PluginUtils';
16
16
  export { default as BaseAnalysis } from './BaseAnalysis';
17
17
  export { default as DetachedDOMElementAnalysis } from './plugins/DetachedDOMElementAnalysis';
18
18
  export { default as GlobalVariableAnalysis } from './plugins/GlobalVariableAnalysis/GlobalVariableAnalysis';
@@ -54,7 +54,7 @@ class CollectionUnboundGrowthAnalysis extends BaseAnalysis_1.default {
54
54
  const snapshotDir = PluginUtils_1.default.getSnapshotDirForAnalysis(options);
55
55
  const opt = snapshotDir ? { minSnapshots: 2, snapshotDir } : {};
56
56
  core_1.config.chaseWeakMapEdge = false;
57
- core_1.analysis.visualizeMemoryUsage(opt);
57
+ core_1.memoryBarChart.plotMemoryBarChart(opt);
58
58
  core_1.utils.checkSnapshots(opt);
59
59
  yield this.checkUnboundCollection(opt);
60
60
  });
@@ -58,7 +58,7 @@ class ObjectUnboundGrowthAnalysis extends BaseAnalysis_1.default {
58
58
  }
59
59
  checkUnbound(options = {}) {
60
60
  return __awaiter(this, void 0, void 0, function* () {
61
- core_1.analysis.visualizeMemoryUsage(options);
61
+ core_1.memoryBarChart.plotMemoryBarChart(options);
62
62
  core_1.utils.checkSnapshots(options);
63
63
  yield this.detectUnboundGrowth(options);
64
64
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memlab/heap-analysis",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "license": "MIT",
5
5
  "description": "heap analysis plugins for memlab",
6
6
  "author": "Liang Gong <lgong@fb.com>",