@memlab/cli 1.0.24 → 1.0.26

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.
Files changed (46) hide show
  1. package/dist/BaseCommand.d.ts +3 -3
  2. package/dist/BaseCommand.js +5 -1
  3. package/dist/Dispatcher.js +6 -0
  4. package/dist/commands/MemLabRunCommand.d.ts +2 -2
  5. package/dist/commands/RunMeasureCommand.d.ts +2 -2
  6. package/dist/commands/RunMeasureCommand.js +2 -0
  7. package/dist/commands/WarmupAppCommand.d.ts +2 -2
  8. package/dist/commands/WarmupAppCommand.js +2 -0
  9. package/dist/commands/heap/CheckLeakCommand.d.ts +2 -1
  10. package/dist/commands/heap/CheckLeakCommand.js +44 -5
  11. package/dist/commands/heap/DiffLeakCommand.d.ts +13 -1
  12. package/dist/commands/heap/DiffLeakCommand.js +44 -14
  13. package/dist/commands/heap/GetRetainerTraceCommand.d.ts +2 -2
  14. package/dist/commands/heap/HeapAnalysisCommand.d.ts +2 -2
  15. package/dist/commands/heap/interactive/InteractiveHeapCommand.d.ts +2 -2
  16. package/dist/commands/heap/interactive/InteractiveHeapExploreCommand.d.ts +2 -2
  17. package/dist/commands/heap/interactive/ui-components/HeapViewUtils.d.ts +2 -0
  18. package/dist/commands/heap/interactive/ui-components/HeapViewUtils.js +25 -21
  19. package/dist/commands/heap/interactive/ui-components/ListComponent.js +1 -1
  20. package/dist/commands/helper/GenerateCLIDocCommand.js +10 -7
  21. package/dist/commands/helper/HelperCommand.d.ts +7 -4
  22. package/dist/commands/helper/HelperCommand.js +17 -13
  23. package/dist/commands/helper/lib/DocUtils.d.ts +19 -0
  24. package/dist/commands/helper/lib/DocUtils.js +39 -0
  25. package/dist/commands/snapshot/TakeSnapshotCommand.d.ts +2 -2
  26. package/dist/commands/snapshot/TakeSnapshotCommand.js +2 -0
  27. package/dist/commands/snapshot/WarmupAndSnapshotCommand.d.ts +3 -1
  28. package/dist/commands/snapshot/WarmupAndSnapshotCommand.js +23 -0
  29. package/dist/lib/CLIUtils.js +15 -2
  30. package/dist/options/SetMaxClusterSampleSizeOption.d.ts +19 -0
  31. package/dist/options/SetMaxClusterSampleSizeOption.js +49 -0
  32. package/dist/options/e2e/SetChromiumBinaryOption.d.ts +18 -0
  33. package/dist/options/e2e/SetChromiumBinaryOption.js +43 -0
  34. package/dist/options/experiment/ExperimentOptionUtils.d.ts +13 -0
  35. package/dist/options/experiment/ExperimentOptionUtils.js +39 -0
  36. package/dist/options/experiment/SetControlWorkDirOption.d.ts +3 -4
  37. package/dist/options/experiment/SetControlWorkDirOption.js +3 -25
  38. package/dist/options/experiment/SetTreatmentWorkDirOption.d.ts +2 -2
  39. package/dist/options/experiment/SetTreatmentWorkDirOption.js +4 -13
  40. package/dist/options/heap/SetTraceContainsFilterOption.d.ts +18 -0
  41. package/dist/options/heap/SetTraceContainsFilterOption.js +42 -0
  42. package/dist/options/heap/TraceAllObjectsOption.d.ts +4 -2
  43. package/dist/options/heap/TraceAllObjectsOption.js +26 -4
  44. package/dist/options/lib/OptionConstant.d.ts +6 -0
  45. package/dist/options/lib/OptionConstant.js +3 -0
  46. package/package.json +1 -1
@@ -7,7 +7,7 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { CLIOptions, Nullable } from '@memlab/core';
10
+ import type { CLIOptions, CommandOptionExample, Nullable, Optional } from '@memlab/core';
11
11
  import { BaseOption } from '@memlab/core';
12
12
  export declare enum CommandCategory {
13
13
  COMMON = "COMMON",
@@ -24,7 +24,7 @@ declare abstract class Command {
24
24
  }
25
25
  export default class BaseCommand extends Command {
26
26
  getCommandName(): string;
27
- getExamples(): string[];
27
+ getExamples(): CommandOptionExample[];
28
28
  getCategory(): CommandCategory;
29
29
  getDescription(): string;
30
30
  getDocumenation(): string;
@@ -32,7 +32,7 @@ export default class BaseCommand extends Command {
32
32
  isInternalCommand(): boolean;
33
33
  getOptions(): BaseOption[];
34
34
  getExcludedOptions(): BaseOption[];
35
- getSubCommands(): BaseCommand[];
35
+ getSubCommands(): Optional<BaseCommand[]>;
36
36
  run(_options: CLIOptions): Promise<void>;
37
37
  }
38
38
  export {};
@@ -85,7 +85,7 @@ class BaseCommand extends Command {
85
85
  const className = this.constructor.name;
86
86
  throw new Error(`${className}.getCommandName is not implemented`);
87
87
  }
88
- // get a list of examples
88
+ // get a list of CLI option examples
89
89
  // examples will be displayed in helper text
90
90
  getExamples() {
91
91
  return [];
@@ -131,6 +131,10 @@ class BaseCommand extends Command {
131
131
  // for example command 'A' has two sub-commands 'B' and 'C'
132
132
  // CLI supports running in terminal: `memlab A B` or `memlab A C`
133
133
  // The parent command will be executed before its subcommands
134
+ //
135
+ // If this callback returns null or undefined, it means
136
+ // the command will handle the dispatcher won't try to match and process
137
+ // the subcommands (the command will handle sub-commands by itself).
134
138
  getSubCommands() {
135
139
  return [];
136
140
  }
@@ -107,6 +107,8 @@ class CommandDispatcher {
107
107
  const { configFromOptions } = runCmdOpt;
108
108
  // execute command
109
109
  yield command.run({ cliArgs: args, configFromOptions });
110
+ // recommand CLI command and flags
111
+ core_1.config.setRunInfo('command', process.argv.slice(2).join(' '));
110
112
  if (runCmdOpt.isPrerequisite !== true) {
111
113
  // execute subcommands
112
114
  const commandIndex = ((_a = runCmdOpt.commandIndex) !== null && _a !== void 0 ? _a : 0) + 1;
@@ -125,6 +127,10 @@ class CommandDispatcher {
125
127
  return;
126
128
  }
127
129
  const subCommands = command.getSubCommands();
130
+ // if the command will handle the sub-commands by itself
131
+ if (subCommands == null) {
132
+ return;
133
+ }
128
134
  for (const subCommand of subCommands) {
129
135
  if (subCommand.getCommandName() === args._[subCommandIndex]) {
130
136
  yield this.runCommand(subCommand, args, runCmdOpt);
@@ -7,12 +7,12 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { BaseOption, CLIOptions } from '@memlab/core';
10
+ import type { BaseOption, CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand, { CommandCategory } from '../BaseCommand';
12
12
  export default class MemLabRunCommand extends BaseCommand {
13
13
  getCommandName(): string;
14
14
  getDescription(): string;
15
- getExamples(): string[];
15
+ getExamples(): CommandOptionExample[];
16
16
  getPrerequisites(): BaseCommand[];
17
17
  getOptions(): BaseOption[];
18
18
  getExcludedOptions(): BaseOption[];
@@ -7,14 +7,14 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { CLIOptions } from '@memlab/core';
10
+ import type { CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand from '../BaseCommand';
12
12
  import { BaseOption } from '@memlab/core';
13
13
  export default class RunMeasureCommand extends BaseCommand {
14
14
  getCommandName(): string;
15
15
  getDescription(): string;
16
16
  getPrerequisites(): BaseCommand[];
17
- getExamples(): string[];
17
+ getExamples(): CommandOptionExample[];
18
18
  getOptions(): BaseOption[];
19
19
  run(options: CLIOptions): Promise<void>;
20
20
  }
@@ -45,6 +45,7 @@ const HeadfulBrowserOption_1 = __importDefault(require("../options/e2e/HeadfulBr
45
45
  const DisableWebSecurityOption_1 = __importDefault(require("../options/e2e/DisableWebSecurityOption"));
46
46
  const EnableJSRewriteOption_1 = __importDefault(require("../options/e2e/EnableJSRewriteOption"));
47
47
  const EnableJSInterceptOption_1 = __importDefault(require("../options/e2e/EnableJSInterceptOption"));
48
+ const SetChromiumBinaryOption_1 = __importDefault(require("../options/e2e/SetChromiumBinaryOption"));
48
49
  class RunMeasureCommand extends BaseCommand_1.default {
49
50
  getCommandName() {
50
51
  return 'measure';
@@ -77,6 +78,7 @@ class RunMeasureCommand extends BaseCommand_1.default {
77
78
  new RunningModeOption_1.default(),
78
79
  new RemoteBrowserDebugOption_1.default(),
79
80
  new ScenarioFileOption_1.default(),
81
+ new SetChromiumBinaryOption_1.default(),
80
82
  new SetDeviceOption_1.default(),
81
83
  new SetUserAgentOption_1.default(),
82
84
  new DisableXvfbOption_1.default(),
@@ -7,14 +7,14 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { CLIOptions } from '@memlab/core';
10
+ import type { CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import { BaseOption } from '@memlab/core';
12
12
  import BaseCommand from '../BaseCommand';
13
13
  export default class FBWarmupAppCommand extends BaseCommand {
14
14
  getCommandName(): string;
15
15
  getDescription(): string;
16
16
  getPrerequisites(): BaseCommand[];
17
- getExamples(): string[];
17
+ getExamples(): CommandOptionExample[];
18
18
  getOptions(): BaseOption[];
19
19
  run(_options: CLIOptions): Promise<void>;
20
20
  }
@@ -38,6 +38,7 @@ const HeadfulBrowserOption_1 = __importDefault(require("../options/e2e/HeadfulBr
38
38
  const DisableWebSecurityOption_1 = __importDefault(require("../options/e2e/DisableWebSecurityOption"));
39
39
  const EnableJSRewriteOption_1 = __importDefault(require("../options/e2e/EnableJSRewriteOption"));
40
40
  const EnableJSInterceptOption_1 = __importDefault(require("../options/e2e/EnableJSInterceptOption"));
41
+ const SetChromiumBinaryOption_1 = __importDefault(require("../options/e2e/SetChromiumBinaryOption"));
41
42
  class FBWarmupAppCommand extends BaseCommand_1.default {
42
43
  getCommandName() {
43
44
  return 'warmup';
@@ -62,6 +63,7 @@ class FBWarmupAppCommand extends BaseCommand_1.default {
62
63
  new RunningModeOption_1.default(),
63
64
  new RemoteBrowserDebugOption_1.default(),
64
65
  new ScenarioFileOption_1.default(),
66
+ new SetChromiumBinaryOption_1.default(),
65
67
  new SetDeviceOption_1.default(),
66
68
  new SetUserAgentOption_1.default(),
67
69
  new DisableXvfbOption_1.default(),
@@ -8,7 +8,7 @@
8
8
  * @oncall web_perf_infra
9
9
  */
10
10
  import type { ParsedArgs } from 'minimist';
11
- import type { BaseOption, CLIOptions } from '@memlab/core';
11
+ import type { BaseOption, CLIOptions, CommandOptionExample } from '@memlab/core';
12
12
  import BaseCommand, { CommandCategory } from '../../BaseCommand';
13
13
  export declare type CheckLeakCommandOptions = {
14
14
  isMLClustering?: boolean;
@@ -20,6 +20,7 @@ export default class CheckLeakCommand extends BaseCommand {
20
20
  protected restoreDefaultMLClusteringSetting(cliArgs: ParsedArgs): void;
21
21
  constructor(options?: CheckLeakCommandOptions);
22
22
  getCommandName(): string;
23
+ getExamples(): CommandOptionExample[];
23
24
  getDescription(): string;
24
25
  getDocumenation(): string;
25
26
  getCategory(): CommandCategory;
@@ -54,6 +54,7 @@ const MLClusteringLinkageMaxDistanceOption_1 = __importDefault(require("../../op
54
54
  const MLClusteringMaxDFOption_1 = __importDefault(require("../../options/MLClusteringMaxDFOption"));
55
55
  const CleanupSnapshotOption_1 = __importDefault(require("../../options/heap/CleanupSnapshotOption"));
56
56
  const SetWorkingDirectoryOption_1 = __importDefault(require("../../options/SetWorkingDirectoryOption"));
57
+ const OptionConstant_1 = __importDefault(require("../../options/lib/OptionConstant"));
57
58
  class CheckLeakCommand extends BaseCommand_1.default {
58
59
  constructor(options = {}) {
59
60
  super();
@@ -75,16 +76,54 @@ class CheckLeakCommand extends BaseCommand_1.default {
75
76
  getCommandName() {
76
77
  return 'find-leaks';
77
78
  }
79
+ getExamples() {
80
+ const optionNames = OptionConstant_1.default.optionNames;
81
+ const workDirOption = `--${optionNames.WORK_DIR}`;
82
+ const snapshotDirOption = `--${optionNames.SNAPSHOT_DIR}`;
83
+ const baselineOption = `--${optionNames.BASELINE}`;
84
+ const targetOption = `--${optionNames.TARGET}`;
85
+ const finalOption = `--${optionNames.FINAL}`;
86
+ return [
87
+ {
88
+ description: 'check memory leaks in the default working directory generated by\n' +
89
+ `memlab run (without setting the ${workDirOption} option)`,
90
+ cliOptionExample: '', // default empty command options
91
+ },
92
+ {
93
+ description: 'specify the baseline, target, and final heap snapshot file path separately',
94
+ cliOptionExample: `${baselineOption} /tmp/baseline.heapsnapshot ${targetOption} /tmp/target.heapsnapshot ${finalOption} /tmp/final.heapsnapshot`,
95
+ },
96
+ {
97
+ description: 'specifies the directory that holds all three heap snapshot files',
98
+ cliOptionExample: `${snapshotDirOption} /dir/containing/heapsnapshot/files/`,
99
+ },
100
+ {
101
+ description: 'specifies the output working directory of the `memlab run` or the `memlab snapshot` command',
102
+ cliOptionExample: `${workDirOption} /memlab/working/dir/generated/by/memlab/`,
103
+ },
104
+ ];
105
+ }
78
106
  getDescription() {
79
107
  return 'find memory leaks in heap snapshots';
80
108
  }
81
109
  getDocumenation() {
82
- return `There are three ways to specify inputs for the \`memlab find-leaks\` command:
83
- 1. \`--baseline\`, \`--target\`, \`--final\` specifies each snapshot input individually;
84
- 2. \`--snapshot-dir\` specifies the directory that holds all three heap snapshot files (MemLab will assign baseline, target, and final based on alphabetic order of the file);
85
- 3. \`--work-dir\` specifies the output working directory of the \`memlab run\` or the \`memlab snapshot\` command;
110
+ const optionNames = OptionConstant_1.default.optionNames;
111
+ const workDirOption = `--${optionNames.WORK_DIR}`;
112
+ const snapshotDirOption = `--${optionNames.SNAPSHOT_DIR}`;
113
+ const baselineOption = `--${optionNames.BASELINE}`;
114
+ const targetOption = `--${optionNames.TARGET}`;
115
+ const finalOption = `--${optionNames.FINAL}`;
116
+ return `There are three ways to specify inputs for the \`memlab ${this.getCommandName()}\` command:
117
+ 1. \`${baselineOption}\`, \`${targetOption}\`, \`${finalOption}\` specifies each heap snapshot input individually;
118
+ 2. \`${snapshotDirOption}\` specifies the directory that holds all three heap snapshot files (MemLab will assign baseline, target, and final based on alphabetic order of the file);
119
+ 3. \`${workDirOption}\` specifies the output working directory of the \`memlab run\` or the \`memlab snapshot\` command;
120
+
121
+ Please only use one of the three ways to specify the input.
86
122
 
87
- Please only use one of the three ways to specify the input.`;
123
+ You can also manually take heap snapshots in Chrome Devtools, save them to disk.
124
+ Then process them using this command with the CLI flags (either option 1
125
+ or option 2 mentioned above).
126
+ `;
88
127
  }
89
128
  getCategory() {
90
129
  return BaseCommand_1.CommandCategory.COMMON;
@@ -7,14 +7,26 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { BaseOption, CLIOptions } from '@memlab/core';
10
+ import type { ParsedArgs } from 'minimist';
11
+ import { BaseOption, CLIOptions } from '@memlab/core';
12
+ import type { CheckLeakCommandOptions } from './CheckLeakCommand';
11
13
  import BaseCommand, { CommandCategory } from '../../BaseCommand';
14
+ export declare type WorkDirSettings = {
15
+ controlWorkDirs: Array<string>;
16
+ treatmentWorkDirs: Array<string>;
17
+ };
12
18
  export default class CheckLeakCommand extends BaseCommand {
19
+ private isMLClustering;
20
+ private isMLClusteringSettingCache;
21
+ protected useDefaultMLClusteringSetting(cliArgs: ParsedArgs): void;
22
+ protected restoreDefaultMLClusteringSetting(cliArgs: ParsedArgs): void;
23
+ constructor(options?: CheckLeakCommandOptions);
13
24
  getCommandName(): string;
14
25
  getDescription(): string;
15
26
  getCategory(): CommandCategory;
16
27
  getPrerequisites(): BaseCommand[];
17
28
  getOptions(): BaseOption[];
29
+ protected getWorkDirs(options: CLIOptions): WorkDirSettings;
18
30
  run(options: CLIOptions): Promise<void>;
19
31
  }
20
32
  //# sourceMappingURL=DiffLeakCommand.d.ts.map
@@ -50,7 +50,26 @@ const MLClusteringLinkageMaxDistanceOption_1 = __importDefault(require("../../op
50
50
  const MLClusteringMaxDFOption_1 = __importDefault(require("../../options/MLClusteringMaxDFOption"));
51
51
  const SetControlWorkDirOption_1 = __importDefault(require("../../options/experiment/SetControlWorkDirOption"));
52
52
  const SetTreatmentWorkDirOption_1 = __importDefault(require("../../options/experiment/SetTreatmentWorkDirOption"));
53
+ const SetMaxClusterSampleSizeOption_1 = __importDefault(require("../../options/SetMaxClusterSampleSizeOption"));
54
+ const SetTraceContainsFilterOption_1 = __importDefault(require("../../options/heap/SetTraceContainsFilterOption"));
53
55
  class CheckLeakCommand extends BaseCommand_1.default {
56
+ constructor(options = {}) {
57
+ super();
58
+ this.isMLClustering = false;
59
+ this.isMLClusteringSettingCache = false;
60
+ this.isMLClustering = !!(options === null || options === void 0 ? void 0 : options.isMLClustering);
61
+ }
62
+ useDefaultMLClusteringSetting(cliArgs) {
63
+ if (!MLClusteringOption_1.default.hasOptionSet(cliArgs)) {
64
+ core_1.config.isMLClustering = this.isMLClustering;
65
+ this.isMLClusteringSettingCache = core_1.config.isMLClustering;
66
+ }
67
+ }
68
+ restoreDefaultMLClusteringSetting(cliArgs) {
69
+ if (!MLClusteringOption_1.default.hasOptionSet(cliArgs)) {
70
+ core_1.config.isMLClustering = this.isMLClusteringSettingCache;
71
+ }
72
+ }
54
73
  getCommandName() {
55
74
  return 'diff-leaks';
56
75
  }
@@ -65,8 +84,8 @@ class CheckLeakCommand extends BaseCommand_1.default {
65
84
  }
66
85
  getOptions() {
67
86
  return [
68
- new SetControlWorkDirOption_1.default().required(),
69
- new SetTreatmentWorkDirOption_1.default().required(),
87
+ new SetControlWorkDirOption_1.default(),
88
+ new SetTreatmentWorkDirOption_1.default(),
70
89
  new JSEngineOption_1.default(),
71
90
  new LeakFilterFileOption_1.default(),
72
91
  new OversizeThresholdOption_1.default(),
@@ -76,28 +95,39 @@ class CheckLeakCommand extends BaseCommand_1.default {
76
95
  new MLClusteringOption_1.default(),
77
96
  new MLClusteringLinkageMaxDistanceOption_1.default(),
78
97
  new MLClusteringMaxDFOption_1.default(),
98
+ new SetMaxClusterSampleSizeOption_1.default(),
99
+ new SetTraceContainsFilterOption_1.default(),
79
100
  ];
80
101
  }
81
- run(options) {
102
+ getWorkDirs(options) {
82
103
  var _a, _b;
104
+ // double check parameters
105
+ if (!((_a = options.configFromOptions) === null || _a === void 0 ? void 0 : _a.controlWorkDirs) ||
106
+ !((_b = options.configFromOptions) === null || _b === void 0 ? void 0 : _b.treatmentWorkDirs)) {
107
+ core_1.info.error('Please specify control and test working directory');
108
+ throw core_1.utils.haltOrThrow('No control or test working directory specified');
109
+ }
110
+ // get parameters
111
+ const controlWorkDirs = options.configFromOptions['controlWorkDirs'];
112
+ const treatmentWorkDirs = options.configFromOptions['treatmentWorkDirs'];
113
+ return {
114
+ controlWorkDirs,
115
+ treatmentWorkDirs,
116
+ };
117
+ }
118
+ run(options) {
83
119
  return __awaiter(this, void 0, void 0, function* () {
84
120
  core_1.config.chaseWeakMapEdge = false;
85
- // double check parameters
86
- if (!((_a = options.configFromOptions) === null || _a === void 0 ? void 0 : _a.controlWorkDirs) ||
87
- !((_b = options.configFromOptions) === null || _b === void 0 ? void 0 : _b.treatmentWorkDir)) {
88
- core_1.info.error('Please specify control and test working directory');
89
- throw core_1.utils.haltOrThrow('No control or test working directory specified');
90
- }
91
- // get parameters
92
- const controlWorkDirs = options.configFromOptions['controlWorkDirs'];
93
- const treatmentWorkDir = options.configFromOptions['treatmentWorkDir'];
121
+ const { controlWorkDirs, treatmentWorkDirs } = this.getWorkDirs(options);
94
122
  const { runMetaInfoManager } = core_1.runInfoUtils;
95
123
  runMetaInfoManager.setConfigFromRunMeta({
96
- workDir: treatmentWorkDir,
124
+ workDir: treatmentWorkDirs[0],
97
125
  silentFail: true,
98
126
  });
99
127
  // diff memory leaks
100
- yield core_1.analysis.diffLeakByWorkDir({ controlWorkDirs, treatmentWorkDir });
128
+ this.useDefaultMLClusteringSetting(options.cliArgs);
129
+ yield core_1.analysis.diffLeakByWorkDir({ controlWorkDirs, treatmentWorkDirs });
130
+ this.restoreDefaultMLClusteringSetting(options.cliArgs);
101
131
  });
102
132
  }
103
133
  }
@@ -7,14 +7,14 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { CLIOptions } from '@memlab/core';
10
+ import type { CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand, { CommandCategory } from '../../BaseCommand';
12
12
  import { BaseOption } from '@memlab/core';
13
13
  export default class GetRetainerTraceCommand extends BaseCommand {
14
14
  getCommandName(): string;
15
15
  getDescription(): string;
16
16
  getCategory(): CommandCategory;
17
- getExamples(): string[];
17
+ getExamples(): CommandOptionExample[];
18
18
  getOptions(): BaseOption[];
19
19
  run(options: CLIOptions): Promise<void>;
20
20
  }
@@ -7,7 +7,7 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { CLIOptions } from '@memlab/core';
10
+ import type { CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand, { CommandCategory } from '../../BaseCommand';
12
12
  export default class RunHeapAnalysisCommand extends BaseCommand {
13
13
  getCommandName(): string;
@@ -15,7 +15,7 @@ export default class RunHeapAnalysisCommand extends BaseCommand {
15
15
  getCategory(): CommandCategory;
16
16
  getPrerequisites(): BaseCommand[];
17
17
  getSubCommands(): BaseCommand[];
18
- getExamples(): string[];
18
+ getExamples(): CommandOptionExample[];
19
19
  run(options: CLIOptions): Promise<void>;
20
20
  }
21
21
  //# sourceMappingURL=HeapAnalysisCommand.d.ts.map
@@ -7,14 +7,14 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import { CLIOptions } from '@memlab/core';
10
+ import { CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand, { CommandCategory } from '../../../BaseCommand';
12
12
  import { BaseOption } from '@memlab/core';
13
13
  export default class InteractiveHeapCommand extends BaseCommand {
14
14
  getCommandName(): string;
15
15
  getDescription(): string;
16
16
  getCategory(): CommandCategory;
17
- getExamples(): string[];
17
+ getExamples(): CommandOptionExample[];
18
18
  getOptions(): BaseOption[];
19
19
  private exitAttempt;
20
20
  private printPromptInfo;
@@ -7,13 +7,13 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { BaseOption, CLIOptions } from '@memlab/core';
10
+ import type { BaseOption, CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand, { CommandCategory } from '../../../BaseCommand';
12
12
  export default class InteractiveHeapViewCommand extends BaseCommand {
13
13
  getCommandName(): string;
14
14
  getDescription(): string;
15
15
  getCategory(): CommandCategory;
16
- getExamples(): string[];
16
+ getExamples(): CommandOptionExample[];
17
17
  getOptions(): BaseOption[];
18
18
  private getHeap;
19
19
  private getNodesToFocus;
@@ -17,6 +17,8 @@ export declare class ComponentDataItem {
17
17
  type?: string;
18
18
  details?: Map<string, string>;
19
19
  static getTextForDisplay(data: ComponentDataItem): string;
20
+ private static getHeapObjectTextContent;
21
+ private static getHeapEdgeTextContent;
20
22
  private static getTextContent;
21
23
  }
22
24
  export declare class ComponentData {
@@ -66,6 +66,28 @@ class ComponentDataItem {
66
66
  }
67
67
  return chalk_1.default.grey(content);
68
68
  }
69
+ static getHeapObjectTextContent(node) {
70
+ const objectType = chalk_1.default.grey(`(${node.type})`);
71
+ const objectId = chalk_1.default.grey(` @${node.id}`);
72
+ const size = core_1.utils.getReadableBytes(node.retainedSize);
73
+ const sizeInfo = chalk_1.default.grey(' [') + chalk_1.default.bold(chalk_1.default.blue(size)) + chalk_1.default.grey(']');
74
+ const objectTitle = node.isString ? '<string>' : node.name;
75
+ return (chalk_1.default.green('[') +
76
+ (isUsefulObjectForDebugging(node)
77
+ ? chalk_1.default.green(objectTitle)
78
+ : chalk_1.default.bold(chalk_1.default.grey(objectTitle))) +
79
+ chalk_1.default.green(']') +
80
+ objectType +
81
+ objectId +
82
+ sizeInfo);
83
+ }
84
+ static getHeapEdgeTextContent(edge) {
85
+ const arrowPrefix = chalk_1.default.grey('--');
86
+ const arrowSuffix = chalk_1.default.grey('---') + '>';
87
+ const edgeType = chalk_1.default.grey(`(${edge.type})`);
88
+ const edgeName = edge.name_or_index;
89
+ return `${arrowPrefix}${edgeName}${edgeType}${arrowSuffix} `;
90
+ }
69
91
  static getTextContent(data) {
70
92
  let ret = '';
71
93
  if (data.tag) {
@@ -74,32 +96,14 @@ class ComponentDataItem {
74
96
  if (data.stringContent) {
75
97
  ret += data.stringContent;
76
98
  }
77
- const arrowPrefix = chalk_1.default.grey('--');
78
- const arrowSuffix = chalk_1.default.grey('---') + '>';
79
99
  if (data.referrerEdge) {
80
- const edgeType = chalk_1.default.grey(`(${data.referrerEdge.type})`);
81
- const edgeName = data.referrerEdge.name_or_index;
82
- ret += `${arrowPrefix}${edgeName}${edgeType}${arrowSuffix} `;
100
+ ret += this.getHeapEdgeTextContent(data.referrerEdge);
83
101
  }
84
102
  if (data.heapObject) {
85
- const objectType = chalk_1.default.grey(`(${data.heapObject.type})`);
86
- const objectId = chalk_1.default.grey(` @${data.heapObject.id}`);
87
- const size = core_1.utils.getReadableBytes(data.heapObject.retainedSize);
88
- const sizeInfo = chalk_1.default.grey(' [') + chalk_1.default.bold(chalk_1.default.blue(size)) + chalk_1.default.grey(']');
89
- ret +=
90
- chalk_1.default.green('[') +
91
- (isUsefulObjectForDebugging(data.heapObject)
92
- ? chalk_1.default.green(data.heapObject.name)
93
- : chalk_1.default.bold(chalk_1.default.grey(data.heapObject.name))) +
94
- chalk_1.default.green(']') +
95
- objectType +
96
- objectId +
97
- sizeInfo;
103
+ ret += this.getHeapObjectTextContent(data.heapObject);
98
104
  }
99
105
  if (data.referenceEdge) {
100
- const edgeType = chalk_1.default.grey(`(${data.referenceEdge.type})`);
101
- const edgeName = data.referenceEdge.name_or_index;
102
- ret += ` ${arrowPrefix}${edgeName}${edgeType}${arrowSuffix} `;
106
+ ret += this.getHeapEdgeTextContent(data.referenceEdge);
103
107
  }
104
108
  return ret === '' ? chalk_1.default.grey('<undefinied>') : ret;
105
109
  }
@@ -203,7 +203,7 @@ class ListComponent {
203
203
  this.element.pushItem(content[i]);
204
204
  ++this.displayedItems;
205
205
  }
206
- this.content = content;
206
+ this.content = content.map(v => v.replace(/\n/g, '\\n'));
207
207
  this.horizonScrollPositionMap.clear();
208
208
  this.insertDisplayMoreEntry();
209
209
  this.updateContent(oldContent, this.content);
@@ -46,6 +46,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
46
46
  Object.defineProperty(exports, "__esModule", { value: true });
47
47
  const path_1 = __importDefault(require("path"));
48
48
  const fs_extra_1 = __importDefault(require("fs-extra"));
49
+ const DocUtils_1 = __importDefault(require("./lib/DocUtils"));
49
50
  const BaseCommand_1 = __importStar(require("../../BaseCommand"));
50
51
  const core_1 = require("@memlab/core");
51
52
  const UniversalOptions_1 = __importDefault(require("../../options/lib/UniversalOptions"));
@@ -86,6 +87,10 @@ class GenerateCLIDocCommand extends BaseCommand_1.default {
86
87
  }
87
88
  writeCommandCategories(docFile) {
88
89
  this.writeTextWithNewLine(docFile, '# Command Line Interface');
90
+ this.writeTextWithNewLine(docFile, `Install the memlab command line tool with npm:
91
+ \`\`\`bash
92
+ npm install -g memlab
93
+ \`\`\``);
89
94
  for (const category in BaseCommand_1.CommandCategory) {
90
95
  const commandsToPrintFirst = [];
91
96
  this.writeCategory(docFile, category, commandsToPrintFirst);
@@ -131,6 +136,7 @@ class GenerateCLIDocCommand extends BaseCommand_1.default {
131
136
  this.writeTextWithNewLine(docFile, `\n## ${categoryName} Commands\n`);
132
137
  }
133
138
  writeCommand(docFile, command, indent = '') {
139
+ var _a, _b;
134
140
  const name = command.getFullCommand();
135
141
  const desc = core_1.utils.upperCaseFirstCharacter(command.getDescription().trim());
136
142
  const cmdDoc = command.getDocumenation().trim();
@@ -144,17 +150,14 @@ class GenerateCLIDocCommand extends BaseCommand_1.default {
144
150
  }
145
151
  // get example
146
152
  const examples = command.getExamples();
147
- let example = '';
148
- if (examples.length > 0) {
149
- example = examples[0].trim();
150
- }
153
+ const example = (_a = examples[0]) !== null && _a !== void 0 ? _a : '';
151
154
  // write command synopsis
152
- const cmd = `memlab ${name} ${example}`;
155
+ const cmd = DocUtils_1.default.generateExampleCommand(name, example);
153
156
  this.writeCodeBlock(docFile, cmd, 'bash');
154
157
  // write command examples if there is any
155
158
  const exampleBlock = examples
156
159
  .slice(1)
157
- .map(example => `memlab ${name} ${example.trim()}`)
160
+ .map(example => DocUtils_1.default.generateExampleCommand(name, example))
158
161
  .join('\n');
159
162
  if (exampleBlock.length > 0) {
160
163
  this.writeTextWithNewLine(docFile, '\n#### examples\n');
@@ -162,7 +165,7 @@ class GenerateCLIDocCommand extends BaseCommand_1.default {
162
165
  }
163
166
  // write options
164
167
  this.writeCommandOptions(docFile, command);
165
- const subCommands = command.getSubCommands();
168
+ const subCommands = (_b = command.getSubCommands()) !== null && _b !== void 0 ? _b : [];
166
169
  for (const subCommand of subCommands) {
167
170
  this.writeCommand(docFile, subCommand, indent + '#');
168
171
  }
@@ -7,20 +7,23 @@
7
7
  * @format
8
8
  * @oncall web_perf_infra
9
9
  */
10
- import type { BaseOption, CLIOptions } from '@memlab/core';
10
+ import type { BaseOption, CLIOptions, CommandOptionExample } from '@memlab/core';
11
11
  import BaseCommand from '../../BaseCommand';
12
- declare type HelperOption = CLIOptions & {
12
+ declare type PrintCommandOptions = {
13
+ printOptions?: boolean;
14
+ printDoc?: boolean;
15
+ };
16
+ declare type HelperOption = CLIOptions & PrintCommandOptions & {
13
17
  modules: Map<string, BaseCommand>;
14
18
  command: BaseCommand | null;
15
19
  indent?: string;
16
- printOptions?: boolean;
17
20
  };
18
21
  export default class HelperCommand extends BaseCommand {
19
22
  private printedCommand;
20
23
  private universalOptions;
21
24
  getCommandName(): string;
22
25
  getDescription(): string;
23
- getExamples(): string[];
26
+ getExamples(): CommandOptionExample[];
24
27
  setUniversalOptions(options: BaseOption[]): void;
25
28
  private printHeader;
26
29
  private printCommandCategories;