Skip to content

Commit 13abca3

Browse files
jasnelltargos
authored andcommitted
perf_hooks: make event loop delay histogram disposable
PR-URL: #58384 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 532c173 commit 13abca3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

doc/api/perf_hooks.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,23 @@ added: v11.10.0
19731973
Enables the update interval timer. Returns `true` if the timer was
19741974
started, `false` if it was already started.
19751975

1976+
### `histogram[Symbol.dispose]()`
1977+
1978+
<!-- YAML
1979+
added: REPLACEME
1980+
-->
1981+
1982+
Disables the update interval timer when the histogram is disposed.
1983+
1984+
```js
1985+
const { monitorEventLoopDelay } = require('node:perf_hooks');
1986+
{
1987+
using hist = monitorEventLoopDelay({ resolution: 20 });
1988+
hist.enable();
1989+
// The histogram will be disabled when the block is exited.
1990+
}
1991+
```
1992+
19761993
### Cloning an `IntervalHistogram`
19771994

19781995
{IntervalHistogram} instances can be cloned via {MessagePort}. On the receiving

lib/internal/perf/event_loop_delay.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const {
33
ReflectConstruct,
44
SafeMap,
55
Symbol,
6+
SymbolDispose,
67
} = primordials;
78

89
const {
@@ -38,7 +39,7 @@ const {
3839
const kEnabled = Symbol('kEnabled');
3940

4041
class ELDHistogram extends Histogram {
41-
constructor(i) {
42+
constructor() {
4243
throw new ERR_ILLEGAL_CONSTRUCTOR();
4344
}
4445

@@ -65,6 +66,10 @@ class ELDHistogram extends Histogram {
6566
this[kHandle].stop();
6667
return true;
6768
}
69+
70+
[SymbolDispose]() {
71+
this.disable();
72+
}
6873
}
6974

7075
/**

0 commit comments

Comments
 (0)