User Timing
interface allows the developer to create application specific
timestamps
that are part of the browser's
performance timeline
. There are two types of
user
defined timing event types: the "
mark
"
event type
and the "
measure
"
event type
.
mark
events are
命名
by the application and can be set at any location in an application.
measure
events are also
命名
by the application but they are placed between two marks thus they are effectively a
midpoint
between two marks.
This document provides an overview of the
mark
and
measure
performance event types
including the four
User Timing
methods that extend the
性能
interface. For more details and example code regarding these two performance event types and the methods, see
Using the User Timing API
.
marks
A performance
mark
是
命名
performance entry
that is created by the application. The mark is a
timestamp
in the browser's
performance timeline
.
mark
performance.mark()
method is used to create a performance mark. The method takes one argument, the
name
of the mark (for example
performance.mark("mark-1")
).
mark's
performance entry
will have the following property values:
entryType
- set to "
mark
".
名称
- set to the "
名称
" given when the mark was created.
startTime
- set to the
timestamp
当
mark()
被调用。
duration
- set to "
0
" (a mark has no
duration
).
marks
性能
interface has three methods that can be used to retrieve a mark:
performance.getEntries()
performance entries
in the performance timeline. Finding only
mark
entries requires checking each entry's
entryType
for "
mark
".
performance.getEntriesByName(name, entryType)
performance entries
in the performance timeline with the specified
名称
and
entryType
, thus set
entryType
to "
mark
" to get all marks (and set
名称
accordingly to retrieve more specific entries).
performance.getEntriesByType(entryType)
performance entries
in the performance timeline with the specified
entryType
, thus set
entryType
to "
mark
" to get all marks.
marks
To remove a specific mark from the performance timeline, call
performance.clearMarks(name)
where
名称
is the name of the mark(s) you want removed. If this method is called with no arguments, all mark type entries will be removed from the performance timeline.
measures
measure
events are also
命名
by the application but they are placed between two marks thus they are effectively a
midpoint
between two marks.
measure
A
measure
is created by calling
performance.measure(measureName, startMarkName, endMarkName)
where
measureName
is the measure's name and
startMarkName
and
endMarkName
are the start and end names, respectively, of the marks the measure will be placed between (in the performance timeline).
measure's
performance entry
will have the following property values:
entryType
- set to "
measure
".
名称
- set to the "
名称
" given when the measure was created.
startTime
- set to the
timestamp
当
measure()
被调用。
duration
- set to a
DOMHighResTimeStamp
that is the duration of the measure (typically, the end mark timestamp minus the start mark timestamp).
measures
性能
interface has three methods that can be used to retrieve a measure:
performance.getEntries()
performance entries
in the performance timeline. Finding the
measure
entries requires checking each entry's
entryType
for "
measure
".
performance.getEntriesByName(name, entryType)
performance entries
in the performance timeline with the specified
名称
and
entryType
, thus set
entryType
to "
measure
" to get all measures (and set
名称
accordingly to retrieve more specific entries).
performance.getEntriesByType(entryType)
performance entries
in the performance timeline with the specified
entryType
, thus set
entryType
to "
measure
" to get all measures.
measures
To remove a specific measure from the performance timeline, call
performance.clearMeasures(name)
where
名称
is the name of the measure(s) you want removed. If this method is called with no arguments, all measure type entries will be removed from the performance timeline.
As shown in the
性能
接口的
浏览器兼容性
table, the
User Timing
methods are broadly implemented by desktop and mobile browsers (the only exceptions are Desktop Safari and Mobile Safari, however
the Safari Technology Preview 24 has support
).
To test your browser's support for this API, run the
perf-api-support
应用程序。