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 import os | 5 import os |
6 import tempfile | 6 import tempfile |
7 | 7 |
8 from metrics import loading | 8 from metrics import loading |
9 from telemetry.core import util | 9 from telemetry.core import util |
10 from telemetry.core.platform.profiler import perf_profiler | 10 from telemetry.core.platform.profiler import perf_profiler |
(...skipping 16 matching lines...) Expand all Loading... |
27 page_repeat_option.default = 2 | 27 page_repeat_option.default = 2 |
28 parser.remove_option('--page-repeat') | 28 parser.remove_option('--page-repeat') |
29 parser.add_option(page_repeat_option) | 29 parser.add_option(page_repeat_option) |
30 | 30 |
31 def CustomizeBrowserOptions(self, options): | 31 def CustomizeBrowserOptions(self, options): |
32 perf_profiler.PerfProfiler.CustomizeBrowserOptions(options) | 32 perf_profiler.PerfProfiler.CustomizeBrowserOptions(options) |
33 | 33 |
34 def WillNavigateToPage(self, page, tab): | 34 def WillNavigateToPage(self, page, tab): |
35 tab.browser.StartProfiling(perf_profiler.PerfProfiler.name(), | 35 tab.browser.StartProfiling(perf_profiler.PerfProfiler.name(), |
36 os.path.join(tempfile.mkdtemp(), | 36 os.path.join(tempfile.mkdtemp(), |
37 page.url_as_file_safe_name)) | 37 page.file_safe_name)) |
38 | 38 |
39 def MeasurePage(self, page, tab, results): | 39 def MeasurePage(self, page, tab, results): |
40 # In current telemetry tests, all tests wait for DocumentComplete state, | 40 # In current telemetry tests, all tests wait for DocumentComplete state, |
41 # but we need to wait for the load event. | 41 # but we need to wait for the load event. |
42 def IsLoaded(): | 42 def IsLoaded(): |
43 return bool(tab.EvaluateJavaScript('performance.timing.loadEventStart')) | 43 return bool(tab.EvaluateJavaScript('performance.timing.loadEventStart')) |
44 util.WaitFor(IsLoaded, 300) | 44 util.WaitFor(IsLoaded, 300) |
45 | 45 |
46 profile_files = tab.browser.StopProfiling() | 46 profile_files = tab.browser.StopProfiling() |
47 | 47 |
48 loading.LoadingMetric().AddResults(tab, results) | 48 loading.LoadingMetric().AddResults(tab, results) |
49 | 49 |
50 profile_file = None | 50 profile_file = None |
51 for profile_file in profile_files: | 51 for profile_file in profile_files: |
52 if 'renderer' in profile_file: | 52 if 'renderer' in profile_file: |
53 break | 53 break |
54 | 54 |
55 for function, period in perf_profiler.PerfProfiler.GetTopSamples( | 55 for function, period in perf_profiler.PerfProfiler.GetTopSamples( |
56 profile_file, 10).iteritems(): | 56 profile_file, 10).iteritems(): |
57 results.Add(function.replace('.', '_'), 'period', period) | 57 results.Add(function.replace('.', '_'), 'period', period) |
OLD | NEW |