跳到主要内容

类: BaseAnalysis

继承关系

构造函数

new BaseAnalysis()

方法

analyzeSnapshotFromFile(file, options?)

为单个堆快照文件运行堆分析

  • 参数:
    • file: string | .heapsnapshot 文件的绝对路径。
    • options: RunHeapAnalysisOptions | 堆分析运行的可选配置
  • 返回值: Promise<AnalyzeSnapshotResult>| 这个 API 返回 AnalyzeSnapshotResult, 其中包含分析控制台输出的日志文件。或者,要获得更结构化的分析结果,请查看托管堆分析类的文档,并在调用此方法后调用特定于分析的 API 以获取结果。
  • 示例:
const analysis = new StringAnalysis();
// analysis console output is saved in result.analysisOutputFile
const result = await analysis.analyzeSnapshotFromFile(snapshotFile);
// query analysis-specific and structured results
const stringPatterns = analysis.getTopDuplicatedStringsInCount();

此外,您可以指定一个工作目录,中间文件、日志文件和最终输出文件将被转储到该目录

const analysis = new StringAnalysis();
// analysis console output is saved in result.analysisOutputFile
// which is inside the specified working directory
const result = await analysis.analyzeSnapshotFromFile(snapshotFile, {
// if the specified directory doesn't exist, memlab will create it
workDir: '/tmp/your/work/dir',
});

analyzeSnapshotsInDirectory(directory, options?)

为一系列堆快照文件运行堆分析

  • 参数:
    • directory: string | 包含一系列 .heapsnapshot 文件的目录的绝对路径,所有快照文件将按照这些快照文件名称的字母数字升序加载和分析。
    • options: RunHeapAnalysisOptions | 堆分析运行的可选配置
  • 返回值: Promise<AnalyzeSnapshotResult>| 这个 API 返回 AnalyzeSnapshotResult, 其中包含分析控制台输出的日志文件。或者,要获得更结构化的分析结果,请查看托管堆分析类的文档,并在调用此方法后调用特定于分析的 API 以获取结果。
  • 示例:
const analysis = new ShapeUnboundGrowthAnalysis();
// analysis console output is saved in result.analysisOutputFile
const result = await analysis.analyzeSnapshotsInDirectory(snapshotDirectory);
// query analysis-specific and structured results
const shapes = analysis.getShapesWithUnboundGrowth();
  • 此外,您可以指定一个工作目录,中间文件、日志文件和最终输出文件将被转储到该目录
const analysis = new ShapeUnboundGrowthAnalysis();
// analysis console output is saved in result.analysisOutputFile
// which is inside the specified working directory
const result = await analysis.analyzeSnapshotsInDirectory(snapshotDirectory, {
// if the specified directory doesn't exist, memlab will create it
workDir: '/tmp/your/work/dir',
});

getCommandName()

获取堆分析的名称,该名称也用于在 memlab 命令行工具中引用分析。

以下终端命令将使用此分析启动:memlab analyze <ANALYSIS_NAME>

  • 返回值: string | 分析的名称
  • 示例:
const analysis = new YourAnalysis();
const name = analysis.getCommandName();

getDescription()

获取堆分析的文本描述。 此分析的描述将由以下命令打印:memlab analyze list


getOptions()

如果您希望 CLI 打印选项信息,请覆盖此方法


process(options)

memlab analyze <command-name> 的回调。在此回调中进行内存分析并打印结果。分析应支持:1) 在屏幕上打印结果 2) 通过返回值返回结果

  • 继承关系
  • 构造函数
    • new BaseAnalysis()
  • 方法
    • analyzeSnapshotFromFile(file, options?)
    • analyzeSnapshotsInDirectory(directory, options?)
    • getCommandName()
    • getDescription()
    • getOptions()
    • process(options)