@@ -521,6 +521,38 @@ added: v8.5.0 |
521 | 521 | Returns a list of `PerformanceEntry` objects in chronological order |
522 | 522 | with respect to `performanceEntry.startTime`. |
523 | 523 |
|
| 524 | +```js |
| 525 | +const { |
| 526 | + performance, |
| 527 | + PerformanceObserver |
| 528 | +} = require('perf_hooks'); |
| 529 | + |
| 530 | +const obs = new PerformanceObserver((perfObserverList, observer) => { |
| 531 | + console.log(perfObserverList.getEntries()); |
| 532 | + /** |
| 533 | + * [ |
| 534 | + * PerformanceEntry { |
| 535 | + * name: 'test', |
| 536 | + * entryType: 'mark', |
| 537 | + * startTime: 81.465639, |
| 538 | + * duration: 0 |
| 539 | + * }, |
| 540 | + * PerformanceEntry { |
| 541 | + * name: 'meow', |
| 542 | + * entryType: 'mark', |
| 543 | + * startTime: 81.860064, |
| 544 | + * duration: 0 |
| 545 | + * } |
| 546 | + * ] |
| 547 | + */ |
| 548 | + observer.disconnect(); |
| 549 | +}); |
| 550 | +obs.observe({ entryTypes: ['mark'], buffered: true }); |
| 551 | + |
| 552 | +performance.mark('test'); |
| 553 | +performance.mark('meow'); |
| 554 | +``` |
| 555 | + |
524 | 556 | ### `performanceObserverEntryList.getEntriesByName(name[, type])` |
525 | 557 | <!-- YAML |
526 | 558 | added: v8.5.0 |
@@ -535,6 +567,46 @@ with respect to `performanceEntry.startTime` whose `performanceEntry.name` is |
535 | 567 | equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to |
536 | 568 | `type`. |
537 | 569 |
|
| 570 | +```js |
| 571 | +const { |
| 572 | + performance, |
| 573 | + PerformanceObserver |
| 574 | +} = require('perf_hooks'); |
| 575 | + |
| 576 | +const obs = new PerformanceObserver((perfObserverList, observer) => { |
| 577 | + console.log(perfObserverList.getEntriesByName('meow')); |
| 578 | + /** |
| 579 | + * [ |
| 580 | + * PerformanceEntry { |
| 581 | + * name: 'meow', |
| 582 | + * entryType: 'mark', |
| 583 | + * startTime: 98.545991, |
| 584 | + * duration: 0 |
| 585 | + * } |
| 586 | + * ] |
| 587 | + */ |
| 588 | + console.log(perfObserverList.getEntriesByName('nope')); // [] |
| 589 | + |
| 590 | + console.log(perfObserverList.getEntriesByName('test', 'mark')); |
| 591 | + /** |
| 592 | + * [ |
| 593 | + * PerformanceEntry { |
| 594 | + * name: 'test', |
| 595 | + * entryType: 'mark', |
| 596 | + * startTime: 63.518931, |
| 597 | + * duration: 0 |
| 598 | + * } |
| 599 | + * ] |
| 600 | + */ |
| 601 | + console.log(perfObserverList.getEntriesByName('test', 'measure')); // [] |
| 602 | + observer.disconnect(); |
| 603 | +}); |
| 604 | +obs.observe({ entryTypes: ['mark', 'measure'], buffered: true }); |
| 605 | + |
| 606 | +performance.mark('test'); |
| 607 | +performance.mark('meow'); |
| 608 | +``` |
| 609 | + |
538 | 610 | ### `performanceObserverEntryList.getEntriesByType(type)` |
539 | 611 | <!-- YAML |
540 | 612 | added: v8.5.0 |
@@ -547,6 +619,38 @@ Returns a list of `PerformanceEntry` objects in chronological order |
547 | 619 | with respect to `performanceEntry.startTime` whose `performanceEntry.entryType` |
548 | 620 | is equal to `type`. |
549 | 621 |
|
| 622 | +```js |
| 623 | +const { |
| 624 | + performance, |
| 625 | + PerformanceObserver |
| 626 | +} = require('perf_hooks'); |
| 627 | + |
| 628 | +const obs = new PerformanceObserver((perfObserverList, observer) => { |
| 629 | + console.log(perfObserverList.getEntriesByType('mark')); |
| 630 | + /** |
| 631 | + * [ |
| 632 | + * PerformanceEntry { |
| 633 | + * name: 'test', |
| 634 | + * entryType: 'mark', |
| 635 | + * startTime: 55.897834, |
| 636 | + * duration: 0 |
| 637 | + * }, |
| 638 | + * PerformanceEntry { |
| 639 | + * name: 'meow', |
| 640 | + * entryType: 'mark', |
| 641 | + * startTime: 56.350146, |
| 642 | + * duration: 0 |
| 643 | + * } |
| 644 | + * ] |
| 645 | + */ |
| 646 | + observer.disconnect(); |
| 647 | +}); |
| 648 | +obs.observe({ entryTypes: ['mark'], buffered: true }); |
| 649 | + |
| 650 | +performance.mark('test'); |
| 651 | +performance.mark('meow'); |
| 652 | +``` |
| 653 | + |
550 | 654 | ## `perf_hooks.monitorEventLoopDelay([options])` |
551 | 655 | <!-- YAML |
552 | 656 | added: v11.10.0 |
|