diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 0a81874adb7b55..3e05ba285fd3cf 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) - - -Remove all performance entry objects with `entryType` equal to `name` from the -Performance Timeline. - -### performance.clearFunctions([name]) - - -* `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() - - -Remove all performance entry objects with `entryType` equal to `gc` from the -Performance Timeline. - ### performance.clearMarks([name]) - -* `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() - - -* Returns: {Array} - -Returns a list of all `PerformanceEntry` objects in chronological order -with respect to `performanceEntry.startTime`. - -### performance.getEntriesByName(name[, type]) - - -* `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) - - -* `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]) - -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)