Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
perf_hooks: introduce monitorEventLoopIdleness
`perf_hooks.monitorEventLoopIdleness` tracks the time event loop has
spent waiting for new IO events (i.e. difference between IO poll start
time and IO poll end time). The API is identical to
`monitorEventLoopDelay`.

NOTE: Some of the trace event names had to be renamed for consistency.
  • Loading branch information
indutny committed Feb 28, 2020
commit 27375989ee47b01c6df96954b225c05cb90de689
18 changes: 18 additions & 0 deletions doc/api/perf_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ console.log(h.percentile(50));
console.log(h.percentile(99));
```

## `perf_hooks.monitorEventLoopIdleness([options])`
<!-- YAML
added: REPLACEME
-->

* `options` {Object}
* `resolution` {number} The sampling rate in milliseconds. Must be greater
than zero. **Default:** `10`.
* Returns: {Histogram}

Creates a `Histogram` object that samples and reports the event loop idleness
over time (time difference between IO poll start and poll end). The idleness
will be reported in nanoseconds.

The behavior of `monitorEventLoopIdleness` is identical to
[`monitorEventLoopDelay`][] above.

### Class: `Histogram`
<!-- YAML
added: v11.10.0
Expand Down Expand Up @@ -643,3 +660,4 @@ require('some-module');
[`timeOrigin`]: https://w3c.github.io/hr-time/#dom-performance-timeorigin
[Async Hooks]: async_hooks.html
[W3C Performance Timeline]: https://w3c.github.io/performance-timeline/
[`monitorEventLoopDelay`]: #perf_hooks_perf_hooks_monitoreventloopdelay_options
25 changes: 21 additions & 4 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const {
} = primordials;

const {
ELDHistogram: _ELDHistogram,
ELDHistogram,
ELIHistogram,
PerformanceEntry,
mark: _mark,
clearMark: _clearMark,
Expand Down Expand Up @@ -558,7 +559,7 @@ function sortedInsert(list, entry) {
list.splice(location, 0, entry);
}

class ELDHistogram extends Histogram {
class EventLoopHistogram extends Histogram {
enable() { return this[kHandle].enable(); }
disable() { return this[kHandle].disable(); }
}
Expand All @@ -575,13 +576,29 @@ function monitorEventLoopDelay(options = {}) {
if (resolution <= 0 || !NumberIsSafeInteger(resolution)) {
throw new ERR_INVALID_OPT_VALUE.RangeError('resolution', resolution);
}
return new ELDHistogram(new _ELDHistogram(resolution));
return new EventLoopHistogram(new ELDHistogram(resolution));
}

function monitorEventLoopIdleness(options = {}) {
if (typeof options !== 'object' || options === null) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
const { resolution = 10 } = options;
if (typeof resolution !== 'number') {
throw new ERR_INVALID_ARG_TYPE('options.resolution',
'number', resolution);
}
if (resolution <= 0 || !NumberIsSafeInteger(resolution)) {
throw new ERR_INVALID_OPT_VALUE.RangeError('resolution', resolution);
}
return new EventLoopHistogram(new ELIHistogram(resolution));
}

module.exports = {
performance,
PerformanceObserver,
monitorEventLoopDelay
monitorEventLoopDelay,
monitorEventLoopIdleness
};

ObjectDefineProperty(module.exports, 'constants', {
Expand Down
1 change: 1 addition & 0 deletions src/async_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace node {
V(DIRHANDLE) \
V(DNSCHANNEL) \
V(ELDHISTOGRAM) \
V(ELIHISTOGRAM) \
V(FILEHANDLE) \
V(FILEHANDLECLOSEREQ) \
V(FSEVENTWRAP) \
Expand Down
Loading