# @dnlup/doc 中文文档

规范地址：https://npmcn.com/package/%40dnlup/doc/

版本：5\.0\.4
npm 元数据更新时间：2025-02-18T08:08:48.303Z
中文译文更新时间：2026-11-12T13:28:12.285Z
软件包许可：ISC

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

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

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

- 包体积（解压后）：49.2 kB，24 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：1 个
- 首次发布：2020-03-30T18:27:12.348Z
- 最新版本发布：2025-02-18T08:08:48.117Z
- 近 30 天下载量：4740（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：28（近 12 个月 0 个）

## 中文简介

获取关于您节点js进程的使用和健康数据

## 安装

```sh
npm install @dnlup/doc
```

也可以使用：`pnpm add @dnlup/doc`、`yarn add @dnlup/doc`、`bun add @dnlup/doc`

## README

# 医生

[![npm version](https://badge.fury.io/js/%40dnlup%2Fdoc.svg)](https://badge.fury.io/js/%40dnlup%2Fdoc) ![Tests](https://github.com/dnlup/doc/workflows/Tests/badge.svg) ![Benchmarks](https://github.com/dnlup/doc/workflows/Benchmarks/badge.svg) [![codecov](https://codecov.io/gh/dnlup/doc/branch/next/graph/badge.svg?token=2I4S01J2X3)](https://codecov.io/gh/dnlup/doc) [![Known Vulnerabilities](https://snyk.io/test/github/dnlup/doc/badge.svg?targetFile=package.json)](https://snyk.io/test/github/dnlup/doc?targetFile=package.json)

> 获取关于您节点js过程的使用情况和健康数据 .

`doc` 是一个小模块,帮助您收集有关您节点js过程的健康指标. 它只使用节点本身(没有本土依赖)上可用的API来做到这一点. 它与APM平台没有任何联系,因此你可以随意使用任何你想要的用于此目的. 它的 API 允许您在可能时访问计算值和原始值.

-   [安装](https://npmcn.com/package/%40dnlup/doc/#readme-installation) \* 联合国 [最新稳定版本](https://npmcn.com/package/%40dnlup/doc/#readme-latest-stable-version) \* 联合国 [最新开发版本](https://npmcn.com/package/%40dnlup/doc/#readme-latest-development-version)
-   [使用量](https://npmcn.com/package/%40dnlup/doc/#readme-usage) \* 联合国 [正在用普通JS导入](https://npmcn.com/package/%40dnlup/doc/#readme-importing-with-commonjs) \* 联合国 [采用无害环境管理的进口](https://npmcn.com/package/%40dnlup/doc/#readme-importing-with-esm) \* 联合国 [说明](https://npmcn.com/package/%40dnlup/doc/#readme-note) - 说吧 [启用/ 无效的计量集合](https://npmcn.com/package/%40dnlup/doc/#readme-enabledisable-metrics-collection) - 说吧 [垃圾收集](https://npmcn.com/package/%40dnlup/doc/#readme-garbage-collection) - 说吧 [活动控点](https://npmcn.com/package/%40dnlup/doc/#readme-active-handles)
    -   [实例](https://npmcn.com/package/%40dnlup/doc/#readme-examples)
-   [API 密码](https://npmcn.com/package/%40dnlup/doc/#readme-api)
    -   [`doc([options])`](https://npmcn.com/package/%40dnlup/doc/#readme-docoptions)
    -   [类 : `doc.Sampler`](https://npmcn.com/package/%40dnlup/doc/#readme-class-docsampler)
        -   [新设 `doc.Sampler([options])`](https://npmcn.com/package/%40dnlup/doc/#readme-new-docsampleroptions)
        -   [活动: '`sample`'](https://npmcn.com/package/%40dnlup/doc/#readme-event-sample)
        -   [`sampler.start()`](https://npmcn.com/package/%40dnlup/doc/#readme-samplerstart)
        -   [`sampler.stop()`](https://npmcn.com/package/%40dnlup/doc/#readme-samplerstop)
        -   [`sampler.cpu`](https://npmcn.com/package/%40dnlup/doc/#readme-samplercpu)
        -   [`sampler.resourceUsage`](https://npmcn.com/package/%40dnlup/doc/#readme-samplerresourceusage)
        -   [`sampler.eventLoopDelay`](https://npmcn.com/package/%40dnlup/doc/#readme-samplereventloopdelay)
        -   [`sampler.eventLoopUtilization`](https://npmcn.com/package/%40dnlup/doc/#readme-samplereventlooputilization)
        -   [`sampler.gc`](https://npmcn.com/package/%40dnlup/doc/#readme-samplergc)
        -   [`sampler.activeHandles`](https://npmcn.com/package/%40dnlup/doc/#readme-sampleractivehandles)
        -   [`sampler.memory`](https://npmcn.com/package/%40dnlup/doc/#readme-samplermemory)
    -   [类 : `CpuMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-cpumetric)
        -   [`cpuMetric.usage`](https://npmcn.com/package/%40dnlup/doc/#readme-cpumetricusage)
        -   [`cpuMetric.raw`](https://npmcn.com/package/%40dnlup/doc/#readme-cpumetricraw)
    -   [类 : `ResourceUsageMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-resourceusagemetric)
        -   [`resourceUsage.cpu`](https://npmcn.com/package/%40dnlup/doc/#readme-resourceusagecpu)
        -   [`resourceUsage.raw`](https://npmcn.com/package/%40dnlup/doc/#readme-resourceusageraw)
    -   [类 : `EventLoopDelayMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-eventloopdelaymetric)
        -   [`eventLoopDelay.computed`](https://npmcn.com/package/%40dnlup/doc/#readme-eventloopdelaycomputed)
        -   [`eventLoopDelay.raw`](https://npmcn.com/package/%40dnlup/doc/#readme-eventloopdelayraw)
        -   [`eventLoopDelay.compute(raw)`](https://npmcn.com/package/%40dnlup/doc/#readme-eventloopdelaycomputeraw)
    -   [类 : `EventLoopUtilizationMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-eventlooputilizationmetric)
        -   [`eventLoopUtilization.idle`](https://npmcn.com/package/%40dnlup/doc/#readme-eventlooputilizationidle)
        -   [`eventLoopUtilization.active`](https://npmcn.com/package/%40dnlup/doc/#readme-eventlooputilizationactive)
        -   [`eventLoopUtilization.utilization`](https://npmcn.com/package/%40dnlup/doc/#readme-eventlooputilizationutilization)
        -   [`eventLoopUtilization.raw`](https://npmcn.com/package/%40dnlup/doc/#readme-eventlooputilizationraw)
    -   [类 : `GCMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcmetric)
        -   [`new GCMetric(options)`](https://npmcn.com/package/%40dnlup/doc/#readme-new-gcmetricoptions)
    -   [`gcMetric.pause`](https://npmcn.com/package/%40dnlup/doc/#readme-gcmetricpause)
        -   [`gcMetric.major`](https://npmcn.com/package/%40dnlup/doc/#readme-gcmetricmajor)
        -   [`gcMetric.minor`](https://npmcn.com/package/%40dnlup/doc/#readme-gcmetricminor)
        -   [`gcMetric.incremental`](https://npmcn.com/package/%40dnlup/doc/#readme-gcmetricincremental)
        -   [`gcMetric.weakCb`](https://npmcn.com/package/%40dnlup/doc/#readme-gcmetricweakcb)
    -   [类 : `GCEntry`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)
        -   [`new GCEntry()`](https://npmcn.com/package/%40dnlup/doc/#readme-new-gcentry)
        -   [`gcEntry.totalDuration`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrytotalduration)
        -   [`gcEntry.totalCount`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrytotalcount)
        -   [`gcEntry.mean`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrymean)
        -   [`gcEntry.max`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrymax)
        -   [`gcEntry.min`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrymin)
        -   [`gcEntry.stdDeviation`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrystddeviation)
        -   [`gcEntry.getPercentile(percentile)`](https://npmcn.com/package/%40dnlup/doc/#readme-gcentrygetpercentilepercentile)
    -   [类 : `GCAggregatedEntry`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcaggregatedentry)
        -   [`new GCAggregatedEntry()`](https://npmcn.com/package/%40dnlup/doc/#readme-new-gcaggregatedentry)
        -   [`gcAggregatedEntry.flags`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflags)
        -   [`gcAggregatedEntry.flags.no`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagsno)
        -   [`gcAggregatedEntry.flags.constructRetained`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagsconstructretained)
        -   [`gcAggregatedEntry.flags.forced`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagsforced)
        -   [`gcAggregatedEntry.flags.synchronousPhantomProcessing`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagssynchronousphantomprocessing)
        -   [`gcAggregatedEntry.flags.allAvailableGarbage`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagsallavailablegarbage)
        -   [`gcAggregatedEntry.flags.allExternalMemory`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagsallexternalmemory)
        -   [`gcAggregatedEntry.flags.scheduleIdle`](https://npmcn.com/package/%40dnlup/doc/#readme-gcaggregatedentryflagsscheduleidle)
    -   [`doc.errors`](https://npmcn.com/package/%40dnlup/doc/#readme-docerrors)
    -   [诊断通道支持](https://npmcn.com/package/%40dnlup/doc/#readme-diagnostics-channel-support)
-   [许可证](https://npmcn.com/package/%40dnlup/doc/#readme-license)

## 安装

###### 最新稳定版本

```bash
$ npm i @dnlup/doc
```

###### 最新开发版本

```bash
$ npm i @dnlup/doc@next
```

## 使用量

您可以使用普通JS或无害环境管理导入模块.

默认 `doc` 返回 a [`Sampler`](https://npmcn.com/package/%40dnlup/doc/#readme-class-docsampler) 实例,用于收集cpu、内存使用、事件循环延迟和事件循环利用的度量.

###### 正在用普通JS导入

```js
const doc = require('@dnlup/doc')

const sampler = doc() // Use the default options

sampler.on('sample', () => {
  doStuffWithCpuUsage(sampler.cpu.usage)
  doStuffWithMemoryUsage(sampler.memory)
  doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
  doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.utilization) // Available only on Node versions that support it
})
```

###### 采用无害环境管理的进口

```js
import doc from '@dnlup/doc'

const sampler = doc()

sampler.on('sample', () => {
  doStuffWithCpuUsage(sampler.cpu.usage)
  doStuffWithMemoryUsage(sampler.memory)
  doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
  doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.utilization) // Available only on Node versions that support it
})
```

###### 说明

A 类 `Sampler` 保存在指定样本间隔取自的度量标准快照. 这种行为使案件变得非常活跃. 每次勾选时,都会有新的快照覆盖上一张.

##### 启用/ 无效的计量集合

你可以禁用你不需要的度量衡.

```js
const doc = require('@dnlup/doc')

// Collect only the event loop delay
const sampler = doc({ collect: { cpu: false, memory: false } })

sampler.on('sample', () => {
  // `sampler.cpu` will be `undefined`
  // `sampler.memory` will be `undefined`
  doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
  doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.utilization) // Available only on Node versions that support it
})
```

需要时可以启用更多度量衡.

##### 垃圾收集

```js
const doc = require('@dnlup/doc')

const sampler = doc({ collect: { gc: true } })
sampler.on('sample', () => {
  doStuffWithCpuUsage(sampler.cpu.usage)
  doStuffWithMemoryUsage(sampler.memory)
  doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
  doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.utilization) // Available only on Node versions that support it
  doStuffWithGarbageCollectionDuration(sampler.gc.pause)
})
```

##### 活动控点

```js
const doc = require('@dnlup/doc')

const sampler = doc({ collect: { activeHandles: true } })

sampler.on('sample', () => {
  doStuffWithCpuUsage(sampler.cpu.usage)
  doStuffWithMemoryUsage(sampler.memory)
  doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
  doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.utilization) // Available only on Node versions that support it
  doStuffWithActiveHandles(sampler.activeHandles)
})
```

### 实例

您可以在 [`examples`](https://npmcn.com/package/%40dnlup/doc/examples) 文件夹.

## API 密码

### `doc([options])`

它创造了一个指标 [`Sampler`](https://npmcn.com/package/%40dnlup/doc/#readme-class-docsampler) 选项.

-   `options` `<Object>`: 与 `Sampler` [`options`](https://npmcn.com/package/%40dnlup/doc/#readme-new-docsampleroptions)。 。 。 .
-   回返情况: [`<Sampler>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-docsampler)

### 类 : `doc.Sampler`

-   扩展 [`EventEmitter`](https://nodejs.org/dist/latest-v18.x/docs/api/events.html#events_class_eventemitter)。 。 。 .

量子标本.

它在正常间隔中收集所选的度量衡. A 类 `Sampler` 因此,每个勾选时, 只有最后一个样本的值。 每次样本都发出 [`sample`](https://npmcn.com/package/%40dnlup/doc/#readme-event-sample) 事件,它将覆盖上一个事件.

#### 新设 `doc.Sampler([options])`

-   `options` `<Object>`
    -   `sampleInterval` `<number>`:样本间隔(ms)以获得样本. 每个 `sampleInterval` 编号 a [`sample`](https://npmcn.com/package/%40dnlup/doc/#readme-event-sample) 事件已释放. **默认 :** `1000` 在套件的盖子下 [`monitorEventLoopDelay`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options) 以跟踪事件循环延迟.
    -   `autoStart` `<boolean>`: 自动开始收集度量衡. **默认 :** `true`。 。 。 .
    -   `unref` `<boolean>`数字 : [未读](https://nodejs.org/dist/latest-v18.x/docs/api/timers.html#timers_timeout_unref) 用于安排采样间隔的计时器. **默认 :** `true`。 。 。 .
    -   `gcOptions` `<Object>`: 垃圾收集选项
        -   `aggregate` `<boolean>`: 追踪和汇总每次垃圾收集作业的统计数据(见 [https://nodejs.org/docs/latest-v18.x/api/perf hooks.html#perf hooks 性能进取 kind](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performanceentry_kind)) (中文(简体) ). **默认 :** `false`
        -   `flags` `<boolean>`:,关于每个(汇总)垃圾收集作业的旗帜的轨迹统计(见 [https://nodejs.org/docs/latest-v18.x/api/perf hooks.html#perf hooks 性能进取 flags](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performanceentry_flags)) (中文(简体) ). `aggregate` 必须是 `true` 以启用此选项. **默认 :** `true` 节点版本 `12.17.0` 更新鲜.
    -   `eventLoopDelayOptions` `<Object>`设置选项 [`monitorEventLoopDelay`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options)。 。 。 . **默认 :** `{ resolution: 10 }`
    -   `collect` `<Object>`: 启用/禁用特定指标的收集.
        -   `cpu` `<boolean>`: 启用 cpu 度量衡. **默认 :** `true`。 。 。 .
        -   `resourceUsage` `<boolean>`: 启用 [资源用户](https://nodejs.org/docs/latest-v18.x/api/process.html#process_process_resourceusage) 标准. **默认 :** `false`。 。 。 .
        -   `eventLoopDelay` `<boolean>`: 启用事件LoopDelay 度量标准. **默认 :** `true`。 。 。 .
        -   `eventLoopUtilization` `<boolean>`: 启用 [事件循环](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) 标准. **默认 :** `true` 节点版本 `12.19.0` 更新鲜.
        -   `memory` `<boolean>`: 启用内存度量衡. **默认 :** `true`。 。 。 .
        -   `gc` `<boolean>`:启用垃圾收集度量标准. **默认 :** `false`。 。 。 .
        -   `activeHandles` `<boolean>`: 启用活动手柄收集度量. **默认 :** `false`。 。 。 .

若为 `options.collect.resourceUsage` 设置为 `true`, (中文(简体) ), `options.collect.cpu` 将会被设定为错误,因为 cpu 度量在 [`resource usage metric`](https://npmcn.com/package/%40dnlup/doc/#readme-samplerresourceusage)。 。 。 .

#### 活动: '`sample`'

每一次发件 `sampleInterval`,它表示采样者收集了新的数据.

#### `sampler.start()`

开始收集度量衡.

#### `sampler.stop()`

停止收集度量衡.

#### `sampler.cpu`

-   [`<CpuMetric>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-cpumetric)

资源使用情况.

#### `sampler.resourceUsage`

-   [`<ResourceUsageMetric>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-resourceusagemetric)

资源使用情况.

#### `sampler.eventLoopDelay`

-   [`<EventLoopDelayMetric>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-eventloopdelaymetric)

事件循环延后度量实例 .

#### `sampler.eventLoopUtilization`

-   [`<EventLoopUtilizationMetric>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-eventlooputilizationmetric)

事件循环利用度例.

#### `sampler.gc`

-   [`<GCMetric>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcmetric)

垃圾收集器的例子.

#### `sampler.activeHandles`

-   `<number>`

返回的有效手柄数量 `process._getActiveHandles()`。 。 。 .

#### `sampler.memory`

-   `<object>`

对象返回 [`process.memoryUsage()`](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process_process_memoryusage)。 。 。 .

### 类 : `CpuMetric`

它暴露了cpu用法的计算值和原始值.

#### `cpuMetric.usage`

-   `<number>`

使用率(百分比).

#### `cpuMetric.raw`

-   `<object>`

返回的原始值 [`process.cpuUsage()`](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process_process_cpuusage_previousvalue)。 。 。 .

### 类 : `ResourceUsageMetric`

它揭示了流程资源使用情况的计算值和原始值.

#### `resourceUsage.cpu`

-   `<number>`

使用率(百分比).

#### `resourceUsage.raw`

-   `<object>`

返回的原始值 [`process.resourceUsage()`](https://nodejs.org/docs/latest-v18.x/api/process.html#process_process_resourceusage)。 。 。 .

### 类 : `EventLoopDelayMetric`

它揭示了事件循环延迟的计算值和原始值.

#### `eventLoopDelay.computed`

-   `<number>`

事件循环延迟以毫秒计 。 它使用 `mean` 会 议 日 程 和 议 程 [`Histogram`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) 举个例子.

#### `eventLoopDelay.raw`

-   `<Histogram>`

显示 [`Histogram`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) 举个例子.

#### `eventLoopDelay.compute(raw)`

-   `raw` `<number>` 使用 [`Histogram`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) API (英语).
-   回返 `<number>` 计算出延迟值 .

### 类 : `EventLoopUtilizationMetric`

它揭露了关于事件循环利用的统计数据.

#### `eventLoopUtilization.idle`

-   `<number>`

这个 `idle` 返回对象中的值 [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) 期间 `sampleInterval` 窗口.

#### `eventLoopUtilization.active`

-   `<number>`

这个 `active` 返回对象中的值 [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) 期间 `sampleInterval` 窗口.

#### `eventLoopUtilization.utilization`

-   `<number>`

这个 `utilization` 返回对象中的值 [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) 期间 `sampleInterval` 窗口.

#### `eventLoopUtilization.raw`

-   `<object>`

返回的原始值 [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) 期间 `sampleInterval` 窗口.

### 类 : `GCMetric`

它揭示了垃圾收集器活动统计数据 `sampleInterval` 使用hdr直方图.

#### `new GCMetric(options)`

-   `options` `<object>`配置选项
    -   `aggregate` `<boolean>`: 见 `gcOptions.aggregate` 输入 [样本选项](https://npmcn.com/package/%40dnlup/doc/#readme-new-docsampleroptions)。 。 。 .
    -   `flags` `<boolean>`: 见 `gcOptions.flags` 输入 [样本选项](https://npmcn.com/package/%40dnlup/doc/#readme-new-docsampleroptions)。 。 。 .

### `gcMetric.pause`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

它跟踪垃圾收集器的全球活动.

#### `gcMetric.major`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry) | [`<GCAggregatedEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcaggregatedentry)

类型操作的活动 `major`。它只有在 `GCMetric` 已使用选项创建 `aggregate` 等于 `true`。 。 。 .

见 [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind)。 。 。 .

#### `gcMetric.minor`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry) | [`<GCAggregatedEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcaggregatedentry)

类型操作的活动 `minor`。它只有在 `GCMetric` 已使用选项创建 `aggregate` 等于 `true`。 。 。 .

见 [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind)。 。 。 .

#### `gcMetric.incremental`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry) | [`<GCAggregatedEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcaggregatedentry)

类型操作的活动 `incremental`。它只有在 `GCMetric` 已使用选项创建 `aggregate` 等于 `true`。 。 。 .

见 [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind)。 。 。 .

#### `gcMetric.weakCb`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry) | [`<GCAggregatedEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcaggregatedentry)

类型操作的活动 `weakCb`。它只有在 `GCMetric` 已使用选项创建 `aggregate` 等于 `true`。 。 。 .

见 [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind)。 。 。 .

### 类 : `GCEntry`

它包含垃圾收集数据,以 [直方图](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#class-recordablehistogram-extends-histogram)。所有计时值以纳秒表示.

#### `new GCEntry()`

初始化不需要选项. 它由内部生成 [`GCMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcmetric)。 。 。 .

#### `gcEntry.totalDuration`

-   `<number>`

它是以纳秒计的输入总时间.

#### `gcEntry.totalCount`

-   `<number>`

这是计算的行动总数.

#### `gcEntry.mean`

-   `<number>`

它是以纳秒计的条目的平均值.

#### `gcEntry.max`

-   `<number>`

它是该条目以纳秒计的最大值.

#### `gcEntry.min`

-   `<number>`

它是该条目以纳秒计的最小值.

#### `gcEntry.stdDeviation`

-   `<number>`

它是以纳秒计的条目的标准偏差.

#### `gcEntry.getPercentile(percentile)`

-   `percentile` `<number>`: 从直方图中取一个百分点.
-   回返 `<number>` 百分位数

### 类 : `GCAggregatedEntry`

它延伸 [`GCEntry`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry) 并包含垃圾收集数据加上与之相关的旗帜(参见 [https://nodejs.org/dist/latest-v18.x/docs/api/perf hooks.html#性能登场活佛旗](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#performanceentryflags)) (中文(简体) ).

#### `new GCAggregatedEntry()`

初始化不需要选项. 它由内部生成 [`GCMetric`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcmetric)。 。 。 .

#### `gcAggregatedEntry.flags`

-   `<object>`

此天体包含每个旗帜的各种直方图.

#### `gcAggregatedEntry.flags.no`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

#### `gcAggregatedEntry.flags.constructRetained`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

#### `gcAggregatedEntry.flags.forced`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

#### `gcAggregatedEntry.flags.synchronousPhantomProcessing`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

#### `gcAggregatedEntry.flags.allAvailableGarbage`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

#### `gcAggregatedEntry.flags.allExternalMemory`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

#### `gcAggregatedEntry.flags.scheduleIdle`

-   [`<GCEntry>`](https://npmcn.com/package/%40dnlup/doc/#readme-class-gcentry)

### `doc.errors`

在那个 `errors` 对象导出模块使用的所有自定义错误.

| 错误 | 错误代码 | 说明 |
| --- | --- | --- |
| `InvalidArgumentError` | `DOC_ERR_INVALID_ARG` | 使用了无效的选项或参数 |
| `NotSupportedError` | `DOC_ERR_NOT_SUPPORTED` | 在所使用的节点.js版本上不支持一个参数 |

### 诊断通道支持

节点 [诊断通道](https://nodejs.org/dist/latest-v20.x/docs/api/diagnostics_channel.html) 被支持.

```js
const diagnosticsChannel = require('diagnostics_channel')
const doc = require('@dnlup/doc)

diagnosticsChannel.subscribe(doc.constants.DOC_CHANNEL, s => {
  console.log('A new instance', s)
})

diagnosticsChannel.subscribe(doc.constants.DOC_SAMPLES_CHANNEL, s => {
  console.log('A new sample', s)
})

doc()
```

## 许可证

[公务员制度委员会](https://npmcn.com/package/%40dnlup/doc/LICENSE)

## 常见问题

### @dnlup/doc 是什么？

获取关于您节点js进程的使用和健康数据

### 如何安装 @dnlup/doc？

在项目目录运行 npm install @dnlup/doc，或使用 pnpm add / yarn add / bun add。

### @dnlup/doc 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @dnlup/doc 支持 ESM 还是 CommonJS？

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

### @dnlup/doc 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @dnlup/doc 可以商用吗？

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

### @dnlup/doc 的下载量有多少？

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

### @dnlup/doc 还在维护吗？

最新版本 5\.0\.4 发布于 2025/02/18（1\.7 年前）；至今共发布 28 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/03/31。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

