W3C

User Timing

W3C Working Draft 1 September 2011

This version:
http://www.w3.org/TR/2011/WD-user-timing-20110901/
Latest version:
http://www.w3.org/TR/user-timing/
Latest Editor's Draft:
https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/UserTiming/Overview.html
Previous version:
http://www.w3.org/TR/2011/WD-user-timing-20110811/
Editors:
Jatinder Mann, Microsoft Inc.,
Zhiheng Wang, Google Inc.,
Anderson Quach, Microsoft Inc. (Until March 2011)

Abstract

This specification defines an interface to help web developers measure the performance of their applications by giving them access to high precision timestamps.

Status of this document

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 is a Last Call Working Draft of "User Timing".

Please send comments to public-web-perf@w3.org (archived) with [UserTiming] at the start of the subject line by 22 September 2011.

A diff document with the previous draft is available.

This document is produced by the Web Performance Working Group. The Web Performance Working Group is part of the Rich Web Clients Activity in the W3C Interaction Domain.

You can find the latest Editor's Draft of this document in the W3C's Mercurial repository, which is updated on a regular basis.

Publication as a 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.

Table of Contents

  1. 1 Introduction
  2. 2 Conformance requirements
  3. 3 Terminology
  4. 4 User Timing
    1. 4.1 Introduction
    2. 4.2 The UserTiming Interface
    3. 4.3 The PerformanceMark Interface
    4. 4.4 The PerformanceMeasure Interface
    5. 4.5 Vendor Prefixes
  5. 5 Monotonic Clock
  6. 6 Privacy
  7. 7 Security
  8. Acknowledgements

1 Introduction

This section is non-normative.

Web developers need the ability to assess and understand the performance characteristics of their applications. While JavaScript provides a mechanism to measure application latency (retrieving the current timestamp from the Date.now() method), the precision of this timestamp varies between user agents.

This document introduces the UserTiming interface, which exposes a high precision timestamp to developers so they can better measure the performance of their applications.

TODO: Show example usage.

2 Conformance requirements

All diagrams, examples, and notes in this specification are non-normative, as are all sections explicitly marked non-normative. Everything else in this specification is normative.

The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC2119. For readability, these words do not appear in all uppercase letters in this specification. [RFC2119]

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Some conformance requirements are phrased as requirements on attributes, methods or objects. Such requirements are to be interpreted as requirements on user agents.

Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be easy to follow, and not intended to be performant.)

The IDL fragments in this specification must be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [Web IDL]

3 Terminology

The construction "a Foo object", where Foo is actually an interface, is sometimes used instead of the more accurate "an object implementing the interface Foo".

The term DOM is used to refer to the API set made available to scripts in Web applications, and does not necessarily imply the existence of an actual Document object or of any other Node objects as defined in the DOM Core specifications. [DOM Level 3 Core]

A DOM attribute is said to be getting when its value is being retrieved (such as by author script), and is said to be setting when a new value is assigned to it.

The term "JavaScript" is used to refer to ECMA262, rather than the official term ECMAScript, since the term JavaScript is more widely known. [ECMA262]

4 User Timing

4.1 Introduction

This section is non-normative

The User Timing interface gives web developers access to a high precision, monotonically increasing timestamp so they can better measure the performance characteristics of their applications.

Throughout this work, the term "timestamp" refers to the number of milliseconds since midnight of January 1, 1970 (UTC).

4.2 The UserTiming Interface

  partial interface Performance {
    const unsigned short PERF_DEVELOPER_MARK = 2;
    const unsigned short PERF_DEVELOPER_MEASURE = 3;

    const string MARK_FULLY_LOADED = "fullyLoaded";
    const string MARK_FULLY_VISIBLE = "fullyVisible";
    const string MARK_ABOVE_THE_FOLD = "aboveTheFold";
    const string MARK_TIME_TO_USER_ACTION = "timeToUserAction";

    void mark(in DOMString markName);
    Array getMarks(in optional DOMString markName);
    void clearMarks(in optional  DOMString markName);

    void measure(in DOMString measureName, in optional DOMString startMark, in optional DOMString endMark);
    Array getMeasures(in optional DOMString measureName);
    void clearMeasures(in optional DOMString measureName);
  };
    

mark method

This method stores a timestamp with the associated name (a "mark").

Parameters

in name type of DOMString

The name associated with the timestamp.

Mark names may be re-used within the same document. Each call to the mark() method stores a new timestamp under the specified mark name.

The mark name cannot be the same name as any of the attributes in the PerformanceTiming interface [Navigation Timing].

Standard Mark Names

The mark name may be one of the following Standard Mark Names. When using a Standard Mark Name, the user agent is responsible for storing a new timestamp under the specified mark name. The user agent does not validate that the usage of the Standard Mark Name is appropriate or consistent with its description.

MARK_FULLY_LOADED

The time when the page is considered fully loaded as marked by the developer in their application.

MARK_FULLY_VISIBLE

The time when the page is considered completely visible to an end-user as marked by the developer in their application.

MARK_ABOVE_THE_FOLD

The time when all of the content in the visible viewport has been presented to the end-user as marked by the developer in their application.

MARK_TIME_TO_USER_ACTION

The time of the first user interaction with the page during or after a navigation, such as scroll or click, as marked by the developer in their application.

No Return Value

Exceptions

Throws a SYNTAX_ERR exception if the markName argument is the same name as an attribute in the PerformanceTiming interface.

getMarks method

If the markName argument is not specified, this method must return all of the marks and their associated timestamps.

If the markName argument is specified, this method must return all of the timestamps for the specified mark name.

If the markName argument is specified but it does not exist, this method must return an empty array.

Parameters

in markName type of DOMString

[optional] The name of the mark. If not specified, all marks are returned.

Return Value

Array

If the markName argument is not specified, the method returns an associative Array. Each key in the Array is a mark name. The value associated with the mark name is an Array of timestamps for that mark. In JSON notation, the data structure will look similar to this: { "mark1": [0, 1, 3], "mark2": [2] }

If the markName argument is specified, and the mark name exists, the method returns an Array of timestamps. In JSON notation, the data structure will look similar to this: [0, 1, 3]

If the markName argument is specified, and the mark name does not exist, the method returns an empty Array. In JSON notation, the data structure will look similar to this: []

Timestamps will be listed in the order that the mark() method was called.

The returned Array is a copy of data at the time that the getMarks() method was called.

No Exceptions

clearMarks method

If the markName argument is not specified, this method removes all marks and their associated timestamps.

If the markName argument is specified, this method removes all timestamps for the given mark name.

If the markName argument is specified but the specified markName does not exist, this method will do nothing.

Parameters

in markName type of DOMString

[optional] The name of the mark whose timestamps should be cleared. If not specified, all marks will be cleared.

No Return Value

No Exceptions

measure method

This method stores the duration between two marks (measured in milliseconds) along with the associated name (a "measure").

The behavior of this method depends on which arguments are specified:

The startMark and endMark arguments may be the name of one of the attributes in the PerformanceTiming interface [Navigation Timing]. In this case, the value of that attribute is used as the timestamp.

Parameters

in name type of DOMString

The name associated with the measure.

Measure names may be re-used within the same document. Each call to the measure() method stores a new duration under the specified measure name.

Measure names live independently from mark names.

in startMark type of DOMString

[optional] The name of the start mark.

If specified, the most recent timestamp of the start mark is used.

If not specified, fetchStart is used.

May be the name of one of the attributes in the PerformanceTiming interface [Navigation Timing]. In this case, the value of that attribute is used as the start timestamp.

in endMark type of DOMString

[optional] The name of the end mark.

If specified, the most recent timestamp of the end mark is used.

If not specified, the current time is used.

May be the name of one of the attributes in the PerformanceTiming interface [Navigation Timing]. In this case, the value of that attribute is used as the end timestamp.

No Return Value

Exceptions

Throws a SYNTAX_ERR exception if the start mark or end mark does not exist.

Throws a SYNTAX_ERR exception if the duration (the end mark timestamp minus the start mark timestamp) is negative.

Throws a SYNTAX_ERR exception if either startMark or endMark argument, or both, have the same name as a PerformanceTiming attribute with a timestamp value of 0 [Navigation Timing].

getMeasures method

If the measureName argument is not specified, this method must return all of the measures and their associated durations.

If the measureName argument is specified, this method must return all of the durations for the specified measure name.

If the measureName argument is specified but it does not exist, this method must return an empty array.

Parameters

in measureName type of DOMString

[optional] The name of the measure to return. If not specified, all measures are returned.

Return Value

Array

If the measureName argument is not specified, the method returns an associative Array. Each key in the Array is a measure name. The value associated with the measure name is an Array of durations for that measure. In JSON notation, the data structure will look similar to this: { "measure1": [0, 5, 1], "measure2": [3] }

If the measureName argument is specified, and the measure name exists, the method returns an Array of durations. In JSON notation, the data structure will look similar to this: [0, 5, 1]

If the measureName argument is specified, and the measure name does not exist, the method returns an empty Array. In JSON notation, the data structure will look similar to this: []

Durations will be listed in the order that the measure() method was called.

The returned Array is a copy of data at the time that the getMeasures() method was called.

No Exceptions

clearMeasures method

If the measureName argument is not specified, this method removes all measures and their associated durations.

If the measureName argument is specified, this method removes all durations for the given measure name.

If the measureName argument is specified but the specified measureName does not exist, this method will do nothing.

Parameters

in measureName type of DOMString

[optional] The name of the measure whose durations should be cleared. If not specified, all measures will be cleared.

No Return Value

No Exceptions

4.3 The PerformanceMark Interface

  interface PerformanceMark : PerformanceEntry {
  }
    

The PerformanceMark interface also exposes marks created via the mark() method to the Performance Timeline. The PerformanceMark interface extends the following attributes of the PerformanceEntry interface:

The name attribute will return the mark's name.

The entryType attribute will return PERF_DEVELOPER_MARK.

The startTime attribute will return the mark's timestamp.

The duration attribute will return 0.

4.4 The PerformanceMeasure Interface

  interface PerformanceMeasure : PerformanceEntry {
  }
    

The PerformanceMeasure interface also exposes measures created via the measure() method to the Performance Timeline. The PerformanceMeasure interface extends the following attributes of the PerformanceEntry interface:

The name attribute will return the measure's name.

The entryType attribute will return PERF_DEVELOPER_MEASURE.

The startTime attribute will return the timestamp of the measure's start mark.

The duration attribute will return the duration of the measure.

4.5 Vendor Prefixes

Vendor-specific proprietary user agent extensions to this specification are strongly discouraged. If such extensions are needed, e.g. for experimental purposes, vendors must use the following extension mechanisms:

If the extension to be added is a Standard Mark Name, the Standard Mark Name must:

5 Monotonic Clock

The timestamps stored within the interface must monotonically increase to ensure they are not affected by adjustments to the system clock. The difference between any two chronologically recorded timestamps must never be negative. The user agent must record the system clock at the beginning of the navigation and define subsequent timestamps in terms of a monotonic clock measuring time elapsed from the beginning of the navigation.

6 Privacy

This section is non-normative.

UserTiming potentially exposes information about specific activities on a page. This information must explicitly not be accessible in cross-domain situations and made available to only the server where the root document originates.

7 Security

This section is non-normative.

Similar to the discussion in the Privacy section.

Acknowledgements

Thanks to James Simonsen, Jason Weber, Karen Anderson, Nic Jansma, Steve Souders, and Tony Gentilcore for their useful comments that led to changes to this specification and their contributions to this work.

References

[IETF RFC 2119]
Key words for use in RFCs to Indicate Requirement Levels, Scott Bradner, Author. Internet Engineering Task Force, March 1997. Available at http://www.ietf.org/rfc/rfc2119.txt.
[DOM Level 3 Core]
Document Object Model Level 3 Core Specification, A. Le Hors, et al., Editors. World Wide Web Consortium, 7 April 2004. This version of the Document Object Model Level 3 Core Recommendation is http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407. The latest version of DOM Core is available at http://www.w3.org/TR/domcore/.
[ECMA-262]
ECMAScript Language Specification, 5th Edition. ECMA International, Standard ECMA-262, December 2009. This version of the ECMAScript Language is available from http://www.ecma-international.org/publications/standards/Ecma-262.htm.
[Navigation Timing]
Navigation Timing, Zhiheng Wang, Editor. World Wide Web Consortium, June 2011. This version of the Navigation Timing specification is available from http://www.w3.org/TR/2011/CR-navigation-timing-20110602/. The latest version of Navigation Timing is available at http://www.w3.org/TR/navigation-timing/.
[Performance Timeline]
Performance Timeline, Jatinder Mann, et al, Editors. World Wide Web Consortium, September 2011. This version of the Performance Timeline specification is available from http://www.w3.org/TR/performance-timeline/. The latest version of Performance Timeline is available at http://www.w3.org/TR/performance-timeline/.
[Web IDL]
Web IDL, Cameron McCormack, Editor. World Wide Web Consortium, July 2011. This version of the Web IDL specification is available from http://www.w3.org/TR/2011/WD-WebIDL-20110712/. The latest version of Web IDL is available at http://www.w3.org/TR/WebIDL/.