@contrast/perf

中文文档
1.5.0发布于 2026/10/23SEE LICENSE IN LICENSETypeScriptCommonJS近 30 天下载 1.5万

Performance measurement

原始使用文档
文档目录3 节
  1. Design goals
  2. Usage
  3. Log format

@contrast/perf

Performance measurement for developers working on the Contrast Node.js agent. It's meant for development and testing, though it is light enough to use when troubleshooting a performance issue in production.

Design goals

The primary design goal of the perf module is that it not introduce any cost when it is not in use. Practically, this is impossible in an interpreted language, so perf is designed to have no cost after startup when it is not in use. Perf does not introduce any cost after startup if it is not enabled.

A secondary design goal is that perf is efficient enough that, if desired, it could be used in production code in order to troubleshoot a performance issue. To this end, minimal aggregation and no analysis is performed at runtime. The perf log is very simple and can be analyzed offline.

Usage

Set the environment variable CSI_PERF to 1 to enable perf.

CSI_PERF_INTERVAL sets the timer interval in milliseconds (default 60000). Startup timings are written during the first few intervals, and the full set of timings is written every fifth interval after that (every 5 minutes by default). The timer doesn't keep the process alive, so a short run may exit before anything is logged. Lower the interval for short runs.

The log is written to agent-perf.jsonl in the current working directory.

Log format

The log is one JSON object per line (JSONL).

版本与发布记录

@contrast/perf 共发布 10 个版本,首次发布于 2024/09/26;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.5.0latest2026/10/2318 天前
1.4.22026/07/133 个月前
1.4.12026/04/017 个月前
1.4.02025/08/271.2 年前
1.3.12025/01/241.8 年前
1.3.02025/01/101.8 年前

关于 @contrast/perf 的常见问题

@contrast/perf 是什么?

Performance measurement

如何安装 @contrast/perf?

在项目目录运行 npm install @contrast/perf,或使用 pnpm add / yarn add / bun add。

@contrast/perf 支持 TypeScript 吗?

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

@contrast/perf 支持 ESM 还是 CommonJS?

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

@contrast/perf 需要什么版本的 Node.js?

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

@contrast/perf 可以商用吗?

@contrast/perf 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@contrast/perf 的下载量有多少?

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

@contrast/perf 还在维护吗?

最新版本 1.5.0 发布于 2026/10/23(18 天前);至今共发布 10 个版本,其中过去 12 个月发布了 3 个;首次发布于 2024/09/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。