PerformanceEntry - Web APIs 编辑

The PerformanceEntry object encapsulates a single performance metric that is part of the performance timeline. A performance entry can be directly created by making a performance mark or measure (for example by calling the mark() method) at an explicit point in an application. Performance entries are also created in indirect ways such as loading a resource (such as an image).

PerformanceEntry instances will always be one of the following subtypes:

Note:

This feature is available in Web Workers.

Properties

PerformanceEntry.name Read only
A value that further specifies the value returned by the PerformanceEntry.entryType property. The value of both depends on the subtype. See property page for valid values.
PerformanceEntry.entryType Read only
A DOMString representing the type of performance metric such as, for example, "mark". See property page for valid values.
PerformanceEntry.startTime Read only
A DOMHighResTimeStamp representing the starting time for the performance metric.
PerformanceEntry.duration Read only
A DOMHighResTimeStamp representing the time value of the duration of the performance event.

Methods

PerformanceEntry.toJSON()
Returns a JSON representation of the PerformanceEntry object.

Example

The following example checks all PerformanceEntry properties to see if the browser supports them and if so, write their values to the 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] + " is NOT supported");
    }
  }
}

Specifications

SpecificationStatusComment
Resource Timing Level 3Editor's Draft 
Resource Timing Level 2Working Draft 
Resource Timing Level 1Candidate RecommendationAdds the PerformanceResourceTiming interface and the resource value for entryType.
Navigation Timing Level 2Working Draft 
Navigation TimingRecommendationAdds the PerformanceNavigationTiming interface and the navigation value for entryType.
User Timing Level 2Working Draft 
User TimingRecommendationAdds the PerformanceMark and PerformanceMeasure interfaces as well as the mark and measure values for entryType.
Frame TimingDraftAdds the PerformanceFrameTiming interface and the frame value for entryType.
Performance Timeline Level 2
The definition of 'PerformanceEntry' in that specification.
Candidate RecommendationAdded toJSON() serializer method.
Performance Timeline
The definition of 'PerformanceEntry' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:57 次

字数:8296

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文