@clinic/heap-profiler

中文文档
5.0.0发布于 2023/06/28MITCommonJS近 30 天下载 17万

Programmable interface to Clinic.js Heap Profiler

原始使用文档
文档目录8 节
  1. Issues
  2. Installation
  3. Supported node versions
  4. Example
  5. Documentation
  6. new ClinicHeapProfiler([settings])
  7. Examples
  8. License

Clinic.js Heap Profiler

npm version Stability Stable Github Actions build status Downloads Code style

Programmable interface to Clinic.js Heap Profiler. Learn more about Clinic.js: https://clinicjs.org/

screenshot

Issues

To open an issue, please use the main repository with the heapprofiler label.

Installation

npm i -S @clinic/heap-profiler

Supported node versions

  • Node.js 16 and above

Example

const ClinicHeapProfiler = require('@clinic/heap-profiler')
const heapProfiler = new ClinicHeapProfiler()

heapProfiler.collect(['node', './path-to-script.js'], function (err, filepath) {
  if (err) throw err

  heapProfiler.visualize(filepath, filepath + '.html', function (err) {
    if (err) throw err
  })
})

Documentation

const ClinicHeapProfiler = require('@clinic/heap-profiler')
const heapProfiler = new ClinicHeapProfiler()

new ClinicHeapProfiler([settings])

  • settings <Object>
    • detectPort <boolean> Default: false
    • collectOnFailure <boolean> If set to true, the collected data will be returned even if the process exits with non-zero code. Default: false
    • debug <boolean> If set to true, the generated html will not be minified. Default: false
    • dest <String> Destination for the collected data Default: .clinic
    • name <String> File name for the collected data Default: <process.pid>.clinic-heapprofiler

heapProfiler.collect(args, callback)

Starts a process by using @nearform/heap-profiler.

The process sampling is started as soon as the process starts. The filepath with collected data will be the value in the callback.

stdout, stderr, and stdin will be relayed to the calling process.

The sampling is stopped and data collected right before the process exits.

If you want to collect data earlier, you can send the process a SIGINT or, if detectPort is true, you can call heapProfiler.stopViaIPC().

heapProfiler.visualize(dataFilename, outputFilename, callback)

Will consume the datafile specified by dataFilename, this datafile will be produced by the sampler using heapProfiler.collect.

heapProfiler.visualize will then output a standalone HTML file to outputFilename. When completed the callback will be called with no extra arguments, except a possible error.

heapProfiler.stopViaIPC()

When the profiler is started with detectPort=true, the profiler establish a TCP based IPC communication.

This method can therefore be called to collect the data at any time.

If no TCP channel is opened or available, the method will perform no operation so it is safe to call at all times.

Examples

See the examples folder. All example should be run from the repository main folder:

node examples/redis-web-service

Each index.js will contain any specific setup step required by the example, if any.

License

MIT

版本与发布记录

@clinic/heap-profiler 共发布 7 个版本,首次发布于 2021/11/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2023/06/283 年前
4.1.12023/04/293 年前
4.1.02023/03/163 年前
4.0.02022/08/264 年前
3.2.02021/12/104 年前
3.1.02021/11/174 年前

关于 @clinic/heap-profiler 的常见问题

@clinic/heap-profiler 是什么?

Programmable interface to Clinic.js Heap Profiler

如何安装 @clinic/heap-profiler?

在项目目录运行 npm install @clinic/heap-profiler,或使用 pnpm add / yarn add / bun add。

@clinic/heap-profiler 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/clinic__heap-profiler 是否存在。

@clinic/heap-profiler 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@clinic/heap-profiler 可以商用吗?

@clinic/heap-profiler 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@clinic/heap-profiler 的下载量有多少?

根据 npm 官方下载统计,@clinic/heap-profiler 在 2026/10/10 – 2026/11/08 这 30 天内被下载 170,003 次,日均约 5,667 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@clinic/heap-profiler 还在维护吗?

最新版本 5.0.0 发布于 2023/06/28(3 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/11/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。