Copyright © 2015 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This specification extends the High Resolution Time specification [HR-TIME-2] by providing methods to store and retrieve high resolution performance metric data.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This new version is aligned with [HR-TIME-2] and introduces filtering and performance observers.
This is a work in progress and may change without any notices.
This document was published by the Web Performance Working Group as a First Public Working Draft.
This document is intended to become a W3C Recommendation.
If you wish to make comments regarding this document, please send them to
public-web-perf@w3.org
(subscribe,
archives)
with [Performance Timeline]
at the start of your email's subject.
All comments are welcome.
Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 August 2014 W3C Process Document.
This section is non-normative.
Accurately measuring performance characteristics of web applications is an important aspect of making web applications faster. This specification defines the necessary Performance Timeline primitives that enable web developers to access, instrument, and retrieve various performance metrics from the full lifecycle of a web application.
[NAVIGATION-TIMING-2], [RESOURCE-TIMING], and [USER-TIMING] are examples of specifications that define timing information related to the navigation of the document, resources on the page, and developer scripts, respectively. Together these and other performance interfaces define performance metrics that describe the Performance Timeline of a web application. For example, the following script shows how a developer can access the Performance Timeline to obtain performance metrics related to the navigation of the document, resources on the page, and developer scripts:
<!doctype html> <html> <head> </head> <body onload="init()"> <img id="image0" src="http://www.w3.org/Icons/w3c_main.png" /> <script> function init() { performance.mark("startWork"); // see [[User Timing]] doWork(); // Some developer code performance.mark("endWork"); measurePerf(); } function measurePerf() { var perfEntries = performance.getEntries(); for (var i = 0; i < perfEntries.length; i++) { if (window.console) console.log("Name: " + perfEntries[i].name + " Entry Type: " + perfEntries[i].entryType + " Start Time: " + perfEntries[i].startTime + " Duration: " + perfEntries[i].duration + "\n"); } } </script> </body> </html>
Alternatively, instead of processing metrics at a predefined time, or having to periodically poll the timeline for new metrics, the developer may also observe the Performance Timeline and be notified of new performance metrics via a Performance Observer:
<!doctype html> <html> <head> </head> <body> <img id="image0" src="http://www.w3.org/Icons/w3c_main.png" /> <script> var observer = new PerformanceObserver(function(list) { var doneObservingEvents = false; var perfEntries = list.getEntries(); for (var i = 0; i < perfEntries.length; i++) { if (window.console) console.log("Name: " + perfEntries[i].name + " Entry Type: " + perfEntries[i].entryType + " Start Time: " + perfEntries[i].startTime + " Duration: " + perfEntries[i].duration + "\n"); } // maybe disconnect after processing the events. if (doneObservingEvents) { observer.disconnect(); } }); // subscribe to Frame-Timing and User-Timing events observer.observe({typeFilter: ['render', 'composite', 'mark', 'measure']}); </script> </body> </html>
The Performance Timeline enables the user agent and application developers to access, instrument, and retrieve various performance metrics from the full lifecycle of a web application.
All interfaces that participate in the Performance Timeline MUST adhere to the following rules:
PerformanceEntry
interfaceThe PerformanceEntry
interface hosts the performance data of various metrics.
[Exposed=(Window,Worker)]
interface PerformanceEntry {
readonly attribute DOMString name;
readonly attribute DOMString entryType;
readonly attribute DOMHighResTimeStamp startTime;
readonly attribute DOMHighResTimeStamp duration;
serializer = {attribute};
};
duration
of type DOMHighResTimeStamp, readonly PerformanceEntry
. Typically, this would be the time difference between the last recorded timestamp and the first recorded timestamp of this PerformanceEntry
. If the duration concept doesn't apply, a performance metric may choose to return a duration
of 0.entryType
of type DOMString, readonly PerformanceEntry
object.name
of type DOMString, readonly PerformanceEntry
object. This identifier does not have to be unique.startTime
of type DOMHighResTimeStamp, readonly Instances of this interface are serialized as a map with entries for each of the serializable attributes.
This extends the Performance interface [HR-TIME-2] and hosts performance related attributes and methods used to retrieve the performance metric data from the Performance Timeline.
dictionary FilterOptions {
DOMString name;
DOMString entryType;
DOMString initiatorType;
};
FilterOptions
MembersentryType
of type DOMString, PerformanceEntry
object.initiatorType
of type DOMString, PerformanceEntry
object.name
of type DOMString, PerformanceEntry
object.partial interface Performance {
PerformanceEntryList
getEntries (optional FilterOptions
filter);
PerformanceEntryList
getEntriesByType (DOMString entryType);
PerformanceEntryList
getEntriesByName (DOMString name, optional DOMString entryType);
};
getEntries
This method returns a PerformanceEntryList
object that contains a list of PerformanceEntry
objects, sorted in chronological order with respect to startTime, that match the following criteria:
PerformanceEntryList
.filter
that is present and the second element is the value of that dictionary member.PerformanceEntry
object (entryObject), in chronological order with respect to startTime:
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
filter |
| ✘ | ✔ |
PerformanceEntryList
getEntriesByName
PerformanceEntryList
object returned by getEntries({'name': name})
if optional entryType
is omitted, and getEntries({'name': name, 'entryType': entryType})
otherwise.Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
name | DOMString | ✘ | ✘ | |
entryType | DOMString | ✘ | ✔ |
PerformanceEntryList
getEntriesByType
PerformanceEntryList
object returned by getEntries({'entryType': entryType})
.Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
entryType | DOMString | ✘ | ✘ |
PerformanceEntryList
typedef sequence<PerformanceEntry
> PerformanceEntryList;
PerformanceEntry
> type.[NoInterfaceObject, Exposed=(Window,Worker)]
interface GlobalPerformance {
[Replaceable]
readonly attribute Performance
performance;
};
performance
of type Performance
, readonly This attribute allows access to performance related attributes and methods.
Window implementsGlobalPerformance
; WorkerGlobalScope implementsGlobalPerformance
;
The PerformanceObserver
interface can be used to observe the Performance Timeline and be notified of new performance entries as they are recorded by the user agent. A registered performance observer consists of an observer (a PerformanceObserver
object) and options (a PerformanceObserverInit
dictionary).
callback PerformanceObserverCallback = void (PerformanceObserverEntryList entries, PerformanceObserver observer) ();
[Constructor(PerformanceObserverCallback callback), Exposed=(Window,Worker)]
interface PerformanceObserver {
void observe (PerformanceObserverInit
options);
void disconnect ();
};
disconnect
void
observe
dictionary PerformanceObserverInit {
sequence<DOMString> typeFilter;
};
PerformanceObserverInit
MemberstypeFilter
of type sequence<DOMString>, A list of valid entryType names to be observed. The list MUST NOT be empty and types not recognized by the user agent MUST be ignored.
To keep the performance overhead to minimum the application should only subscribe to event types that it is interested in, and disconnect the observer once it no longer needs to observe the performance data. Filtering by name is not supported, as it would implicitly require a subscription for all event types — this is possible, but discouraged, as it will generate a significant volume of events.
The observe(options)
method must run these steps:
typeFilter
attribute is not present, throw a JavaScript TypeError
.typeFilter
sequence, and replace the typeFilter
sequence with the new filtered sequence.typeFilter
attribute is an empty sequence, throw a JavaScript TypeError
.options
.Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
options |
| ✘ | ✘ |
void
The PerformanceObserverEntryList
interface provides the same getEntries
, getEntriesByType
, getEntriesByName
methods as the Performance
interface, except that PerformanceObserverEntryList
operates on the observed emitted list of events instead of the global timeline.
[Exposed=(Window,Worker)]
interface PerformanceObserverEntryList {
PerformanceEntryList
getEntries (optional FilterOptions
filter);
PerformanceEntryList
getEntriesByType (DOMString entryType);
PerformanceEntryList
getEntriesByName (DOMString name, optional DOMString entryType);
};
getEntries
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
filter |
| ✘ | ✔ |
PerformanceEntryList
getEntriesByName
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
name | DOMString | ✘ | ✘ | |
entryType | DOMString | ✘ | ✔ |
PerformanceEntryList
getEntriesByType
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
entryType | DOMString | ✘ | ✘ |
PerformanceEntryList
If a vendor-specific proprietary user agent extension is needed to create experimental PerformanceEntry
objects, on getting the entryType IDL attribute, vendors MUST return a DOMString
that uses the following convention:
[vendorPrefix]-[entryType]
Where, [vendorPrefix]
is a non-capitalized name that identifies the vendor, [entryType]
is a non-capitalized name given to the type of interface represented by this PerformanceEntry
object, and the above names are in ASCII.