PerformanceObserverEntryList

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

注意:此功能在 Web Workers 中可用。

PerformanceObserverEntryList 接口是可通过 observe() 方法显式观察到的 性能事件 列表。

实例方法

PerformanceObserverEntryList.getEntries()

返回所有显式观察到的 PerformanceEntry 对象列表。

PerformanceObserverEntryList.getEntriesByType()

返回给定条目类型的所有显式观察到的 PerformanceEntry 对象列表。

PerformanceObserverEntryList.getEntriesByName()

根据给定的名称和条目类型,返回所有显式观察到的 PerformanceEntry 对象列表。

示例

使用 PerformanceObserverEntryList

在以下示例中,listPerformanceObserverEntryList 对象。调用 getEntries() 方法来获取所有显式观察到的 PerformanceEntry 对象,在本例中是“measure”和“mark”。

js
function perfObserver(list, observer) {
  list.getEntries().forEach((entry) => {
    if (entry.entryType === "mark") {
      console.log(`${entry.name}'s startTime: ${entry.startTime}`);
    }
    if (entry.entryType === "measure") {
      console.log(`${entry.name}'s duration: ${entry.duration}`);
    }
  });
}
const observer = new PerformanceObserver(perfObserver);
observer.observe({ entryTypes: ["measure", "mark"] });

规范

规范
性能时间线
# performanceobserverentrylist-interface

浏览器兼容性