Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dnlup/doc

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dnlup/doc - npm Package Compare versions

Comparing version 3.0.3 to 3.1.0

lib/util.js

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [3.1.0](https://github.com/dnlup/doc/compare/v3.0.3...v3.1.0) (2021-01-11)
### Features
* add support flags ([3d0fd39](https://github.com/dnlup/doc/commit/3d0fd396817fa1f06ddcfc161d2ac37dc0327121))
### [3.0.3](https://github.com/dnlup/doc/compare/v3.0.2...v3.0.3) (2020-11-10)

@@ -7,0 +14,0 @@

5

index.d.ts

@@ -57,7 +57,8 @@ import { EventEmitter } from 'events'

declare function createSampler(options?: SamplerOptions): Sampler
export default createSampler
export { createSampler }
export const eventLoopUtilizationSupported: Boolean
export const resourceUsageSupported: Boolean
export const gcFlagsSupported: Boolean
export { CPUMetric } from './types/cpuMetric'

@@ -64,0 +65,0 @@ export { EventLoopDelayMetric } from './types/eventLoopDelayMetric'

'use strict'
const Sampler = require('./lib/sampler')
const util = require('./lib/util')

@@ -14,1 +15,19 @@ function createSampler (options = {}) {

module.exports.Sampler = Sampler
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
})

3

lib/eventLoopUtilization.js

@@ -10,6 +10,7 @@ 'use strict'

const kLastSample = Symbol('kLastSample')
const { eventLoopUtilizationSupported } = require('./util')
class EventLoopUtiizationMetric {
constructor () {
if (!eventLoopUtilization) {
if (!eventLoopUtilizationSupported) {
throw new Error('eventLoopUtilization is not supported on this Node.js version')

@@ -16,0 +17,0 @@ }

@@ -16,3 +16,2 @@ 'use strict'

NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE
} = constants

@@ -26,3 +25,3 @@ const {

const flagsSupported = NODE_PERFORMANCE_GC_FLAGS_NO !== undefined
const { gcFlagsSupported } = require('./util')

@@ -51,3 +50,3 @@ const GC_ENTRIES = Object.freeze({

this.average = 0
if (flagsSupported) {
if (gcFlagsSupported) {
this.flags = new Map()

@@ -69,3 +68,3 @@ }

if (flagsSupported) {
if (gcFlagsSupported) {
const flags = GC_FLAGS[gcEntry.flags]

@@ -91,3 +90,3 @@ if (flags) {

this.average = 0
if (flagsSupported) {
if (gcFlagsSupported) {
for (const entry of this.flags.keys()) {

@@ -94,0 +93,0 @@ this.flags.delete(entry)

@@ -9,2 +9,3 @@ 'use strict'

} = require('./symbols')
const { resourceUsageSupported } = require('./util')

@@ -15,3 +16,3 @@ const kLastSample = Symbol('kLastSample')

constructor () {
if (typeof process.resourceUsage !== 'function') {
if (!resourceUsageSupported) {
throw new Error('resourceUsage is not supported on this Node.js version')

@@ -18,0 +19,0 @@ }

{
"name": "@dnlup/doc",
"version": "3.0.3",
"version": "3.1.0",
"description": "Get usage and health data about your Node.js process",

@@ -12,3 +12,3 @@ "main": "index.js",

"lint:ts": "eslint *.ts",
"test": "npm run lint && npm run test:js && npm run test:ts",
"test": "npm run test:js && npm run test:ts",
"test:ci": "npm run lint && npm run test:js -- --coverage-report=lcovonly && npm run test:ts",

@@ -75,3 +75,3 @@ "test:js": "tap -J test/**.test.js",

"atomic-sleep": "^1.0.0",
"autocannon": "^6.4.0",
"autocannon": "^7.0.0",
"concurrently": "^5.3.0",

@@ -84,9 +84,10 @@ "deoptigate": "^0.5.0",

"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-standard": "^5.0.0",
"husky": "^4.3.0",
"is-ci": "^2.0.0",
"lint-staged": "^10.5.3",
"markdown-toc": "^1.2.0",
"standard-version": "^9.0.0",
"tap": "^14.10.8",
"tsd": "^0.13.1"
"tsd": "^0.14.0"
},

@@ -93,0 +94,0 @@ "dependencies": {

@@ -6,3 +6,3 @@ # doc

![Benchmarks](https://github.com/dnlup/doc/workflows/Benchmarks/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/dnlup/doc/badge.svg?branch=next)](https://coveralls.io/github/dnlup/doc?branch=next)
[![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)

@@ -13,3 +13,3 @@

`doc` is a small module that helps you collect health metrics about your Node.js process.
It does that by using only the API provided available on Node itself.
It does that by using only the API available on Node itself (i.e. no native dependencies).
It doesn't have any ties with an APM platform, so you are free to use anything you want for that purpose.

@@ -28,3 +28,3 @@ Its API lets you access both computed and raw values, where possible.

- [API](#api)
* [doc([options])](#docoptions)
* [`doc([options])`](#docoptions)
* [Class: `doc.Sampler`](#class-docsampler)

@@ -66,3 +66,5 @@ + [new `doc.Sampler([options])`](#new-docsampleroptions)

* [`total`](#total)
- [Contributing](#contributing)
* [`doc.eventLoopUtilizationSupported`](#doceventlooputilizationsupported)
* [`doc.resourceUsageSupported`](#docresourceusagesupported)
* [`doc.gcFlagsSupported`](#docgcflagssupported)
- [Credits](#credits)

@@ -90,5 +92,5 @@

```js
const doc = require('@dnlup/doc');
const doc = require('@dnlup/doc')
const sampler = doc(); // Use the default options
const sampler = doc() // Use the default options

@@ -120,2 +122,3 @@ sampler.on('sample', () => {

doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.raw) // Available only on Node versions that support it
})

@@ -129,3 +132,3 @@ ```

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

@@ -137,2 +140,3 @@ const sampler = doc({ collect: { gc: true } })

doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.raw) // Available only on Node versions that support it
doStuffWithGarbageCollectionDuration(sampler.gc)

@@ -153,2 +157,3 @@ })

doStuffWithEventLoopDelay(sampler.eventLoopDelay.computed)
doStuffWithEventLoopUtilization(sampler.eventLoopUtilization.raw) // Available only on Node versions that support it
doStuffWithActiveHandles(sampler.activeHandles)

@@ -160,3 +165,3 @@ })

### doc([options])
### `doc([options])`

@@ -404,35 +409,22 @@ It creates a metrics [`Sampler`](#class-docsampler) instance with the given options.

## Contributing
### `doc.eventLoopUtilizationSupported`
You found a bug or want to discuss and implement a new feature? This project welcomes contributions.
* `<boolean>`
The code follows the [standardjs](https://standardjs.com/) style guide.
Whether the Node.js version in use supports the [eventLoopUtilization metric](https://nodejs.org/dist/latest-v14.x/docs/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2).
Every contribution should pass the existing tests or implementing new ones if that's the case.
### `doc.resourceUsageSupported`
```bash
# Run tests locally
$ npm test
* `<boolean>`
# Run js tests
$ npm test:js
Whether the Node.js version in use supports the [resourceUsage metric](https://nodejs.org/dist/latest-v14.x/docs/api/process.html#process_process_resourceusage).
# Run typescript types tests
$ npm test:ts
### `doc.gcFlagsSupported`
# Lint all the code
$ npm lint
* `<boolean>`
# Lint only js files
$ npm lint:js
Whether the Node.js version in use supports [GC flags](https://nodejs.org/dist/latest-v14.x/docs/api/perf_hooks.html#perf_hooks_performanceentry_flags).
# Lint only typescript files
$ npm lint:ts
# Create the TOC in the README
$ npm run doc
```
## Credits
When writing this module, I took a lot of inspiration from the fantastic [Node Clinic Doctor](https://github.com/clinicjs/node-clinic-doctor) package.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc