当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js PerformanceObserverEntryList.getEntriesByName(name[, type])用法及代码示例


performanceObserverEntryList.getEntriesByName(name[, type])

添加于:v8.5.0

参数

返回 PerformanceEntry 对象列表,按时间顺序相对于 performanceEntry.startTimeperformanceEntry.name 等于 name ,并且可选地,其 performanceEntry.entryType 等于 type

const {
  performance,
  PerformanceObserver
} = require('node: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')); // []

  performance.clearMarks();
  performance.clearMeasures();
  observer.disconnect();
});
obs.observe({ entryTypes: ['mark', 'measure'] });

performance.mark('test');
performance.mark('meow');

相关用法


注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 PerformanceObserverEntryList.getEntriesByName(name[, type])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。