summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2019-01-07 11:36:35 -0800
committerjasnell <jasnell@gmail.com>2019-02-08 09:20:18 -0800
commitbcdd228f90b3e9e428b584814e7d52627616456a (patch)
treeeed1b405a1fd7e2f78bbf10e82d65c57d2c29105 /doc
parent679c23f2ae1e62443f8d90e653824007ce174139 (diff)
downloadandroid-node-v8-bcdd228f90b3e9e428b584814e7d52627616456a.tar.gz
android-node-v8-bcdd228f90b3e9e428b584814e7d52627616456a.tar.bz2
android-node-v8-bcdd228f90b3e9e428b584814e7d52627616456a.zip
perf_hooks: implement histogram based api
Add a sampling-based event loop delay monitor. ```js const { monitorEventLoopDelay } = require('perf_hooks'); const h = monitorEventLoopDelay(); h.enable(); h.disable(); console.log(h.percentiles); console.log(h.min); console.log(h.max); console.log(h.mean); console.log(h.stddev); console.log(h.percentile(50)); ``` PR-URL: https://github.com/nodejs/node/pull/25378 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/perf_hooks.md113
1 files changed, 113 insertions, 0 deletions
diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md
index a891e875b5..d805a0cf9d 100644
--- a/doc/api/perf_hooks.md
+++ b/doc/api/perf_hooks.md
@@ -398,6 +398,119 @@ Returns a list of `PerformanceEntry` objects in chronological order
with respect to `performanceEntry.startTime` whose `performanceEntry.entryType`
is equal to `type`.
+## monitorEventLoopDelay([options])
+<!-- YAML
+added: REPLACEME
+-->
+
+* `options` {Object}
+ * `resolution` {number} The sampling rate in milliseconds. Must be greater
+ than zero. Defaults to `10`.
+* Returns: {Histogram}
+
+Creates a `Histogram` object that samples and reports the event loop delay
+over time.
+
+Using a timer to detect approximate event loop delay works because the
+execution of timers is tied specifically to the lifecycle of the libuv
+event loop. That is, a delay in the loop will cause a delay in the execution
+of the timer, and those delays are specifically what this API is intended to
+detect.
+
+```js
+const { monitorEventLoopDelay } = require('perf_hooks');
+const h = monitorEventLoopDelay({ resolution: 20 });
+h.enable();
+// Do something
+h.disable();
+console.log(h.min);
+console.log(h.max);
+console.log(h.mean);
+console.log(h.stddev);
+console.log(h.percentiles);
+console.log(h.percentile(50));
+console.log(h.percentile(99));
+```
+
+### Class: Histogram
+<!-- YAML
+added: REPLACEME
+-->
+Tracks the event loop delay at a given sampling rate.
+
+#### histogram.disable()
+<!-- YAML
+added: REPLACEME
+-->
+
+* Returns: {boolean}
+
+Disables the event loop delay sample timer. Returns `true` if the timer was
+stopped, `false` if it was already stopped.
+
+#### histogram.enable()
+<!-- YAML
+added: REPLACEME
+-->
+
+* Returns: {boolean}
+
+Enables the event loop delay sample timer. Returns `true` if the timer was
+started, `false` if it was already started.
+
+#### histogram.exceeds
+
+* Value: {number}
+
+The number of times the event loop delay exceeded the maximum 1 hour event
+loop delay threshold.
+
+#### histogram.max
+
+* Value: {number}
+
+The maximum recorded event loop delay.
+
+#### histogram.mean
+
+* Value: {number}
+
+The mean of the recorded event loop delays.
+
+#### histogram.min
+<!-- YAML
+added: REPLACEME
+-->
+
+* Value: {number}
+
+The minimum recorded event loop delay.
+
+#### histogram.percentile(percentile)
+
+* `percentile` {number} A percentile value between 1 and 100.
+
+Returns the value at the given percentile.
+
+#### histogram.percentiles
+
+* Value: {Map}
+
+Returns a `Map` object detailing the accumulated percentile distribution.
+
+#### histogram.reset()
+<!-- YAML
+added: REPLACEME
+-->
+
+Resets the collected histogram data.
+
+#### histogram.stddev
+
+* Value: {number}
+
+The standard deviation of the recorded event loop delays.
+
## Examples
### Measuring the duration of async operations