diff options
author | James M Snell <jasnell@gmail.com> | 2018-03-23 21:23:22 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-04-03 23:57:41 +0300 |
commit | 2ec69955556bf92f49355659b6126e08fa2c3298 (patch) | |
tree | 3164620ed2a629f083119f58fe75856b2ed401c3 /doc/api/perf_hooks.md | |
parent | d54f651910ffca2e50fad42dfec825d2339b1b6b (diff) |
perf_hooks: simplify perf_hooks
Remove the `performance.getEntries()` and `performance.clear*()`
variants and eliminate the accumulation of the global timeline
entries. The design of this particular bit of the API is a memory
leak and performance footgun. The `PerformanceObserver` API is
a better approach to consuming the data in a more transient way.
PR-URL: https://github.com/nodejs/node/pull/19563
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'doc/api/perf_hooks.md')
-rw-r--r-- | doc/api/perf_hooks.md | 106 |
1 files changed, 8 insertions, 98 deletions
diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 0a81874adb7..3e05ba285fd 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -10,14 +10,18 @@ is to support collection of high resolution performance metrics. This is the same Performance API as implemented in modern Web browsers. ```js -const { performance } = require('perf_hooks'); +const { PerformanceObserver, performance } = require('perf_hooks'); + +const obs = new PerformanceObserver((items) => { + console.log(items.getEntries()[0].duration); + performance.clearMarks(); +}); +obs.observe({ entryTypes: ['measure'] }); + performance.mark('A'); doSomeLongRunningProcess(() => { performance.mark('B'); performance.measure('A to B', 'A', 'B'); - const measure = performance.getEntriesByName('A to B')[0]; - console.log(measure.duration); - // Prints the number of milliseconds between Mark 'A' and Mark 'B' }); ``` @@ -26,35 +30,6 @@ doSomeLongRunningProcess(() => { 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: v9.5.0 ---> - -Remove all performance entry objects with `entryType` equal to `name` from the -Performance Timeline. - -### performance.clearFunctions([name]) -<!-- YAML -added: v8.5.0 ---> - -* `name` {string} - -If `name` is not provided, removes all `PerformanceFunction` objects from the -Performance Timeline. If `name` is provided, removes entries with `name`. - -### performance.clearGC() -<!-- YAML -added: v8.5.0 ---> - -Remove all performance entry objects with `entryType` equal to `gc` from the -Performance Timeline. - ### performance.clearMarks([name]) <!-- YAML added: v8.5.0 @@ -65,53 +40,6 @@ added: v8.5.0 If `name` is not provided, removes all `PerformanceMark` objects from the Performance Timeline. If `name` is provided, removes only the named mark. -### performance.clearMeasures([name]) -<!-- YAML -added: v8.5.0 ---> - -* `name` {string} - -If `name` is not provided, removes all `PerformanceMeasure` objects from the -Performance Timeline. If `name` is provided, removes only objects whose -`performanceEntry.name` matches `name`. - -### performance.getEntries() -<!-- YAML -added: v8.5.0 ---> - -* Returns: {Array} - -Returns a list of all `PerformanceEntry` objects in chronological order -with respect to `performanceEntry.startTime`. - -### performance.getEntriesByName(name[, type]) -<!-- YAML -added: v8.5.0 ---> - -* `name` {string} -* `type` {string} -* Returns: {Array} - -Returns a list of all `PerformanceEntry` objects in chronological order -with respect to `performanceEntry.startTime` whose `performanceEntry.name` is -equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to -`type`. - -### performance.getEntriesByType(type) -<!-- YAML -added: v8.5.0 ---> - -* `type` {string} -* Returns: {Array} - -Returns a list of all `PerformanceEntry` objects in chronological order -with respect to `performanceEntry.startTime` whose `performanceEntry.entryType` -is equal to `type`. - ### performance.mark([name]) <!-- YAML added: v8.5.0 @@ -125,20 +53,6 @@ Creates a new `PerformanceMark` entry in the Performance Timeline. A `performanceEntry.duration` is always `0`. Performance marks are used to mark specific significant moments in the Performance Timeline. -### performance.maxEntries -<!-- YAML -added: v9.6.0 ---> - -Value: {number} - -The maximum number of Performance Entry items that should be added to the -Performance Timeline. This limit is not strictly enforced, but a process -warning will be emitted if the number of entries in the timeline exceeds -this limit. - -Defaults to 150. - ### performance.measure(name, startMark, endMark) <!-- YAML added: v8.5.0 @@ -220,7 +134,6 @@ const wrapped = performance.timerify(someFunction); const obs = new PerformanceObserver((list) => { console.log(list.getEntries()[0].duration); obs.disconnect(); - performance.clearFunctions(); }); obs.observe({ entryTypes: ['function'] }); @@ -608,7 +521,6 @@ hook.enable(); const obs = new PerformanceObserver((list, observer) => { console.log(list.getEntries()[0]); performance.clearMarks(); - performance.clearMeasures(); observer.disconnect(); }); obs.observe({ entryTypes: ['measure'], buffered: true }); @@ -642,8 +554,6 @@ const obs = new PerformanceObserver((list) => { console.log(`require('${entry[0]}')`, entry.duration); }); obs.disconnect(); - // Free memory - performance.clearFunctions(); }); obs.observe({ entryTypes: ['function'], buffered: true }); |