@memlab/core 1.1.17 → 1.1.18

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,8 +8,7 @@
8
8
  * @oncall web_perf_infra
9
9
  */
10
10
  import type { LaunchOptions, Permission } from 'puppeteer';
11
- import type { AnyFunction, AnyValue, IClusterStrategy, IRunningMode, IScenario, Nullable, Optional, QuickExperiment, ILeakFilter, IPackageInfo } from './Types';
12
- import { IHeapConfig } from '..';
11
+ import type { AnyFunction, AnyValue, FileOption, IClusterStrategy, IRunningMode, IScenario, IHeapConfig, Nullable, Optional, QuickExperiment, ILeakFilter, IPackageInfo } from './Types';
13
12
  interface BrowserLaunchArgumentOptions {
14
13
  headless?: boolean;
15
14
  userDataDir?: string;
@@ -217,6 +216,8 @@ export declare class MemLabConfig {
217
216
  set disableWebSecurity(disable: boolean);
218
217
  get disableWebSecurity(): boolean;
219
218
  get browserBinaryPath(): string;
219
+ set defaultFileManagerOption(fileOption: FileOption);
220
+ get defaultFileManagerOption(): FileOption;
220
221
  set reportLeaksInTimers(shouldReport: boolean);
221
222
  get reportLeaksInTimers(): boolean;
222
223
  setDevice(deviceName: string, options?: {
@@ -8,6 +8,29 @@
8
8
  * @format
9
9
  * @oncall web_perf_infra
10
10
  */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
11
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
36
  };
@@ -17,7 +40,7 @@ const path_1 = __importDefault(require("path"));
17
40
  const RunningModes_1 = __importDefault(require("../modes/RunningModes"));
18
41
  const Console_1 = __importDefault(require("./Console"));
19
42
  const Constant_1 = __importDefault(require("./Constant"));
20
- const FileManager_1 = __importDefault(require("./FileManager"));
43
+ const FileManager_1 = __importStar(require("./FileManager"));
21
44
  const InternalValueSetter_1 = require("./InternalValueSetter");
22
45
  const devices = Constant_1.default.isFRL
23
46
  ? {}
@@ -429,6 +452,17 @@ class MemLabConfig {
429
452
  get browserBinaryPath() {
430
453
  return path_1.default.join(this.browserDir, this.browser);
431
454
  }
455
+ // Default input option for file manager.
456
+ // If no other input option is provided, the file manager
457
+ // will generate directories and files based on this default option.
458
+ set defaultFileManagerOption(fileOption) {
459
+ FileManager_1.FileManager.defaultFileOption = fileOption;
460
+ // initialize file and directory paths
461
+ FileManager_1.default.initDirs(this, fileOption);
462
+ }
463
+ get defaultFileManagerOption() {
464
+ return FileManager_1.FileManager.defaultFileOption;
465
+ }
432
466
  set reportLeaksInTimers(shouldReport) {
433
467
  if (shouldReport) {
434
468
  this.removeFromSet(this.nodeNameBlockList, this._timerNodes);
@@ -8,35 +8,31 @@
8
8
  * @oncall web_perf_infra
9
9
  */
10
10
  import type { MemLabConfig } from './Config';
11
- import type { AnyValue, Optional } from './Types';
12
- /** @internal */
13
- export declare type FileOption = {
14
- workDir?: Optional<string>;
15
- clear?: boolean;
16
- transient?: boolean;
17
- };
11
+ import type { AnyValue, FileOption } from './Types';
18
12
  /** @internal */
19
13
  export declare class FileManager {
20
14
  getDefaultWorkDir(): string;
21
15
  generateTmpHeapDir(): string;
22
16
  private static transientInstanceIdx;
17
+ static defaultFileOption: FileOption;
23
18
  getWorkDir(options?: FileOption): string;
24
19
  getChromeBinaryZipFile(): string;
25
20
  getChromeBinaryTimeStampFile(): string;
26
21
  getChromeBinaryDir(): string;
27
- clearUserDataDir(options: FileOption): void;
28
- getDataBaseDir(options: FileOption): string;
22
+ getDataBaseDir(options?: FileOption): string;
29
23
  getCodeDataDir(): string;
30
24
  getClusterSampleDataDir(): string;
31
- getUserDataDir(options: FileOption): string;
32
- getCurDataDir(options: FileOption): string;
25
+ getUserDataDir(options?: FileOption): string;
26
+ clearUserDataDir(options?: FileOption): void;
27
+ getCurDataDir(options?: FileOption): string;
33
28
  getWebSourceDir(options?: FileOption): string;
34
29
  getWebSourceMetaFile(options?: FileOption): string;
35
30
  getDebugDataDir(options?: FileOption): string;
36
31
  getDebugSourceFile(options?: FileOption): string;
37
- getPersistDataDir(options: FileOption): string;
32
+ getPersistDataDir(options?: FileOption): string;
38
33
  getLoggerOutDir(options?: FileOption): string;
39
34
  getHeapAnalysisLogDir(options?: FileOption): string;
35
+ getHeapSaveLogJSONFile(options?: FileOption): string;
40
36
  getTraceClustersDir(options?: FileOption): string;
41
37
  getTraceJSONDir(options?: FileOption): string;
42
38
  getUnclassifiedTraceClusterDir(options?: FileOption): string;
@@ -24,7 +24,7 @@ function joinAndProcessDir(options, ...args) {
24
24
  const filepath = path_1.default.join(...args);
25
25
  if (!fs_extra_1.default.existsSync(filepath)) {
26
26
  try {
27
- fs_extra_1.default.mkdirSync(filepath);
27
+ fs_extra_1.default.mkdirpSync(filepath);
28
28
  }
29
29
  catch (ex) {
30
30
  const err = Utils_1.default.getError(ex);
@@ -43,11 +43,11 @@ class FileManager {
43
43
  generateTmpHeapDir() {
44
44
  const dirPath = path_1.default.join(this.getTmpDir(), 'memlab-' + Utils_1.default.getUniqueID());
45
45
  if (!fs_extra_1.default.existsSync(dirPath)) {
46
- fs_extra_1.default.mkdirSync(dirPath);
46
+ fs_extra_1.default.mkdirpSync(dirPath);
47
47
  }
48
48
  return dirPath;
49
49
  }
50
- getWorkDir(options = {}) {
50
+ getWorkDir(options = FileManager.defaultFileOption) {
51
51
  // workDir options supercedes all the other options
52
52
  if (options.workDir) {
53
53
  return path_1.default.resolve(options.workDir);
@@ -73,11 +73,7 @@ class FileManager {
73
73
  getChromeBinaryDir() {
74
74
  return path_1.default.join(this.getDefaultWorkDir(), 'chrome');
75
75
  }
76
- clearUserDataDir(options) {
77
- const userDataDir = this.getUserDataDir(options);
78
- this.rmDir(userDataDir);
79
- }
80
- getDataBaseDir(options) {
76
+ getDataBaseDir(options = FileManager.defaultFileOption) {
81
77
  return path_1.default.join(this.getWorkDir(options), 'data');
82
78
  }
83
79
  getCodeDataDir() {
@@ -86,66 +82,74 @@ class FileManager {
86
82
  getClusterSampleDataDir() {
87
83
  return path_1.default.join(this.getCodeDataDir(), 'cluster');
88
84
  }
89
- getUserDataDir(options) {
85
+ getUserDataDir(options = FileManager.defaultFileOption) {
90
86
  return path_1.default.join(this.getDataBaseDir(options), 'profile');
91
87
  }
92
- getCurDataDir(options) {
88
+ clearUserDataDir(options = FileManager.defaultFileOption) {
89
+ const userDataDir = this.getUserDataDir(options);
90
+ this.rmDir(userDataDir);
91
+ }
92
+ getCurDataDir(options = FileManager.defaultFileOption) {
93
93
  return path_1.default.join(this.getDataBaseDir(options), 'cur');
94
94
  }
95
- getWebSourceDir(options = {}) {
95
+ getWebSourceDir(options = FileManager.defaultFileOption) {
96
96
  return path_1.default.join(this.getCurDataDir(options), 'code');
97
97
  }
98
- getWebSourceMetaFile(options = {}) {
98
+ getWebSourceMetaFile(options = FileManager.defaultFileOption) {
99
99
  return path_1.default.join(this.getWebSourceDir(options), 'files.json');
100
100
  }
101
- getDebugDataDir(options = {}) {
101
+ getDebugDataDir(options = FileManager.defaultFileOption) {
102
102
  return path_1.default.join(this.getDataBaseDir(options), 'debug');
103
103
  }
104
- getDebugSourceFile(options = {}) {
104
+ getDebugSourceFile(options = FileManager.defaultFileOption) {
105
105
  return path_1.default.join(this.getDebugDataDir(options), 'file.js');
106
106
  }
107
- getPersistDataDir(options) {
107
+ getPersistDataDir(options = FileManager.defaultFileOption) {
108
108
  return path_1.default.join(this.getDataBaseDir(options), 'persist');
109
109
  }
110
- getLoggerOutDir(options = {}) {
110
+ getLoggerOutDir(options = FileManager.defaultFileOption) {
111
111
  return path_1.default.join(this.getDataBaseDir(options), 'logger');
112
112
  }
113
113
  // all heap analysis results generated
114
- getHeapAnalysisLogDir(options = {}) {
114
+ getHeapAnalysisLogDir(options = FileManager.defaultFileOption) {
115
115
  return path_1.default.join(this.getLoggerOutDir(options), 'heap-analysis');
116
116
  }
117
+ // memlab save-heap result log file
118
+ getHeapSaveLogJSONFile(options = FileManager.defaultFileOption) {
119
+ return path_1.default.join(this.getHeapAnalysisLogDir(options), 'save-heap.json');
120
+ }
117
121
  // all trace clusters generated from the current run
118
- getTraceClustersDir(options = {}) {
122
+ getTraceClustersDir(options = FileManager.defaultFileOption) {
119
123
  return path_1.default.join(this.getLoggerOutDir(options), 'trace-clusters');
120
124
  }
121
125
  // stores JSON file (with heap object and reference details for visualization)
122
126
  // of all trace clusters (each cluster has a representative trace)
123
- getTraceJSONDir(options = {}) {
127
+ getTraceJSONDir(options = FileManager.defaultFileOption) {
124
128
  return path_1.default.join(this.getLoggerOutDir(options), 'trace-jsons');
125
129
  }
126
- getUnclassifiedTraceClusterDir(options = {}) {
130
+ getUnclassifiedTraceClusterDir(options = FileManager.defaultFileOption) {
127
131
  return path_1.default.join(this.getLoggerOutDir(options), 'unclassified-clusters');
128
132
  }
129
- getUniqueTraceClusterDir(options = {}) {
133
+ getUniqueTraceClusterDir(options = FileManager.defaultFileOption) {
130
134
  return path_1.default.join(this.getLoggerOutDir(options), 'unique-trace-clusters');
131
135
  }
132
- getNewUniqueTraceClusterDir(options = {}) {
136
+ getNewUniqueTraceClusterDir(options = FileManager.defaultFileOption) {
133
137
  return path_1.default.join(this.getUniqueTraceClusterDir(options), 'add');
134
138
  }
135
- getStaleUniqueTraceClusterDir(options = {}) {
139
+ getStaleUniqueTraceClusterDir(options = FileManager.defaultFileOption) {
136
140
  return path_1.default.join(this.getUniqueTraceClusterDir(options), 'delete');
137
141
  }
138
- getAllClusterSummaryFile(options = {}) {
142
+ getAllClusterSummaryFile(options = FileManager.defaultFileOption) {
139
143
  return path_1.default.join(this.getUniqueTraceClusterDir(options), 'unique-clusters-summary.txt');
140
144
  }
141
- getExistingUniqueTraceClusterDir(options = {}) {
145
+ getExistingUniqueTraceClusterDir(options = FileManager.defaultFileOption) {
142
146
  return path_1.default.join(this.getUniqueTraceClusterDir(options), 'existing');
143
147
  }
144
148
  getAllFilesInDir(dir) {
145
149
  const files = fs_extra_1.default.readdirSync(dir);
146
150
  return files.map((file) => path_1.default.join(dir, file));
147
151
  }
148
- getDataOutDir(options = {}) {
152
+ getDataOutDir(options = FileManager.defaultFileOption) {
149
153
  return path_1.default.join(this.getDataBaseDir(options), 'out');
150
154
  }
151
155
  getCoreProjectBaseDir() {
@@ -157,19 +161,19 @@ class FileManager {
157
161
  getDocDir() {
158
162
  return path_1.default.join(this.getMonoRepoDir(), 'website', 'docs');
159
163
  }
160
- getReportOutDir(options = {}) {
164
+ getReportOutDir(options = FileManager.defaultFileOption) {
161
165
  return path_1.default.join(this.getPersistDataDir(options), 'reports');
162
166
  }
163
- getPreviewReportDir(options = {}) {
167
+ getPreviewReportDir(options = FileManager.defaultFileOption) {
164
168
  return path_1.default.join(this.getPersistDataDir(options), 'report-preview');
165
169
  }
166
- getLeakSummaryFile(options = {}) {
170
+ getLeakSummaryFile(options = FileManager.defaultFileOption) {
167
171
  return path_1.default.join(this.getDataOutDir(options), 'leaks.txt');
168
172
  }
169
- getRunMetaFile(options = {}) {
173
+ getRunMetaFile(options = FileManager.defaultFileOption) {
170
174
  return path_1.default.join(this.getCurDataDir(options), 'run-meta.json');
171
175
  }
172
- getSnapshotSequenceMetaFile(options = {}) {
176
+ getSnapshotSequenceMetaFile(options = FileManager.defaultFileOption) {
173
177
  return path_1.default.join(this.getCurDataDir(options), 'snap-seq.json');
174
178
  }
175
179
  getInputDataDir() {
@@ -192,6 +196,7 @@ class FileManager {
192
196
  }
193
197
  return ret;
194
198
  }
199
+ // system default tmp dir
195
200
  getTmpDir() {
196
201
  return os_1.default.tmpdir();
197
202
  }
@@ -211,7 +216,7 @@ class FileManager {
211
216
  return { controlWorkDir, testWorkDir };
212
217
  }
213
218
  // create a unique log file created for heap analysis output
214
- initNewHeapAnalysisLogFile(options = {}) {
219
+ initNewHeapAnalysisLogFile(options = FileManager.defaultFileOption) {
215
220
  const dir = this.getHeapAnalysisLogDir(options);
216
221
  const file = path_1.default.join(dir, `analysis-${Utils_1.default.getUniqueID()}-out.log`);
217
222
  if (!fs_extra_1.default.existsSync(file)) {
@@ -222,10 +227,10 @@ class FileManager {
222
227
  getAndInitTSCompileIntermediateDir() {
223
228
  const dir = path_1.default.join(this.getTmpDir(), 'memlab-code');
224
229
  this.rmDir(dir);
225
- fs_extra_1.default.mkdirSync(dir);
230
+ fs_extra_1.default.mkdirpSync(dir);
226
231
  return dir;
227
232
  }
228
- clearDataDirs(options = {}) {
233
+ clearDataDirs(options = FileManager.defaultFileOption) {
229
234
  const curDataDir = this.getCurDataDir(options);
230
235
  if (!fs_extra_1.default.existsSync(curDataDir)) {
231
236
  return;
@@ -249,7 +254,7 @@ class FileManager {
249
254
  fs_extra_1.default.emptyDirSync(dir);
250
255
  }
251
256
  }
252
- emptyTraceLogDataDir(options = {}) {
257
+ emptyTraceLogDataDir(options = FileManager.defaultFileOption) {
253
258
  // all leak trace clusters
254
259
  this.emptyDirIfExists(this.getTraceClustersDir(options));
255
260
  // all JSON files for trace visualization
@@ -290,7 +295,7 @@ class FileManager {
290
295
  this.iterateAllFiles(filepath, callback);
291
296
  });
292
297
  }
293
- rmWorkDir(options = {}) {
298
+ rmWorkDir(options = FileManager.defaultFileOption) {
294
299
  try {
295
300
  this.rmDir(this.getWorkDir(options));
296
301
  }
@@ -303,7 +308,7 @@ class FileManager {
303
308
  const internalDir = Constant_1.default.internalDir;
304
309
  return filePath.includes(`${sep}${internalDir}${sep}`);
305
310
  }
306
- initDirs(config, options = {}) {
311
+ initDirs(config, options = FileManager.defaultFileOption) {
307
312
  config.monoRepoDir = Constant_1.default.monoRepoDir;
308
313
  // make sure getWorkDir is called first before
309
314
  // any other get file or get dir calls
@@ -356,4 +361,5 @@ class FileManager {
356
361
  }
357
362
  exports.FileManager = FileManager;
358
363
  FileManager.transientInstanceIdx = 0;
364
+ FileManager.defaultFileOption = {};
359
365
  exports.default = new FileManager();
@@ -43,6 +43,12 @@ export declare type HaltOrThrowOptions = {
43
43
  printCallback?: () => void;
44
44
  };
45
45
  /** @internal */
46
+ export declare type FileOption = {
47
+ workDir?: Optional<string>;
48
+ clear?: boolean;
49
+ transient?: boolean;
50
+ };
51
+ /** @internal */
46
52
  export declare type CLIOptions = {
47
53
  cliArgs: ParsedArgs;
48
54
  configFromOptions?: AnyRecord;
@@ -122,7 +122,7 @@ declare function getError(maybeError: unknown): Error;
122
122
  declare function isNodeDominatedByDeletionsArray(node: IHeapNode): boolean;
123
123
  declare function getUniqueID(): string;
124
124
  declare function getClosureSourceUrl(node: IHeapNode): Nullable<string>;
125
- export declare function runShell(command: string, options?: ShellOptions): string;
125
+ export declare function runShell(command: string, options?: ShellOptions): Nullable<string>;
126
126
  export declare function getRetainedSize(node: IHeapNode): number;
127
127
  export declare function aggregateDominatorMetrics(ids: HeapNodeIdSet, snapshot: IHeapSnapshot, checkNodeCb: (node: IHeapNode) => boolean, nodeMetricsCb: (node: IHeapNode) => number): number;
128
128
  declare const _default: {
package/dist/lib/Utils.js CHANGED
@@ -1764,7 +1764,7 @@ function runShell(command, options = {}) {
1764
1764
  if (process_1.default.platform !== 'win32') {
1765
1765
  execOptions.shell = '/bin/bash';
1766
1766
  }
1767
- let ret = '';
1767
+ let ret = null;
1768
1768
  try {
1769
1769
  ret = child_process_1.default.execSync(command, execOptions);
1770
1770
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memlab/core",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "license": "MIT",
5
5
  "description": "memlab core libraries",
6
6
  "author": "Liang Gong <lgong@fb.com>",