@dnlup/doc
Advanced tools
Comparing version 4.0.1 to 5.0.0
@@ -1,17 +0,35 @@ | ||
import { Sampler, SamplerOptions } from './types/sampler' | ||
import errors = require('./types/errors') | ||
import { | ||
Sampler, | ||
SamplerOptions, | ||
InstancesDiagnosticChannelHookData, | ||
SamplesDiagnosticChannelHookData | ||
} from './types/sampler' | ||
import errors from './types/errors' | ||
import { CPUMetric } from './types/cpuMetric' | ||
import { EventLoopDelayMetric } from './types/eventLoopDelayMetric' | ||
import { ResourceUsageMetric } from './types/resourceUsageMetric' | ||
import { EventLoopUtilizationMetric } from './types/eventLoopUtilizationMetric' | ||
import { GCEntry, GCAggregatedEntry, GCMetric } from './types/gcMetric' | ||
import * as constants from './types/constants' | ||
declare function createSampler(options?: SamplerOptions): Sampler | ||
export default createSampler | ||
export { createSampler } | ||
export const eventLoopUtilizationSupported: Boolean | ||
export const resourceUsageSupported: Boolean | ||
export const gcFlagsSupported: Boolean | ||
export { Sampler, SamplerOptions } | ||
export { errors } | ||
export * from './types/cpuMetric' | ||
export * from './types/eventLoopDelayMetric' | ||
export * from './types/resourceUsageMetric' | ||
export * from './types/eventLoopUtilizationMetric' | ||
export * from './types/gcMetric' | ||
declare namespace doc { | ||
export { errors } | ||
export type { | ||
Sampler, | ||
SamplerOptions, | ||
InstancesDiagnosticChannelHookData, | ||
SamplesDiagnosticChannelHookData, | ||
CPUMetric, | ||
EventLoopDelayMetric, | ||
ResourceUsageMetric, | ||
EventLoopUtilizationMetric, | ||
GCEntry, | ||
GCAggregatedEntry, | ||
GCMetric, | ||
constants | ||
} | ||
export const createSampler: (options?: SamplerOptions) => Sampler | ||
export { createSampler as default } | ||
} | ||
declare function doc(options?: doc.SamplerOptions): doc.Sampler | ||
export = doc |
21
index.js
'use strict' | ||
const Sampler = require('./lib/sampler') | ||
const util = require('./lib/util') | ||
const errors = require('./lib/errors') | ||
const constants = require('./lib/constants') | ||
@@ -17,19 +17,2 @@ function createSampler (options = {}) { | ||
module.exports.errors = errors | ||
Object.defineProperty(module.exports, 'eventLoopUtilizationSupported', { | ||
value: util.eventLoopUtilizationSupported, | ||
writable: false, | ||
enumerable: true | ||
}) | ||
Object.defineProperty(module.exports, 'resourceUsageSupported', { | ||
value: util.resourceUsageSupported, | ||
writable: false, | ||
enumerable: true | ||
}) | ||
Object.defineProperty(module.exports, 'gcFlagsSupported', { | ||
value: util.gcFlagsSupported, | ||
writable: false, | ||
enumerable: true | ||
}) | ||
module.exports.constants = constants |
'use strict' | ||
const debug = require('./debug') | ||
const { | ||
monitorEventLoopDelaySupported, | ||
eventLoopUtilizationSupported, | ||
resourceUsageSupported, | ||
gcFlagsSupported | ||
} = require('./util') | ||
const { InvalidArgumentError, NotSupportedError } = require('./errors') | ||
const { InvalidArgumentError } = require('./errors') | ||
// This object serves as both a default config and config schema. | ||
const DEFAULTS = { | ||
sampleInterval: monitorEventLoopDelaySupported ? 1000 : 500, | ||
sampleInterval: 1000, | ||
autoStart: true, | ||
@@ -22,3 +16,3 @@ unref: true, | ||
aggregate: false, | ||
flags: gcFlagsSupported | ||
flags: true | ||
}, | ||
@@ -30,3 +24,3 @@ collect: { | ||
eventLoopDelay: true, | ||
eventLoopUtilization: eventLoopUtilizationSupported, | ||
eventLoopUtilization: true, | ||
gc: false, | ||
@@ -86,14 +80,2 @@ activeHandles: false | ||
if (conf.gcOptions.flags && !gcFlagsSupported) { | ||
throw new NotSupportedError('GC flags are not supported on the Node.js version used') | ||
} | ||
if (conf.collect.eventLoopUtilization && !eventLoopUtilizationSupported) { | ||
throw new NotSupportedError('eventLoopUtilization is not supported on the Node.js version used') | ||
} | ||
if (conf.collect.resourceUsage && !resourceUsageSupported) { | ||
throw new NotSupportedError('resourceUsage is not supported on the Node.js version used') | ||
} | ||
if (conf.collect.cpu && conf.collect.resourceUsage) { | ||
@@ -100,0 +82,0 @@ conf.collect.cpu = false |
@@ -12,14 +12,4 @@ 'use strict' | ||
class NotSupportedError extends Error { | ||
constructor (message) { | ||
super(message) | ||
Error.captureStackTrace(this, NotSupportedError) | ||
this.name = 'NotSupportedError' | ||
this.code = 'DOC_ERR_NOT_SUPPORTED' | ||
} | ||
} | ||
module.exports = { | ||
InvalidArgumentError, | ||
NotSupportedError | ||
InvalidArgumentError | ||
} |
@@ -20,8 +20,4 @@ 'use strict' | ||
this[kOptions] = Object.assign({}, DEFAULTS, opts) | ||
if (monitorEventLoopDelay) { | ||
this[kRawMetric] = monitorEventLoopDelay(this[kOptions]) | ||
this[kRawMetric].enable() | ||
} else { | ||
this[kRawMetric] = 0 | ||
} | ||
this[kRawMetric] = monitorEventLoopDelay(this[kOptions]) | ||
this[kRawMetric].enable() | ||
} | ||
@@ -46,8 +42,3 @@ | ||
[kSample] (elapsedNs, sampleInterval) { | ||
if (monitorEventLoopDelay) { | ||
this[kComputedMetric] = this.compute(this[kRawMetric].mean) | ||
} else { | ||
this[kRawMetric] = elapsedNs - sampleInterval * 1e6 | ||
this[kComputedMetric] = Math.max(0, this[kRawMetric] / 1e6) | ||
} | ||
this[kComputedMetric] = this.compute(this[kRawMetric].mean) | ||
} | ||
@@ -54,0 +45,0 @@ |
@@ -13,5 +13,2 @@ 'use strict' | ||
constructor () { | ||
if (!eventLoopUtilization) { | ||
throw new Error('eventLoopUtilization is not supported on this Node.js version') | ||
} | ||
this[kLastSample] = eventLoopUtilization() | ||
@@ -18,0 +15,0 @@ this[kRawMetric] = this[kLastSample] |
'use strict' | ||
const { PerformanceObserver, constants } = require('perf_hooks') | ||
const { PerformanceObserver, constants, createHistogram } = require('perf_hooks') | ||
const { | ||
@@ -17,3 +17,2 @@ NODE_PERFORMANCE_GC_MAJOR, | ||
} = constants | ||
const hdr = require('hdr-histogram-js') | ||
const { | ||
@@ -27,4 +26,2 @@ kSample, | ||
hdr.initWebAssemblySync() | ||
const kHistogram = Symbol('kHistogram') | ||
@@ -35,6 +32,4 @@ const kTotalDuration = Symbol('kTotalDuration') | ||
constructor () { | ||
this[kHistogram] = hdr.build({ | ||
useWebAssembly: true, | ||
lowestDiscernibleValue: 1, | ||
highestTrackableValue: 1e10 | ||
this[kHistogram] = createHistogram({ | ||
lowestDiscernibleValue: 1 | ||
}) | ||
@@ -49,29 +44,23 @@ this[kTotalDuration] = 0 | ||
get totalCount () { | ||
return this[kHistogram].totalCount | ||
return this[kHistogram].count | ||
} | ||
get mean () { | ||
return this[kHistogram].mean | ||
return isNaN(this[kHistogram].mean) ? 0 : this[kHistogram].mean | ||
} | ||
get max () { | ||
return this[kHistogram].maxValue | ||
return this[kHistogram].max | ||
} | ||
// It seems this is not well supprted in hdr-histogram | ||
// See https://github.com/HdrHistogram/HdrHistogramJS/issues/11 | ||
get min () { | ||
return this[kHistogram].minNonZeroValue | ||
return this[kHistogram].min | ||
} | ||
get stdDeviation () { | ||
return this[kHistogram].stdDeviation | ||
return isNaN(this[kHistogram].stddev) ? 0 : this[kHistogram].stddev | ||
} | ||
get summary () { | ||
return this[kHistogram].summary | ||
} | ||
getPercentile (percentile) { | ||
return this[kHistogram].getValueAtPercentile(percentile) | ||
return this[kHistogram].percentile(percentile) | ||
} | ||
@@ -81,3 +70,8 @@ | ||
this[kTotalDuration] += ns | ||
this[kHistogram].recordValue(ns) | ||
/** | ||
* We have to truncate the value here because `record` | ||
* only accepts integer values: | ||
* https://github.com/nodejs/node/blob/cdad3d8fe5f468aec6549fd59db73a3bfe063e3c/lib/internal/histogram.js#L283-L284 | ||
*/ | ||
this[kHistogram].record(Math.trunc(ns)) | ||
} | ||
@@ -136,3 +130,3 @@ | ||
super[kSample](ns) | ||
const flag = gcEntry.flags | ||
const flag = gcEntry.detail.flags | ||
const entry = this[kFlags].get(flag) | ||
@@ -213,3 +207,3 @@ | ||
} | ||
const entry = this[kGCEntries].get(gcEntry.kind) | ||
const entry = this[kGCEntries].get(gcEntry.detail.kind) | ||
/* istanbul ignore next */ | ||
@@ -216,0 +210,0 @@ if (!entry) { |
@@ -9,3 +9,2 @@ 'use strict' | ||
} = require('./symbols') | ||
const { resourceUsageSupported } = require('./util') | ||
@@ -16,5 +15,2 @@ const kLastSample = Symbol('kLastSample') | ||
constructor () { | ||
if (!resourceUsageSupported) { | ||
throw new Error('resourceUsage is not supported on this Node.js version') | ||
} | ||
this[kLastSample] = process.resourceUsage() | ||
@@ -21,0 +17,0 @@ this[kRawMetric] = this[kLastSample] |
'use strict' | ||
const EventEmitter = require('events') | ||
const diagnosticsChannel = require('diagnostics_channel') | ||
const EventLoopDelayMetric = require('./eventLoopDelay') | ||
@@ -29,3 +30,7 @@ const EventLoopUtilizationMetric = require('./eventLoopUtilization') | ||
} = require('./symbols') | ||
const { DOC_CHANNEL, DOC_SAMPLES_CHANNEL } = require('./constants') | ||
const samples = diagnosticsChannel.channel(DOC_SAMPLES_CHANNEL) | ||
const instances = diagnosticsChannel.channel(DOC_CHANNEL) | ||
class Sampler extends EventEmitter { | ||
@@ -61,2 +66,5 @@ constructor (options) { | ||
} | ||
if (instances.hasSubscribers) { | ||
process.nextTick(() => instances.publish(this)) | ||
} | ||
} | ||
@@ -117,2 +125,5 @@ | ||
this[kReset]() | ||
if (samples.hasSubscribers) { | ||
samples.publish(this) | ||
} | ||
} | ||
@@ -119,0 +130,0 @@ |
{ | ||
"name": "@dnlup/doc", | ||
"version": "4.0.1", | ||
"version": "5.0.0", | ||
"description": "Get usage and health data about your Node.js process", | ||
@@ -9,5 +9,3 @@ "main": "index.js", | ||
"scripts": { | ||
"lint": "npm run lint:js && npm run lint:ts", | ||
"lint:js": "eslint .", | ||
"lint:ts": "eslint *.ts", | ||
"lint": "eslint .", | ||
"test": "npm run test:js && npm run test:ts && npm run test:esm", | ||
@@ -17,3 +15,3 @@ "pretest:ci": "npm run lint", | ||
"test:js": "tap -J test/*.test.js", | ||
"test:ts": "tsd", | ||
"test:ts": "attw --pack && tsd", | ||
"test:esm": "tap --no-coverage test/esm/*.test.js", | ||
@@ -35,3 +33,4 @@ "trace:ic:server": "PORT=3000 deoptigate benchmarks/doc.js", | ||
"postnext": "npm run push && npm publish --tag next", | ||
"push": "git push origin --follow-tags `git rev-parse --abbrev-ref HEAD`" | ||
"push": "git push origin --follow-tags `git rev-parse --abbrev-ref HEAD`", | ||
"prepare": "husky install" | ||
}, | ||
@@ -58,3 +57,3 @@ "repository": { | ||
], | ||
"author": "Daniele Belardi <dwon.dnl@gmail.com>", | ||
"author": "dnlup <dnlup.dev@gmail.com>", | ||
"license": "ISC", | ||
@@ -69,4 +68,4 @@ "publishConfig": { | ||
"engines": { | ||
"node": ">=10", | ||
"npm": ">=6" | ||
"node": ">=18", | ||
"npm": ">=10" | ||
}, | ||
@@ -77,28 +76,28 @@ "tsd": { | ||
"devDependencies": { | ||
"@types/node": "^10.17.40", | ||
"@typescript-eslint/eslint-plugin": "^4.2.0", | ||
"@typescript-eslint/parser": "^4.2.0", | ||
"@arethetypeswrong/cli": "^0.10.2", | ||
"@types/node": "^20.6.3", | ||
"atomic-sleep": "^1.0.0", | ||
"autocannon": "^7.0.0", | ||
"concurrently": "^6.0.0", | ||
"deoptigate": "^0.5.0", | ||
"eslint": "^7.9.0", | ||
"eslint-config-standard": "^16.0.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"autocannon": "^7.12.0", | ||
"concurrently": "^8.2.1", | ||
"deoptigate": "^0.7.1", | ||
"eslint": "^8.49.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-n": "^16.1.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"husky": "^5.1.3", | ||
"is-ci": "^3.0.0", | ||
"lint-staged": "^10.5.3", | ||
"husky": "^8.0.3", | ||
"is-ci": "^3.0.1", | ||
"lint-staged": "^14.0.1", | ||
"markdown-toc": "^1.2.0", | ||
"semver": "^7.3.4", | ||
"standard-version": "^9.0.0", | ||
"tap": "^14.10.8", | ||
"tsd": "^0.14.0" | ||
"semver": "^7.5.4", | ||
"standard-version": "^9.5.0", | ||
"tap": "^16.3.8", | ||
"tsd": "^0.29.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"@dnlup/hrtime-utils": "^1.0.0", | ||
"hdr-histogram-js": "^2.0.1" | ||
"@dnlup/hrtime-utils": "^1.1.0" | ||
} | ||
} |
105
README.md
@@ -73,3 +73,2 @@ # doc | ||
+ [`gcEntry.stdDeviation`](#gcentrystddeviation) | ||
+ [`gcEntry.summary`](#gcentrysummary) | ||
+ [`gcEntry.getPercentile(percentile)`](#gcentrygetpercentilepercentile) | ||
@@ -86,6 +85,4 @@ * [Class: `GCAggregatedEntry`](#class-gcaggregatedentry) | ||
+ [`gcAggregatedEntry.flags.scheduleIdle`](#gcaggregatedentryflagsscheduleidle) | ||
* [`doc.eventLoopUtilizationSupported`](#doceventlooputilizationsupported) | ||
* [`doc.resourceUsageSupported`](#docresourceusagesupported) | ||
* [`doc.gcFlagsSupported`](#docgcflagssupported) | ||
* [`doc.errors`](#docerrors) | ||
* [Diagnostics Channel support](#diagnostics-channel-support) | ||
- [License](#license) | ||
@@ -113,3 +110,3 @@ | ||
By default `doc` returns a [`Sampler`](#class-docsampler) instance that collects metrics about cpu, memory usage, event loop delay and event loop utilization (only on Node versions that [support it](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2)). | ||
By default `doc` returns a [`Sampler`](#class-docsampler) instance that collects metrics about cpu, memory usage, event loop delay and event loop utilization. | ||
@@ -217,3 +214,3 @@ ###### Importing with CommonJS | ||
* Extends [`EventEmitter`](https://nodejs.org/dist/latest-v12.x/docs/api/events.html#events_class_eventemitter). | ||
* Extends [`EventEmitter`](https://nodejs.org/dist/latest-v18.x/docs/api/events.html#events_class_eventemitter). | ||
@@ -228,14 +225,14 @@ Metrics sampler. | ||
* `options` `<Object>` | ||
* `sampleInterval` `<number>`: sample interval (ms) to get a sample. On each `sampleInterval` ms a [`sample`](#event-sample) event is emitted. **Default:** `500` on Node < 11.10.0, `1000` otherwise. Under the hood the package uses [`monitorEventLoopDelay`](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options) when available to track the event loop delay and this allows to increase the default `sampleInterval`. | ||
* `sampleInterval` `<number>`: sample interval (ms) to get a sample. On each `sampleInterval` ms a [`sample`](#event-sample) event is emitted. **Default:** `1000` Under the hood the package uses [`monitorEventLoopDelay`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options) to track the event loop delay. | ||
* `autoStart` `<boolean>`: start automatically to collect metrics. **Default:** `true`. | ||
* `unref` `<boolean>`: [unref](https://nodejs.org/dist/latest-v12.x/docs/api/timers.html#timers_timeout_unref) the timer used to schedule the sampling interval. **Default:** `true`. | ||
* `unref` `<boolean>`: [unref](https://nodejs.org/dist/latest-v18.x/docs/api/timers.html#timers_timeout_unref) the timer used to schedule the sampling interval. **Default:** `true`. | ||
* `gcOptions` `<Object>`: Garbage collection options | ||
* `aggregate` `<boolean>`: Track and aggregate statistics about each garbage collection operation (see https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performanceentry_kind). **Default:** `false` | ||
* `flags` `<boolean>`: , Track statistics about the flags of each (aggregated) garbage collection operation (see https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performanceentry_flags). `aggregate` has to be `true` to enable this option. **Default:** `true` on Node version `12.17.0` and newer. | ||
* `eventLoopDelayOptions` `<Object>`: Options to setup [`monitorEventLoopDelay`](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options). **Default:** `{ resolution: 10 }` | ||
* `aggregate` `<boolean>`: Track and aggregate statistics about each garbage collection operation (see https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performanceentry_kind). **Default:** `false` | ||
* `flags` `<boolean>`: , Track statistics about the flags of each (aggregated) garbage collection operation (see https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performanceentry_flags). `aggregate` has to be `true` to enable this option. **Default:** `true` on Node version `12.17.0` and newer. | ||
* `eventLoopDelayOptions` `<Object>`: Options to setup [`monitorEventLoopDelay`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options). **Default:** `{ resolution: 10 }` | ||
* `collect` `<Object>`: enable/disable the collection of specific metrics. | ||
* `cpu` `<boolean>`: enable cpu metric. **Default:** `true`. | ||
* `resourceUsage` `<boolean>`: enable [resourceUsage](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_resourceusage) metric. **Default:** `false`. | ||
* `resourceUsage` `<boolean>`: enable [resourceUsage](https://nodejs.org/docs/latest-v18.x/api/process.html#process_process_resourceusage) metric. **Default:** `false`. | ||
* `eventLoopDelay` `<boolean>`: enable eventLoopDelay metric. **Default:** `true`. | ||
* `eventLoopUtilization` `<boolean>`: enable [eventLoopUtilization](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) metric. **Default:** `true` on Node version `12.19.0` and newer. | ||
* `eventLoopUtilization` `<boolean>`: enable [eventLoopUtilization](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) metric. **Default:** `true` on Node version `12.19.0` and newer. | ||
* `memory` `<boolean>`: enable memory metric. **Default:** `true`. | ||
@@ -299,3 +296,3 @@ * `gc` `<boolean>`: enable garbage collection metric. **Default:** `false`. | ||
Object returned by [`process.memoryUsage()`](https://nodejs.org/dist/latest-v12.x/docs/api/process.html#process_process_memoryusage). | ||
Object returned by [`process.memoryUsage()`](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process_process_memoryusage). | ||
@@ -316,3 +313,3 @@ ### Class: `CpuMetric` | ||
Raw value returned by [`process.cpuUsage()`](https://nodejs.org/dist/latest-v12.x/docs/api/process.html#process_process_cpuusage_previousvalue). | ||
Raw value returned by [`process.cpuUsage()`](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process_process_cpuusage_previousvalue). | ||
@@ -333,3 +330,3 @@ ### Class: `ResourceUsageMetric` | ||
Raw value returned by [`process.resourceUsage()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_resourceusage). | ||
Raw value returned by [`process.resourceUsage()`](https://nodejs.org/docs/latest-v18.x/api/process.html#process_process_resourceusage). | ||
@@ -344,17 +341,15 @@ ### Class: `EventLoopDelayMetric` | ||
Event loop delay in milliseconds. On Node versions that support [`monitorEventLoopDelay`](https://nodejs.org/dist/latest-v13.x/docs/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options), it computes this value using the `mean` of the [`Histogram`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) instance. Otherwise, it uses a simple timer to calculate it. | ||
Event loop delay in milliseconds. It computes this value using the `mean` of the [`Histogram`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) instance. | ||
#### `eventLoopDelay.raw` | ||
* `<Histogram>` | `<number>` | ||
* `<Histogram>` | ||
On Node versions that support [`monitorEventLoopDelay`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options) this exposes the [`Histogram`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) instance. Otherwise, it exposes the raw delay value in nanoseconds. | ||
Exposes the [`Histogram`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) instance. | ||
#### `eventLoopDelay.compute(raw)` | ||
* `raw` `<number>` The raw value obtained using the [`Histogram`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) API. | ||
* `raw` `<number>` The raw value obtained using the [`Histogram`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) API. | ||
* Returns `<number>` The computed delay value. | ||
This function works only on node versions that support [`monitorEventLoopDelay`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_perf_hooks_monitoreventloopdelay_options). It allows to get computed values of the event loop delay from statistics other than the `mean` of the [`Histogram`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_class_histogram) instance. | ||
### Class: `EventLoopUtilizationMetric` | ||
@@ -368,3 +363,3 @@ | ||
The `idle` value in the object returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
The `idle` value in the object returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
@@ -375,3 +370,3 @@ #### `eventLoopUtilization.active` | ||
The `active` value in the object returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
The `active` value in the object returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
#### `eventLoopUtilization.utilization` | ||
@@ -381,3 +376,3 @@ | ||
The `utilization` value in the object returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
The `utilization` value in the object returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
@@ -388,3 +383,3 @@ #### `eventLoopUtilization.raw` | ||
Raw value returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
Raw value returned by [`performance.eventLoopUtilization()`](https://nodejs.org/docs/latest-v18.x/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) during the `sampleInterval` window. | ||
@@ -413,3 +408,3 @@ ### Class: `GCMetric` | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
@@ -422,3 +417,3 @@ #### `gcMetric.minor` | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
@@ -431,3 +426,3 @@ #### `gcMetric.incremental` | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
@@ -440,7 +435,7 @@ #### `gcMetric.weakCb` | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
See [`performanceEntry.kind`](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_kind). | ||
### Class: `GCEntry` | ||
It contains garbage collection data, represented with an [hdr histogram](https://github.com/HdrHistogram/HdrHistogramJS). All timing values are expressed in nanoseconds. | ||
It contains garbage collection data, represented with an [histogram](https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#class-recordablehistogram-extends-histogram). All timing values are expressed in nanoseconds. | ||
@@ -485,8 +480,2 @@ #### `new GCEntry()` | ||
#### `gcEntry.summary` | ||
* `<object>` | ||
The hdr histogram summary. See https://github.com/HdrHistogram/HdrHistogramJS#record-values-and-retrieve-metrics. | ||
#### `gcEntry.getPercentile(percentile)` | ||
@@ -497,7 +486,5 @@ | ||
See https://github.com/HdrHistogram/HdrHistogramJS#record-values-and-retrieve-metrics. | ||
### Class: `GCAggregatedEntry` | ||
It extends [`GCEntry`](#class-gcentry) and contains garbage collection data plus the flags associated with it (see https://nodejs.org/docs/latest-v12.x/api/perf_hooks.html#perf_hooks_performanceentry_flags). | ||
It extends [`GCEntry`](#class-gcentry) and contains garbage collection data plus the flags associated with it (see https://nodejs.org/dist/latest-v18.x/docs/api/perf_hooks.html#performanceentryflags). | ||
@@ -512,3 +499,3 @@ #### `new GCAggregatedEntry()` | ||
This object contains the various hdr histograms of each flag. | ||
This object contains the various histograms of each flag. | ||
#### `gcAggregatedEntry.flags.no` | ||
@@ -546,31 +533,33 @@ | ||
### `doc.eventLoopUtilizationSupported` | ||
* `<boolean>` | ||
### `doc.errors` | ||
It tells if the Node.js version in use supports the [eventLoopUtilization metric](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2). | ||
In the `errors` object are exported all the custom errors used by the module. | ||
### `doc.resourceUsageSupported` | ||
| Error | Error Code | Description | | ||
|-------|------------|-------------| | ||
| `InvalidArgumentError` | `DOC_ERR_INVALID_ARG` | An invalid option or argument was used | | ||
| `NotSupportedError` | `DOC_ERR_NOT_SUPPORTED` | A metric is not supported on the Node.js version used | | ||
* `<boolean>` | ||
### Diagnostics Channel support | ||
It tells if the Node.js version in use supports the [resourceUsage metric](https://nodejs.org/dist/latest-v12.x/docs/api/process.html#process_process_resourceusage). | ||
Node [diagnostics channel](https://nodejs.org/dist/latest-v20.x/docs/api/diagnostics_channel.html) are supported. | ||
### `doc.gcFlagsSupported` | ||
```js | ||
const diagnosticsChannel = require('diagnostics_channel') | ||
const doc = require('@dnlup/doc) | ||
* `<boolean>` | ||
diagnosticsChannel.subscribe(doc.constants.DOC_CHANNEL, s => { | ||
console.log('A new instance', s) | ||
}) | ||
It tells if the Node.js version in use supports [GC flags](https://nodejs.org/dist/latest-v12.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_flags). | ||
diagnosticsChannel.subscribe(doc.constants.DOC_SAMPLES_CHANNEL, s => { | ||
console.log('A new sample', s) | ||
}) | ||
### `doc.errors` | ||
doc() | ||
``` | ||
In the `errors` object are exported all the custom errors used by the module. | ||
| Error | Error Code | Description | | ||
|-------|------------|-------------| | ||
| `InvalidArgumentError` | `DOC_ERR_INVALID_ARG` | An invalid option or argument was used | | ||
| `NotSupportedError` | `DOC_ERR_NOT_SUPPORTED` | A metric is not supported on the Node.js version used | | ||
## License | ||
[ISC](./LICENSE) |
@@ -7,10 +7,4 @@ declare namespace Errors { | ||
} | ||
/** A metric is not supported */ | ||
export class NotSupportedError extends Error { | ||
name: 'NotSupportedError' | ||
code: 'DOC_ERR_NOT_SUPPORTED' | ||
} | ||
} | ||
export = Errors |
@@ -1,12 +0,2 @@ | ||
/** | ||
* On Node 12 and above this is a Histogram instance from 'perf_hooks'. | ||
*/ | ||
declare interface EventLoopDelayHistogram { | ||
min: number, | ||
max: number, | ||
mean: number, | ||
stddev: number, | ||
percentiles: Map<number, number>, | ||
exceeds: number, | ||
} | ||
import { IntervalHistogram } from "perf_hooks"; | ||
@@ -18,3 +8,3 @@ export interface EventLoopDelayMetric { | ||
computed: number, | ||
raw: number | EventLoopDelayHistogram | ||
raw: IntervalHistogram | ||
} |
@@ -0,1 +1,3 @@ | ||
import { EventLoopUtilization } from "perf_hooks" | ||
export interface EventLoopUtilizationMetric { | ||
@@ -5,7 +7,3 @@ /** | ||
*/ | ||
raw: { | ||
idle: number, | ||
active: number, | ||
utilization: number | ||
} | ||
raw: EventLoopUtilization | ||
} |
@@ -1,2 +0,2 @@ | ||
import { HistogramSummary, WasmHistogram } from 'hdr-histogram-js' | ||
import { RecordableHistogram } from 'perf_hooks'; | ||
@@ -28,27 +28,25 @@ declare enum GCFlag { | ||
*/ | ||
totalCount: WasmHistogram['totalCount']; | ||
// @types/node is not aligned with Node implementation. Let's wait for a fix. | ||
// @ts-ignore | ||
totalCount: RecordableHistogram['count']; | ||
/** | ||
* Mean value in nanoseconds | ||
*/ | ||
mean: WasmHistogram['mean']; | ||
mean: RecordableHistogram['mean']; | ||
/** | ||
* Max value in nanoseconds | ||
*/ | ||
max: WasmHistogram['maxValue']; | ||
max: RecordableHistogram['max']; | ||
/** | ||
* Min value in nanoseconds | ||
*/ | ||
min: WasmHistogram['minNonZeroValue']; | ||
min: RecordableHistogram['min']; | ||
/** | ||
* Standard deviation in nanoseconds | ||
*/ | ||
stdDeviation: WasmHistogram['stdDeviation']; | ||
stdDeviation: RecordableHistogram['stddev']; | ||
/** | ||
* Histogram summary | ||
*/ | ||
summary: HistogramSummary; | ||
/** | ||
* Get a percentile | ||
*/ | ||
getValueAtPercentile: WasmHistogram['getValueAtPercentile']; | ||
getValueAtPercentile: RecordableHistogram['percentile']; | ||
} | ||
@@ -55,0 +53,0 @@ |
@@ -0,1 +1,5 @@ | ||
import { resourceUsage } from "process"; | ||
type ResourceUsage = ReturnType<typeof resourceUsage> | ||
export interface ResourceUsageMetric { | ||
@@ -9,20 +13,3 @@ /** | ||
*/ | ||
raw: { | ||
fsRead: number; | ||
fsWrite: number; | ||
involuntaryContextSwitches: number; | ||
ipcReceived: number; | ||
ipcSent: number; | ||
majorPageFault: number; | ||
maxRSS: number; | ||
minorPageFault: number; | ||
sharedMemorySize: number; | ||
signalsCount: number; | ||
swappedOut: number; | ||
systemCPUTime: number; | ||
unsharedDataSize: number; | ||
unsharedStackSize: number; | ||
userCPUTime: number; | ||
voluntaryContextSwitches: number; | ||
} | ||
raw: ResourceUsage | ||
} |
@@ -10,7 +10,3 @@ import { EventEmitter } from 'events' | ||
/** | ||
* Sample interval (ms), each sampleInterval ms a data event is emitted. | ||
* On Node 10 the default value is 500 while on Node >= 12 is 1000. | ||
* Under the hood the package uses monitorEventLoopDelay where available to | ||
* sample the event loop and this allows to increase the default sample | ||
* interval on Node >= 12. | ||
* Sample interval (ms), each `sampleInterval` ms a data event is emitted. | ||
*/ | ||
@@ -60,1 +56,4 @@ sampleInterval?: number, | ||
} | ||
export type InstancesDiagnosticChannelHookData = Sampler | ||
export type SamplesDiagnosticChannelHookData = Sampler |
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
1
48702
22
863
545
- Removedhdr-histogram-js@^2.0.1
- Removed@assemblyscript/loader@0.10.1(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedhdr-histogram-js@2.0.3(transitive)
- Removedpako@1.0.11(transitive)
Updated@dnlup/hrtime-utils@^1.1.0