Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks,http2: add clearEntries to remove http2 entries #18046

Closed
wants to merge 2 commits into from
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
7 changes: 7 additions & 0 deletions doc/api/perf_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ added: v8.5.0
If `name` is not provided, removes all `PerformanceFunction` objects from the
Performance Timeline. If `name` is provided, removes entries with `name`.

### performance.clearHttp2()
<!-- YAML
added: REPLACEME
-->

Remove all `http2` performance entry objects from the Performance Timeline.

### performance.clearMarks([name])
<!-- YAML
added: v8.5.0
Expand Down
4 changes: 4 additions & 0 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ class Performance extends PerformanceObserverEntryList {
this[kClearEntry]('function', name);
}

clearHttp2() {
this[kClearEntry]('http2');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this path is viable, as we will add clearNet(), clearHttp(), clearHTTPS() and so on. How about clear(string)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.


timerify(fn) {
if (typeof fn !== 'function') {
const errors = lazyErrors();
Expand Down
8 changes: 7 additions & 1 deletion test/parallel/test-http2-perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (!common.hasCrypto)
const assert = require('assert');
const h2 = require('http2');

const { PerformanceObserver } = require('perf_hooks');
const { PerformanceObserver, performance } = require('perf_hooks');

const obs = new PerformanceObserver(common.mustCall((items) => {
const entry = items.getEntries()[0];
Expand Down Expand Up @@ -46,6 +46,7 @@ const obs = new PerformanceObserver(common.mustCall((items) => {
default:
assert.fail('invalid entry name');
}
performance.clearHttp2();
}, 4));
obs.observe({ entryTypes: ['http2'] });

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

}));

process.on('exit', () => {
// There shouldn't be any http2 entries left over.
assert.strictEqual(performance.getEntries().length, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the one entry that is left in there? Can we match that instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nodeTiming entry and yes.

});