★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/645be73b9dNouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files
perf_hooks,http2: add performance.clear()
Add missing clear() method to `perf_hooks.performance` to
remove the entries from the master timeline to prevent
that from being a memory leak.

PR-URL: #18046
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell authored and evanlucas committed Jan 30, 2018
1 parent 30e2221 commit 645be73b9d0196ba704e22e1375584a7fc797287
Showing with 21 additions and 1 deletion.
  1. +8 −0 doc/api/perf_hooks.md
  2. +4 −0 lib/perf_hooks.js
  3. +9 −1 test/parallel/test-http2-perf_hooks.js
@@ -29,6 +29,14 @@ added: v8.5.0
The `Performance` provides access to performance metric data. A single
instance of this class is provided via the `performance` property.

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

Remove all performance entry objects with `entryType` equal to `name` from the
Performance Timeline.

### performance.clearFunctions([name])
<!-- YAML
added: v8.5.0
@@ -471,6 +471,10 @@ class Performance extends PerformanceObserverEntryList {
this[kClearEntry]('function', name);
}

clearEntries(name) {
this[kClearEntry](name);
}

timerify(fn) {
if (typeof fn !== 'function') {
const errors = lazyErrors();
@@ -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];
@@ -46,6 +46,7 @@ const obs = new PerformanceObserver(common.mustCall((items) => {
default:
assert.fail('invalid entry name');
}
performance.clearEntries('http2');
}, 4));
obs.observe({ entryTypes: ['http2'] });

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

}));

process.on('exit', () => {
const entries = performance.getEntries();
// There shouldn't be any http2 entries left over.
assert.strictEqual(entries.length, 1);
assert.strictEqual(entries[0], performance.nodeTiming);
});

0 comments on commit 645be73

Please sign in to comment.