性能时间线
API defines extensions to the
性能
interface to support client-side latency measurements within applications. The extensions provide interfaces to retrieve
性能条目规格
based on specific filter criteria. The standard also includes interfaces that allow an application to define
性能观测器
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 使用性能时间线 .
性能时间线 API 扩展
性能
interface with three methods that provide different mechanisms to get a set of
performance records (metrics)
, depending on the specified filter criteria. The methods are:
getEntries()
performance entries
or, optionally, the entries based on the specified
名称
,
performance type
and/or the
initiatorType
(such as an HTML element).
getEntriesByName()
performance entries
基于指定的
名称
and optionally the
performance type
.
getEntriesByType()
performance entries
基于指定的
performance type
.
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
PerformanceMark
):
名称
The name of the performance entry when the metric was created.
entryType
mark
").
startTime
high resolution timestamp
representing the starting time for the performance entry.
duration
'0'
for such types.)
此接口包括
toJSON()
method that returns the serialization of the
PerformanceEntry
object. The serialization is specific to the performance entry's
type
.
这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
性能观测器 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
performance observer entry list
that contains only
observed
performance entries
. That is, the list contains entries only for the event types that were specified when the observer's
observe()
method was invoked. The
performance observer entry list
interface has the same three
getEntries*()
methods as the
性能
interface. However, note there is one key difference with these methods; the
performance observer entry list
versions are used to retrieve
observed
performance entries within the observer callback.
除了
PerformanceObserver's
接口的
observe()
method (which is used to register the
entry types
to
observe
),
PerformanceObserver
interface also has a
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.
性能
接口的
浏览器兼容性
table, most of these interfaces are broadly implemented by desktop browsers and have less support on mobile devices.
PerformanceEntry
接口的
浏览器兼容性
table, most of these interfaces are broadly implemented by desktop browsers and have less support on mobile devices.
PerformanceObserver
接口的
浏览器兼容性
table, this interface has no shipping implementations.
要测试浏览器对这些接口的支持,运行
perf-api-support
应用程序。