當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。