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. 4 5from metrics import Metric 6 7class LoadingMetric(Metric): 8 """A metric for page loading time based entirely on window.performance""" 9 10 def Start(self, page, tab): 11 raise NotImplementedError() 12 13 def Stop(self, page, tab): 14 raise NotImplementedError() 15 16 def AddResults(self, tab, results): 17 load_timings = tab.EvaluateJavaScript('window.performance.timing') 18 19 # NavigationStart relative markers in milliseconds. 20 load_start = ( 21 float(load_timings['loadEventStart']) - load_timings['navigationStart']) 22 results.Add('load_start', 'ms', load_start) 23 24 dom_content_loaded_start = ( 25 float(load_timings['domContentLoadedEventStart']) - 26 load_timings['navigationStart']) 27 results.Add('dom_content_loaded_start', 'ms', dom_content_loaded_start) 28 29 fetch_start = ( 30 float(load_timings['fetchStart']) - load_timings['navigationStart']) 31 results.Add('fetch_start', 'ms', fetch_start, data_type='unimportant') 32 33 request_start = ( 34 float(load_timings['requestStart']) - load_timings['navigationStart']) 35 results.Add('request_start', 'ms', request_start, data_type='unimportant') 36 37 # Phase measurements in milliseconds. 38 domain_lookup_duration = ( 39 float(load_timings['domainLookupEnd']) - 40 load_timings['domainLookupStart']) 41 results.Add('domain_lookup_duration', 'ms', domain_lookup_duration, 42 data_type='unimportant') 43 44 connect_duration = ( 45 float(load_timings['connectEnd']) - load_timings['connectStart']) 46 results.Add('connect_duration', 'ms', connect_duration, 47 data_type='unimportant') 48 49 request_duration = ( 50 float(load_timings['responseStart']) - load_timings['requestStart']) 51 results.Add('request_duration', 'ms', request_duration, 52 data_type='unimportant') 53 54 response_duration = ( 55 float(load_timings['responseEnd']) - load_timings['responseStart']) 56 results.Add('response_duration', 'ms', response_duration, 57 data_type='unimportant') 58