--- title: Performance Timeline slug: Web/API/Performance_Timeline translation_of: Web/API/Performance_Timeline ---
{{DefaultAPISidebar("Performance Timeline API")}}

The Performance Timeline API defines extensions to the {{domxref("Performance")}} interface to support client-side latency measurements within applications. The extensions provide interfaces to retrieve {{domxref("PerformanceEntry","performance entry metrics", '', 'true')}} based on specific filter criteria. The standard also includes interfaces that allow an application to define {{anch("Performance_Observers","performance observer", '', 'true')}} callbacks that are notified when specific performance events are added to the browser's performance timeline.

This document provides an overview of the standard's interfaces. For more details about the interfaces, see the reference pages and Using Performance Timeline.

Performance extensions

The Performance Timeline API extends the {{domxref("Performance")}} interface with three methods that provide different mechanisms to get a set of {{domxref("PerformanceEntry","performance records (metrics)")}}, depending on the specified filter criteria. The methods are:

{{domxref("Performance.getEntries","getEntries()")}}
Returns all recorded {{domxref("PerformanceEntry","performance entries")}} or, optionally, the entries based on the specified {{domxref("PerformanceEntry.name","name")}}, {{domxref("PerformanceEntry.entryType","performance type")}} and/or the {{domxref("PerformanceEntry.initiatorType","initiatorType")}} (such as an HTML element).
{{domxref("Performance.getEntriesByName","getEntriesByName()")}}
Returns the recorded {{domxref("PerformanceEntry","performance entries")}} based on the specified {{domxref("PerformanceEntry.name","name")}} and optionally the {{domxref("PerformanceEntry.entryType","performance type")}}.
{{domxref("Performance.getEntriesByType","getEntriesByType()")}}
Returns the recorded {{domxref("PerformanceEntry","performance entries")}} based on the specified {{domxref("PerformanceEntry.entryType","performance type")}}.

PerformanceEntry interface

The {{domxref("PerformanceEntry")}} interface encapsulates a single performance entry — that is, a single data point or metric in the performance timeline. This interface has the following four properties, and these properties are extended (with additional constraints) by other interfaces (such as {{domxref("PerformanceMark")}}):

{{domxref("PerformanceEntry.name","name")}}
The name of the performance entry when the metric was created.
{{domxref("PerformanceEntry.entryType","entryType")}}
The type of performance metric (for example, "mark").
{{domxref("PerformanceEntry.startTime","startTime")}}
A {{domxref("DOMHighResTimeStamp","high resolution timestamp")}} representing the starting time for the performance entry.
{{domxref("PerformanceEntry.duration","duration")}}
A {{domxref("DOMHighResTimeStamp","high resolution timestamp", '', 'true')}} representing the time value of the duration of the performance event. (Some performance {{domxref("PerformanceEntry.entryType","entry types", '', 'true')}} have no concept of duration and this value is set to '0' for such types.)

This interface includes a {{domxref("PerformanceEntry.toJSON","toJSON()")}} method that returns the serialization of the {{domxref("PerformanceEntry")}} object. The serialization is specific to the performance entry's {{domxref("PerformanceEntry.entryType","type")}}.

Performance observers

{{SeeCompatTable}}

The performance observer interfaces allow an application to register an observer for specific performance event types, and when one of those event types is recorded, the application is notified of the event via the observer's callback function that was specified when the observer was created.

When the observer (callback) is invoked, the callback's parameters include a {{domxref("PerformanceObserverEntryList","performance observer entry list")}} that contains only observed {{domxref("PerformanceEntry","performance entries")}}. That is, the list contains entries only for the event types that were specified when the observer's {{domxref("PerformanceObserver.observe","observe()")}} method was invoked. The {{domxref("PerformanceObserverEntryList","performance observer entry list")}} interface has the same three getEntries*() methods as the {{domxref("Performance")}} interface. However, note there is one key difference with these methods; the {{domxref("PerformanceObserverEntryList","performance observer entry list")}} versions are used to retrieve observed performance entries within the observer callback.

Besides the {{domxref("PerformanceObserver","PerformanceObserver's")}} interface's {{domxref("PerformanceObserver.observe","observe()")}} method (which is used to register the {{domxref("PerformanceEntry.entryType","entry types")}} to observe), the {{domxref("PerformanceObserver")}} interface also has a {{domxref("PerformanceObserver.disconnect","disconnect()")}} method that stops an observer from receiving further events.

Performance observers were added to the Level 2 version of the standard and were not widely implemented.

实现状态

A summary of the interfaces' implementation status is provided below, including a link to more detailed information.

To test your browser's support for these interfaces, run the perf-api-support application.

参见