# @clinic/heap-profiler 中文文档

规范地址：https://npmcn.com/package/%40clinic/heap-profiler/

版本：5\.0\.0
npm 元数据更新时间：2023-06-27T21:03:27.955Z
中文译文更新时间：2026-11-10T01:45:59.703Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40clinic/heap-profiler
原文对照：https://npmcn.com/package/%40clinic/heap-profiler/?lang=original
项目主页：https://github.com/clinicjs/node-clinic-heap-profiler#readme
源码仓库：https://github.com/clinicjs/node-clinic-heap-profiler

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：333 kB，154 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：13 个
- 首次发布：2021-11-12T16:20:21.889Z
- 最新版本发布：2023-06-27T21:03:27.732Z
- 近 30 天下载量：170003（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

可编程到 Clinic.js Heap 配置器的接口

## 安装

```sh
npm install @clinic/heap-profiler
```

也可以使用：`pnpm add @clinic/heap-profiler`、`yarn add @clinic/heap-profiler`、`bun add @clinic/heap-profiler`

## README

# 诊所.js Heap 剖析器

[![npm version](https://img.shields.io/npm/v/@clinic/heap-profiler.svg?style=flat-square)](https://www.npmjs.org/@clinic/heap-profiler) [![Stability Stable](https://img.shields.io/badge/stability-stable-green.svg?style=flat-square)](https://nodejs.org/api/documentation.html#documentation_stability_index) [![Github Actions build status](https://github.com/clinicjs/node-clinic-flame/workflows/CI/badge.svg)](https://github.com/clinicjs/node-clinic-flame/actions) [![Downloads](http://img.shields.io/npm/dm/@clinic/heap-profiler.svg?style=flat-square)](https://www.npmjs.org/@clinic/heap-profiler) [![Code style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

可编程接口到 [诊所.js](https://github.com/clinicjs/node-clinic) 平面剖面仪. 更多关于诊所的知识 [https://clinicjs.org/ (中文(简体) )](https://clinicjs.org/)

![screenshot](https://user-images.githubusercontent.com/26234614/143886238-481abe39-4cc7-470a-a1cd-144a73a070b9.png)

## 问题

打开一个问题,请使用 [主要仓库](https://github.com/clinicjs/node-clinic) 与 `heapprofiler` 标签.

## 安装

```console
npm i -S @clinic/heap-profiler
```

## 支持的节点版本

-   16及以上节点j

## 示例

```js
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
  })
})
```

## 文档

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

### 新建 ClinicHeap 预览器( \[设置\])

-   设置 [`<Object>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
    -   检测端口 [`<boolean>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) **默认**错误
    -   收藏失败 [`<boolean>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) 如果设定为真,即使进程以非零代码退出,所收集的数据也会被返回. **默认**错误
    -   调试 [`<boolean>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type) 如果设置为真, 生成的 html 将不会被修改 . **默认**错误
    -   离线 [`<String>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) 所收集数据的目的 **默认**数字 : `.clinic`
    -   名称 [`<String>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) 所收集数据的文件名 **默认**数字 : `<process.pid>.clinic-heapprofiler`

#### `heapProfiler.collect(args, callback)`

通过使用 [@ nearform/ hiap- profile](https://github.com/nearform/heap-profiler)。 。 。 .

过程采样工作一开始就立即开始. 所收集数据的文件路径将是回调值 .

`stdout`, (中文(简体) ), `stderr`,以及 `stdin` 将转发到呼叫程序.

采样在过程退出前被停止并收集数据.

如果想要更早收集数据,可以发送进程 a `SIGINT` 或,如果 `detectPort` 实值 `true`你可以打电话 `heapProfiler.stopViaIPC()`。 。 。 .

#### `heapProfiler.visualize(dataFilename, outputFilename, callback)`

将消耗由 `dataFilename`,此数据文件将是 采样者使用 `heapProfiler.collect`。 。 。 .

`heapProfiler.visualize` 然后输出一个独立的 HTML 文件到 `outputFilename`。 。 。 . 完成后 `callback` 将被调用,除了一个 可能的错误.

#### `heapProfiler.stopViaIPC()`

当配置器以 `detectPort=true`,剖析器建立了基于TCP的IPC通信.

因此,可以在任何时候使用这种方法来收集数据.

如果没有打开或可用的 TCP 频道, 该方法将不进行操作, 因此它可以安全地随时拨打 .

## 实例

见 `examples` 文件夹。 所有示例应在主文件夹中运行:

```sh
node examples/redis-web-service
```

每个 `index.js` 将包含示例所要求的任何具体设置步骤.

## 许可证

[麻省理工学院](https://npmcn.com/package/%40clinic/heap-profiler/LICENSE)

## 常见问题

### @clinic/heap-profiler 是什么？

可编程到 Clinic\.js Heap 配置器的接口

### 如何安装 @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 和提交记录判断。

