1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry
.value
import scalar
7 from metrics
import Metric
10 class LoadingMetric(Metric
):
11 """A metric for page loading time based entirely on window.performance"""
13 def Start(self
, page
, tab
):
14 raise NotImplementedError()
16 def Stop(self
, page
, tab
):
17 raise NotImplementedError()
19 def AddResults(self
, tab
, results
):
20 load_timings
= tab
.EvaluateJavaScript('window.performance.timing')
22 # NavigationStart relative markers in milliseconds.
24 float(load_timings
['loadEventStart']) - load_timings
['navigationStart'])
25 results
.AddValue(scalar
.ScalarValue(
26 results
.current_page
, 'load_start', 'ms', load_start
))
28 dom_content_loaded_start
= (
29 float(load_timings
['domContentLoadedEventStart']) -
30 load_timings
['navigationStart'])
31 results
.AddValue(scalar
.ScalarValue(
32 results
.current_page
, 'dom_content_loaded_start', 'ms',
33 dom_content_loaded_start
))
36 float(load_timings
['fetchStart']) - load_timings
['navigationStart'])
37 results
.AddValue(scalar
.ScalarValue(
38 results
.current_page
, 'fetch_start', 'ms', fetch_start
,
42 float(load_timings
['requestStart']) - load_timings
['navigationStart'])
43 results
.AddValue(scalar
.ScalarValue(
44 results
.current_page
, 'request_start', 'ms', request_start
,
47 # Phase measurements in milliseconds.
48 domain_lookup_duration
= (
49 float(load_timings
['domainLookupEnd']) -
50 load_timings
['domainLookupStart'])
51 results
.AddValue(scalar
.ScalarValue(
52 results
.current_page
, 'domain_lookup_duration', 'ms',
53 domain_lookup_duration
, important
=False))
56 float(load_timings
['connectEnd']) - load_timings
['connectStart'])
57 results
.AddValue(scalar
.ScalarValue(
58 results
.current_page
, 'connect_duration', 'ms', connect_duration
,
62 float(load_timings
['responseStart']) - load_timings
['requestStart'])
63 results
.AddValue(scalar
.ScalarValue(
64 results
.current_page
, 'request_duration', 'ms', request_duration
,
68 float(load_timings
['responseEnd']) - load_timings
['responseStart'])
69 results
.AddValue(scalar
.ScalarValue(
70 results
.current_page
, 'response_duration', 'ms', response_duration
,