PerformanceEntry

这篇翻译不完整。请帮忙从英语翻译这篇文章

PerformanceEntry 对象代表了 performance 时间列表中的单个 metric 数据. 每一个 performance entry 都可以在应用运行过程中通过手动构建 mark 或者 measure (例如调用 mark() 方法) 生成. 此外, Performance entries 在资源加载的时候,也会被动生成(例如图片、script、css等资源加载)

Note: Performance 对象暴露给了 WindowWorker. 同时该对象扩展了几个其他对象的属性,包括 PerformanceMark, PerformanceMeasure, PerformanceFrameTiming, PerformanceNavigationTiming 以及 PerformanceResourceTiming.

Properties

PerformanceEntry.name 只读
DOMString 该 performance entry 的名字
PerformanceEntry.entryType 只读
DOMString 代表所上报的 performance metric 的 entryType 类型,例如 "mark". 可以通过 entryType 查阅完整的 entryType type 类型.
PerformanceEntry.startTime 只读
 DOMHighResTimeStamp  此为 metric 上报时的时间
PerformanceEntry.duration 只读
DOMHighResTimeStamp 该事件的耗时

Methods

PerformanceEntry.toJSON()
返回 PerformanceEntry 对象的 JSON 格式数据
 

Example

以下例子检查了当前浏览器所支持的所有 PerformanceEntry 属性,每个属性的检查结果都会通过 console 打印出来

function print_PerformanceEntries() {
  // Use getEntries() to get a list of all performance entries
  var p = performance.getEntries();
  for (var i=0; i < p.length; i++) {
    console.log("PerformanceEntry[" + i + "]");
    print_PerformanceEntry(p[i]);
  }
}
function print_PerformanceEntry(perfEntry) {
  var properties = ["name",
    "entryType",
    "startTime",
    "duration"];

  for (var i=0; i < properties.length; i++) {
    // check each property
    var supported = properties[i] in perfEntry;
    if (supported) {
      var value = perfEntry[properties[i]];
      console.log("... " + properties[i] + " = " + value);
    } else {
      console.log("... " + properties[i] + " = NOT supported");
    }
  }
}

Specifications

Specification Status Comment
Performance Timeline Level 2
PerformanceEntry
Candidate Recommendation Added toJSON() serializer method.
Performance Timeline
PerformanceEntry
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 46
Full support 46
Full support 25
Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support 33Safari Full support 11WebView Android Full support 46
Full support 46
Full support Yes
Prefixed
Prefixed Requires the vendor prefix: webkit
Chrome Android Full support 46
Full support 46
Full support 25
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 25Opera Android Full support 33Safari iOS Full support 11Samsung Internet Android ?
Available in workersChrome Full support 62Edge ? Firefox Full support 60IE ? Opera Full support 49Safari ? WebView Android Full support 62Chrome Android Full support 62Edge Mobile ? Firefox Android Full support 60Opera Android Full support 49Safari iOS ? Samsung Internet Android ?
durationChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 11Samsung Internet Android ?
entryTypeChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 11Samsung Internet Android ?
nameChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 11Samsung Internet Android ?
startTimeChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 25Opera Android Full support YesSafari iOS Full support 11Samsung Internet Android ?
toJSONChrome Full support YesEdge ? Firefox Full support YesIE No support NoOpera Full support YesSafari Full support 11WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 25Opera Android Full support YesSafari iOS Full support 11Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

文档标签和贡献者

此页面的贡献者: fscholz, CCCYing, abbycar
最后编辑者: fscholz,