Skip to content

Commit b3eebe2

Browse files
committed
perf_hooks,http2: add clearHttp2 to remove http2 entries
Add missing clearHttp2 method to `perf_hooks.performance` to remove the http2 entries from the master timeline to prevent that from being a memory leak.
1 parent a02fcd2 commit b3eebe2

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

doc/api/perf_hooks.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ added: v8.5.0
3939
If `name` is not provided, removes all `PerformanceFunction` objects from the
4040
Performance Timeline. If `name` is provided, removes entries with `name`.
4141

42+
### performance.clearHttp2()
43+
<!-- YAML
44+
added: REPLACEME
45+
-->
46+
47+
Remove all `http2` performance entry objects from the Performance Timeline.
48+
4249
### performance.clearMarks([name])
4350
<!-- YAML
4451
added: v8.5.0

lib/perf_hooks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ class Performance extends PerformanceObserverEntryList {
471471
this[kClearEntry]('function', name);
472472
}
473473

474+
clearHttp2() {
475+
this[kClearEntry]('http2');
476+
}
477+
474478
timerify(fn) {
475479
if (typeof fn !== 'function') {
476480
const errors = lazyErrors();

test/parallel/test-http2-perf_hooks.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const h2 = require('http2');
88

9-
const { PerformanceObserver } = require('perf_hooks');
9+
const { PerformanceObserver, performance } = require('perf_hooks');
1010

1111
const obs = new PerformanceObserver(common.mustCall((items) => {
1212
const entry = items.getEntries()[0];
@@ -46,6 +46,7 @@ const obs = new PerformanceObserver(common.mustCall((items) => {
4646
default:
4747
assert.fail('invalid entry name');
4848
}
49+
performance.clearHttp2();
4950
}, 4));
5051
obs.observe({ entryTypes: ['http2'] });
5152

@@ -100,3 +101,8 @@ server.on('listening', common.mustCall(() => {
100101
}));
101102

102103
}));
104+
105+
process.on('exit', () => {
106+
// There shouldn't be any http2 entries left over.
107+
assert.strictEqual(performance.getEntries().length, 1);
108+
});

0 commit comments

Comments
 (0)