GeezerVison is showing github.com — perf_hooks: make event loop delay histogram disposable · nodejs/node@13abca3
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/perf_hooks.md +17Lines changed: 17 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1973,6 +1973,23 @@ added: v11.10.0 |
1973 | 1973 | Enables the update interval timer. Returns `true` if the timer was |
1974 | 1974 | started, `false` if it was already started. |
1975 | 1975 |
|
| 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 | + |
1976 | 1993 | ### Cloning an `IntervalHistogram` |
1977 | 1994 |
|
1978 | 1995 | {IntervalHistogram} instances can be cloned via {MessagePort}. On the receiving |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/perf/event_loop_delay.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
3 | 3 | ReflectConstruct, |
4 | 4 | SafeMap, |
5 | 5 | Symbol, |
| 6 | + SymbolDispose, |
6 | 7 | } = primordials; |
7 | 8 |
|
8 | 9 | const { |
@@ -38,7 +39,7 @@ const { |
38 | 39 | const kEnabled = Symbol('kEnabled'); |
39 | 40 |
|
40 | 41 | class ELDHistogram extends Histogram { |
41 | | - constructor(i) { |
| 42 | + constructor() { |
42 | 43 | throw new ERR_ILLEGAL_CONSTRUCTOR(); |
43 | 44 | } |
44 | 45 |
|
@@ -65,6 +66,10 @@ class ELDHistogram extends Histogram { |
65 | 66 | this[kHandle].stop(); |
66 | 67 | return true; |
67 | 68 | } |
| 69 | + |
| 70 | + [SymbolDispose]() { |
| 71 | + this.disable(); |
| 72 | + } |
68 | 73 | } |
69 | 74 |
|
70 | 75 | /** |
|