OLD | NEW |
| (Empty) |
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 | |
5 import os | |
6 import tempfile | |
7 | |
8 from metrics import loading | |
9 from telemetry.core.platform.profiler import perf_profiler | |
10 from telemetry.page import page_test | |
11 from telemetry.value import scalar | |
12 | |
13 | |
14 class LoadingProfile(page_test.PageTest): | |
15 options = {'page_repeat': 2} | |
16 | |
17 def __init__(self): | |
18 super(LoadingProfile, self).__init__(discard_first_result=True) | |
19 | |
20 def CustomizeBrowserOptions(self, options): | |
21 if not perf_profiler.PerfProfiler.is_supported(browser_type='any'): | |
22 raise Exception('This measurement is not supported on this platform') | |
23 | |
24 perf_profiler.PerfProfiler.CustomizeBrowserOptions( | |
25 browser_type='any', options=options) | |
26 | |
27 def WillNavigateToPage(self, page, tab): | |
28 tab.browser.StartProfiling(perf_profiler.PerfProfiler.name(), | |
29 os.path.join(tempfile.mkdtemp(), | |
30 page.file_safe_name)) | |
31 | |
32 def ValidateAndMeasurePage(self, page, tab, results): | |
33 # In current telemetry tests, all tests wait for DocumentComplete state, | |
34 # but we need to wait for the load event. | |
35 tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300) | |
36 | |
37 profile_files = tab.browser.StopProfiling() | |
38 | |
39 loading.LoadingMetric().AddResults(tab, results) | |
40 | |
41 profile_file = None | |
42 for profile_file in profile_files: | |
43 if 'renderer' in profile_file: | |
44 break | |
45 | |
46 for function, period in perf_profiler.PerfProfiler.GetTopSamples( | |
47 profile_file, 10).iteritems(): | |
48 results.AddValue(scalar.ScalarValue( | |
49 results.current_page, function.replace('.', '_'), 'period', period)) | |
OLD | NEW |