PerformanceEntry

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).

Note: this interface is exposed to Window and Worker. It is extended by several interfaces including PerformanceMark, PerformanceMeasure, PerformanceFrameTiming, PerformanceNavigationTiming and PerformanceResourceTiming.

Properties

PerformanceEntry.name Read only
A DOMString representing the name of a performance entry when the metric was created.
PerformanceEntry.entryType Read only
A DOMString representing the type of performance metric such as "mark". See entryType for a list of 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()
A jsonizer that returns a JSON representation of the PerformanceEntry object.

Example

The following example checks all PerformanceEntry properties to see if the browser supports them or not and if the browser does support the property, the property's value is written 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] + " = NOT supported");
    }
  }
}

Specifications

Specification Status Comment
Performance Timeline Time Level 2
The definition of 'PerformanceEntry' in that specification.
Editor's Draft Added toJSON() serializer method.
Performance Timeline
The definition of 'PerformanceEntry' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support. 25.0 webkit
46.0 (unprefixed)
(Yes) (Yes) (Yes) (Yes)
33 (unprefixed)
No support
toJSON() method. (Yes) ? (Yes) No support No support No support
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support. (Yes) (Yes) webkit
46.0 (unprefixed)
(Yes) 25.0 (25.0) 1.2 (25.0) 10.0 (Yes)
33 (unprefixed)
No support (Yes) webkit
46.0 (unprefixed)
toJSON() method. (Yes) ? ? 25.0 (25.0) 1.2 (25.0) No support (Yes) No support ?

文档标签和贡献者