| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from telemetry.value import scalar | 5 from telemetry.value import scalar |
| 6 | 6 |
| 7 from metrics import Metric | 7 from metrics import Metric |
| 8 | 8 |
| 9 | 9 |
| 10 class LoadingMetric(Metric): | 10 class LoadingMetric(Metric): |
| 11 | 11 |
| 12 """A metric for page loading time based entirely on window.performance""" | 12 """A metric for page loading time based entirely on window.performance""" |
| 13 | 13 |
| 14 def Start(self, page, tab): | 14 def Start(self, page, tab): |
| 15 raise NotImplementedError() | 15 raise NotImplementedError() |
| 16 | 16 |
| 17 def Stop(self, page, tab): | 17 def Stop(self, page, tab): |
| 18 raise NotImplementedError() | 18 raise NotImplementedError() |
| 19 | 19 |
| 20 def AddResults(self, tab, results): | 20 def AddResults(self, tab, results): |
| 21 load_timings = tab.EvaluateJavaScript2('window.performance.timing') | 21 load_timings = tab.EvaluateJavaScript('window.performance.timing') |
| 22 | 22 |
| 23 # NavigationStart relative markers in milliseconds. | 23 # NavigationStart relative markers in milliseconds. |
| 24 load_start = ( | 24 load_start = ( |
| 25 float(load_timings['loadEventStart']) - load_timings['navigationStart']) | 25 float(load_timings['loadEventStart']) - load_timings['navigationStart']) |
| 26 results.AddValue(scalar.ScalarValue( | 26 results.AddValue(scalar.ScalarValue( |
| 27 results.current_page, 'load_start', 'ms', load_start)) | 27 results.current_page, 'load_start', 'ms', load_start)) |
| 28 | 28 |
| 29 dom_content_loaded_start = ( | 29 dom_content_loaded_start = ( |
| 30 float(load_timings['domContentLoadedEventStart']) - | 30 float(load_timings['domContentLoadedEventStart']) - |
| 31 load_timings['navigationStart']) | 31 load_timings['navigationStart']) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 float(load_timings['responseStart']) - load_timings['requestStart']) | 63 float(load_timings['responseStart']) - load_timings['requestStart']) |
| 64 results.AddValue(scalar.ScalarValue( | 64 results.AddValue(scalar.ScalarValue( |
| 65 results.current_page, 'request_duration', 'ms', request_duration, | 65 results.current_page, 'request_duration', 'ms', request_duration, |
| 66 important=False)) | 66 important=False)) |
| 67 | 67 |
| 68 response_duration = ( | 68 response_duration = ( |
| 69 float(load_timings['responseEnd']) - load_timings['responseStart']) | 69 float(load_timings['responseEnd']) - load_timings['responseStart']) |
| 70 results.AddValue(scalar.ScalarValue( | 70 results.AddValue(scalar.ScalarValue( |
| 71 results.current_page, 'response_duration', 'ms', response_duration, | 71 results.current_page, 'response_duration', 'ms', response_duration, |
| 72 important=False)) | 72 important=False)) |
| OLD | NEW |