mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
doc: improve perf_hooks docs
PR-URL: https://github.com/nodejs/node/pull/36909 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
889654d36c
commit
8cf280d9ab
1 file changed
+104
@@ -523,6 +523,38 @@ added: v8.5.0
|
||||
Returns a list of `PerformanceEntry` objects in chronological order
|
||||
with respect to `performanceEntry.startTime`.
|
||||
|
||||
```js
|
||||
const {
|
||||
performance,
|
||||
PerformanceObserver
|
||||
} = require('perf_hooks');
|
||||
|
||||
const obs = new PerformanceObserver((perfObserverList, observer) => {
|
||||
console.log(perfObserverList.getEntries());
|
||||
/**
|
||||
* [
|
||||
* PerformanceEntry {
|
||||
* name: 'test',
|
||||
* entryType: 'mark',
|
||||
* startTime: 81.465639,
|
||||
* duration: 0
|
||||
* },
|
||||
* PerformanceEntry {
|
||||
* name: 'meow',
|
||||
* entryType: 'mark',
|
||||
* startTime: 81.860064,
|
||||
* duration: 0
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
observer.disconnect();
|
||||
});
|
||||
obs.observe({ entryTypes: ['mark'], buffered: true });
|
||||
|
||||
performance.mark('test');
|
||||
performance.mark('meow');
|
||||
```
|
||||
|
||||
### `performanceObserverEntryList.getEntriesByName(name[, type])`
|
||||
<!-- YAML
|
||||
added: v8.5.0
|
||||
@@ -537,6 +569,46 @@ with respect to `performanceEntry.startTime` whose `performanceEntry.name` is
|
||||
equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to
|
||||
`type`.
|
||||
|
||||
```js
|
||||
const {
|
||||
performance,
|
||||
PerformanceObserver
|
||||
} = require('perf_hooks');
|
||||
|
||||
const obs = new PerformanceObserver((perfObserverList, observer) => {
|
||||
console.log(perfObserverList.getEntriesByName('meow'));
|
||||
/**
|
||||
* [
|
||||
* PerformanceEntry {
|
||||
* name: 'meow',
|
||||
* entryType: 'mark',
|
||||
* startTime: 98.545991,
|
||||
* duration: 0
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
console.log(perfObserverList.getEntriesByName('nope')); // []
|
||||
|
||||
console.log(perfObserverList.getEntriesByName('test', 'mark'));
|
||||
/**
|
||||
* [
|
||||
* PerformanceEntry {
|
||||
* name: 'test',
|
||||
* entryType: 'mark',
|
||||
* startTime: 63.518931,
|
||||
* duration: 0
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
console.log(perfObserverList.getEntriesByName('test', 'measure')); // []
|
||||
observer.disconnect();
|
||||
});
|
||||
obs.observe({ entryTypes: ['mark', 'measure'], buffered: true });
|
||||
|
||||
performance.mark('test');
|
||||
performance.mark('meow');
|
||||
```
|
||||
|
||||
### `performanceObserverEntryList.getEntriesByType(type)`
|
||||
<!-- YAML
|
||||
added: v8.5.0
|
||||
@@ -549,6 +621,38 @@ Returns a list of `PerformanceEntry` objects in chronological order
|
||||
with respect to `performanceEntry.startTime` whose `performanceEntry.entryType`
|
||||
is equal to `type`.
|
||||
|
||||
```js
|
||||
const {
|
||||
performance,
|
||||
PerformanceObserver
|
||||
} = require('perf_hooks');
|
||||
|
||||
const obs = new PerformanceObserver((perfObserverList, observer) => {
|
||||
console.log(perfObserverList.getEntriesByType('mark'));
|
||||
/**
|
||||
* [
|
||||
* PerformanceEntry {
|
||||
* name: 'test',
|
||||
* entryType: 'mark',
|
||||
* startTime: 55.897834,
|
||||
* duration: 0
|
||||
* },
|
||||
* PerformanceEntry {
|
||||
* name: 'meow',
|
||||
* entryType: 'mark',
|
||||
* startTime: 56.350146,
|
||||
* duration: 0
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
observer.disconnect();
|
||||
});
|
||||
obs.observe({ entryTypes: ['mark'], buffered: true });
|
||||
|
||||
performance.mark('test');
|
||||
performance.mark('meow');
|
||||
```
|
||||
|
||||
## `perf_hooks.monitorEventLoopDelay([options])`
|
||||
<!-- YAML
|
||||
added: v11.10.0
|
||||
|
||||
Reference in new issue
Block a user