When multiple contexts need to synchronize work with sub-millisecond resolution (e.g. when using dedicated or shared workers to drive animation, audio, etc., in a renderer context), or to create a unified view of the event timeline.
等
timeOrigin 是不受系统、用户时钟的影响,偏差等
1.2、使用timing 进行性能监测
1.2.1、生命周期:original text
∂:navigation [nævɪ'geɪʃ(ə)n] 导航/浏览
1、开始
导航被终止:上下文导航预先存在;;用户取消导航
原文:The navigation is aborted due to the sandboxed navigation browsing context flag, the sandboxed top-level navigation without user activation browsing context flag or the sandboxed top-level navigation with user activation browsing context flag, a preexisting attempt to navigate the browsing context, or the user canceling the navigation.
3、设置 name 为document [属性为 DOMString]
4、设置entryType 和 initiatorType 为navigation
5、设置startTime 为FDOMHighResTimeStamp,时间值为0,并且 nextHopProtocol 设置为 空[DOMString]
6、记录当前导航类型,如果他尚未设置。
7、If the previous document does not pass the algorithm, set both unloadEventStart and unloadEventEnd to 0 then go to . Otherwise, record unloadEventStart as the time immediately before the unload event.
8、Immediately after the unload event is completed, record the current time as unloadEventEnd. If the navigation URL has an , immediately before the user agent record the time as workerStart, or if the worker is available, record the time before the at the active worker. Otherwise, if the navigation URL has no matching , set workerStart value to zero.
9、【分发步骤】如果是使用GET请求,则用户代理检查应用程序缓存,并且,记录当前时间作为fetchStart,workerStart 设置为零。
ß:
The workerStart attribute MUST return the time immediately before the user agent ran
the worker (if the current document has an active service worker registration [SERVICE-WORKERS])
required to service the request, or if the worker was already available,
the time immediately before the user agent fired an event named `fetch`
at the active worker. Otherwise, if there is no active worker this attribute
MUST return zero.
∂:workerStart:应该是记录一个触发请求事件之前的时间,在没有服务工作者【Run Service Worker】的时候,workerStart 为零。
10、Let domainLookupStart, domainLookupEnd, connectStart and connectEnd be the same value as fetchStart.
11、将名称设置为当前文档地址的DOMString值。
12、如果这个资源可以从相关应用缓存、本地资源中包括HTTP缓存[RFC7234] 中获取fetching的话,让我们跳转至【请求启动步骤】
13、如果可以不进行域查找,则跳转至【链接启动步骤】,否则,在用户代理启动域名查询之前,记录此刻作为domainLookupStart
14、在域名查询成功之后,记录此时为domainLookupEnd
15、【链接启动步骤】如果使用长链接[a persistent 持久 transport connection]获取资源,则让connectStart和connectEnd与domainLookupEnd保持一致。否则,记录开始连接到服务器之前的时刻作为connectStart,并且记录在连接服务器或者代理建立之后的时刻作为connectEnd。用户代理可能需要多次重试在[连接建立]之前。一旦建立连接将ALPN ID设置为nextHopProtocol的值用来连接。如果链接没有被建立,abort终止这个步骤接下来的部分。
16、用户代理务必根据此流程设置secureConnectionStart属性:
当使用安全传输时,用户代理必须记录握手之前的时刻作为secureConnectionStart的值,[When a secure transport is used, the user agent MUST record the time as secureConnectionStart immediately before the handshake process to secure the connection.]
NOTE
When persistent connection [RFC7230] is enabled, a user agent MAY first try to re-use an open connect to send the request while the connection can be asynchronously closed. In such case, connectStart, connectEnd and requestStart SHOULD represent timing information collected over the re-open connection.
a. If the timing allow check algorithm does not pass for the origin of the fetched resource,
set redirectStart, redirectEnd, unloadEventStart, unloadEventEnd and redirectCount to 0.
Then, return to fetch-start-step with the new resource.
b. Increment redirectCount by 1.
c. If the value of redirectStart is 0, let it be the value of fetchStart.
d. Let redirectEnd be the value of responseEnd.
e. Set all of the attributes in the PerformanceNavigationTiming object to 0
except startTime, redirectStart, redirectEnd, redirectCount, type, nextHopProtocol,
unloadEventStart and unloadEventEnd. Set nextHopProtocol to the empty DOMString.
f. Return to fetch-start-step with the new resource.
21、在用户代理将当前文档准备就绪时,记录domInteractive 为当时时间。
22、用户代理在文档上触发[fires] DOMContentLoaded event事件之前,立即记录domContentLoadedEventStart为当时时间
23、在DOMContentLoaded event 完成[completes] 时,立即记录domContentLoadedEventEnd
24、用户代理设置current document readiness 为 complete 时,立即记录domComplete
25、loadEventStart:用户代理触发加载事件
26、loadEventEnd:用户代理完成加载事件
27、duration[持续时间]:DOMHighResTimeStamp = doadEventEnd - startTime [Set the duration to a DOMHighResTimeStamp equal to the difference between loadEventEnd and startTime, respectively.]
28、队列展示这个对象
前端性能检测
一、Performance
performance
1.1、timing or timeOrigin
ß:https://developer.mozilla.org/zh-CN/docs/Web/API/Performance/timing mdn 文档上讲timeOrigin将替换timing。但是,文档上timing 是一个对象,timeOrigin 是一个高精度时间戳 所以,参考两个档案。
1.1.1、timing
ß:https://w3c.github.io/navigation-timing/ Performance.timing 也执行了‘高精度时间’标准
1.1.2、timeOrigin
ß:https://w3c.github.io/hr-time/ timeOrigin 是一个亚毫秒级别的单调时钟【High Resolution Time】【Monotonic Clock】,可用来解决
1.2、使用timing 进行性能监测
1.2.1、生命周期:original text
∂:navigation [nævɪ'geɪʃ(ə)n] 导航/浏览
1、开始
2、创建一个新的
PerformanceNavigationTiming
对象,添加在performance entry buffer
3、设置 name 为
document
[属性为 DOMString] 4、设置entryType 和 initiatorType 为navigation
5、设置startTime 为FDOMHighResTimeStamp,时间值为0,并且 nextHopProtocol 设置为 空[DOMString] 6、记录当前导航类型,如果他尚未设置。 7、If the previous document does not pass the algorithm, set both unloadEventStart and unloadEventEnd to 0 then go to . Otherwise, record unloadEventStart as the time immediately before the unload event. 8、Immediately after the unload event is completed, record the current time as unloadEventEnd. If the navigation URL has an , immediately before the user agent record the time as workerStart, or if the worker is available, record the time before the at the active worker. Otherwise, if the navigation URL has no matching , set workerStart value to zero. 9、【分发步骤】如果是使用GET
请求,则用户代理检查应用程序缓存
,并且,记录当前时间作为fetchStart
,workerStart 设置为零。 ß:∂:workerStart:应该是记录一个触发
请求事件
之前的时间,在没有服务工作者
【Run Service Worker】的时候,workerStart 为零。 10、LetdomainLookupStart
,domainLookupEnd
,connectStart
andconnectEnd
be the same value asfetchStart
. 11、将名称设置为当前文档地址的DOMString值。 12、如果这个资源可以从相关应用缓存、本地资源中包括HTTP缓存[RFC7234] 中获取fetching的话,让我们跳转至【请求启动步骤】 13、如果可以不进行域查找,则跳转至【链接启动步骤】,否则,在用户代理启动域名查询之前,记录此刻作为domainLookupStart
14、在域名查询成功之后,记录此时为domainLookupEnd
15、【链接启动步骤】如果使用长链接[a persistent 持久 transport connection]获取资源,则让connectStart
和connectEnd
与domainLookupEnd
保持一致。否则,记录开始连接到服务器之前的时刻作为connectStart
,并且记录在连接服务器或者代理建立之后的时刻作为connectEnd
。用户代理可能需要多次重试在[连接建立]之前。一旦建立连接将ALPN ID
设置为nextHopProtocol
的值用来连接。如果链接没有被建立,abort终止这个步骤接下来的部分。 16、用户代理务必根据此流程设置secureConnectionStart
属性:secureConnectionStart
的值,[When a secure transport is used, the user agent MUST record the time as secureConnectionStart immediately before the handshake process to secure the connection.]secureConnectionStart
为零17、【请求启动步骤】即刻,在用户代理启动发送请求文档的时刻,记录当前时间作为
requestStart
18、记录用户代理接受响应的第一个byte的时间作为responseStart
19、记录接受响应的最后一个byte的时间作为responseEnd
tansferSize
,encodeBodySize
,decodeBodySize
为相应[corresponding] 的值20、如果获取的资源的导致重定向,那么:
21、在用户代理将当前文档准备就绪时,记录
domInteractive
为当时时间。 22、用户代理在文档上触发[fires]DOMContentLoaded event
事件之前,立即记录domContentLoadedEventStart
为当时时间 23、在DOMContentLoaded event
完成[completes] 时,立即记录domContentLoadedEventEnd
24、用户代理设置current document readiness
为complete
时,立即记录domComplete
25、loadEventStart
:用户代理触发加载事件 26、loadEventEnd
:用户代理完成加载事件 27、duration
[持续时间]:DOMHighResTimeStamp
=doadEventEnd
-startTime
[Set the duration to a DOMHighResTimeStamp equal to the difference between loadEventEnd and startTime, respectively.] 28、队列展示这个对象1.2.2、方法实例
根据Resource Timing ,可以用别人家的实例举个例子
实例
1.2.3、这里还有一个监测资源的方法Performance.getEntries()
返回一个数组,将所有http 请求包含在内,与timing大约一致
1.3、参考阅读
http://www.alloyteam.com/2015/09/explore-performance/
1.4、使用场景
很明显,他不易于可视化展示一些需求。