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 re |
6 | 7 |
7 from core import path_util | 8 from core import path_util |
8 from core import perf_benchmark | 9 from core import perf_benchmark |
9 | 10 |
10 from telemetry import benchmark | 11 from telemetry import benchmark |
11 from telemetry import page as page_module | 12 from telemetry import page as page_module |
12 from telemetry.page import legacy_page_test | 13 from telemetry.page import legacy_page_test |
13 from telemetry.page import shared_page_state | 14 from telemetry.page import shared_page_state |
14 from telemetry import story | 15 from telemetry import story |
15 from telemetry.value import list_of_scalar_values | 16 from telemetry.value import list_of_scalar_values |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 for url in page_urls: | 68 for url in page_urls: |
68 ps.AddStory(page_module.Page( | 69 ps.AddStory(page_module.Page( |
69 url, ps, ps.base_dir, | 70 url, ps, ps.base_dir, |
70 shared_page_state_class=shared_page_state_class)) | 71 shared_page_state_class=shared_page_state_class)) |
71 return ps | 72 return ps |
72 | 73 |
73 | 74 |
74 class _BlinkPerfMeasurement(legacy_page_test.LegacyPageTest): | 75 class _BlinkPerfMeasurement(legacy_page_test.LegacyPageTest): |
75 """Tuns a blink performance test and reports the results.""" | 76 """Tuns a blink performance test and reports the results.""" |
76 | 77 |
| 78 # The line with values has the following format: |
| 79 # values optional_metric_name list_of_values unit. |
| 80 # The metric name must start with a letter or '_' and may contain |
| 81 # letters, digits, '-', '.', and '_'. |
| 82 _VALUES_RE = re.compile(r'^values ([^\d\W][\w.\-]*)?(.*) (\S+)$') |
| 83 |
77 def __init__(self): | 84 def __init__(self): |
78 super(_BlinkPerfMeasurement, self).__init__() | 85 super(_BlinkPerfMeasurement, self).__init__() |
79 with open(os.path.join(os.path.dirname(__file__), | 86 with open(os.path.join(os.path.dirname(__file__), |
80 'blink_perf.js'), 'r') as f: | 87 'blink_perf.js'), 'r') as f: |
81 self._blink_perf_js = f.read() | 88 self._blink_perf_js = f.read() |
82 | 89 |
83 def WillNavigateToPage(self, page, tab): | 90 def WillNavigateToPage(self, page, tab): |
84 del tab # unused | 91 del tab # unused |
85 page.script_to_evaluate_on_commit = self._blink_perf_js | 92 page.script_to_evaluate_on_commit = self._blink_perf_js |
86 | 93 |
87 def CustomizeBrowserOptions(self, options): | 94 def CustomizeBrowserOptions(self, options): |
88 options.AppendExtraBrowserArgs([ | 95 options.AppendExtraBrowserArgs([ |
89 '--js-flags=--expose_gc', | 96 '--js-flags=--expose_gc', |
90 '--enable-experimental-web-platform-features', | 97 '--enable-experimental-web-platform-features', |
91 '--disable-gesture-requirement-for-media-playback', | 98 '--disable-gesture-requirement-for-media-playback', |
92 '--enable-experimental-canvas-features', | 99 '--enable-experimental-canvas-features', |
93 # TODO(qinmin): After fixing crbug.com/592017, remove this command line. | 100 # TODO(qinmin): After fixing crbug.com/592017, remove this command line. |
94 '--reduce-security-for-testing' | 101 '--reduce-security-for-testing' |
95 ]) | 102 ]) |
96 if 'content-shell' in options.browser_type: | 103 if 'content-shell' in options.browser_type: |
97 options.AppendExtraBrowserArgs('--expose-internals-for-testing') | 104 options.AppendExtraBrowserArgs('--expose-internals-for-testing') |
98 | 105 |
99 def ValidateAndMeasurePage(self, page, tab, results): | 106 def ValidateAndMeasurePage(self, page, tab, results): |
100 tab.WaitForJavaScriptExpression('testRunner.isDone', 600) | 107 tab.WaitForJavaScriptExpression('testRunner.isDone', 600) |
101 | 108 |
102 log = tab.EvaluateJavaScript('document.getElementById("log").innerHTML') | 109 log = tab.EvaluateJavaScript('document.getElementById("log").innerHTML') |
103 | 110 |
| 111 unnamed_metric_count = 0 |
| 112 |
104 for line in log.splitlines(): | 113 for line in log.splitlines(): |
105 if line.startswith("FATAL: "): | 114 if line.startswith('FATAL: '): |
106 print line | 115 print line |
107 continue | 116 continue |
| 117 |
108 if not line.startswith('values '): | 118 if not line.startswith('values '): |
109 continue | 119 continue |
110 parts = line.split() | 120 |
111 values = [float(v.replace(',', '')) for v in parts[1:-1]] | 121 match = self._VALUES_RE.match(line) |
112 units = parts[-1] | 122 assert match, ('invalid log line with values: %s' % line) |
113 metric = page.display_name.split('.')[0].replace('/', '_') | 123 |
| 124 metric = match.group(1) |
| 125 if not metric: |
| 126 metric = page.display_name.split('.')[0].replace('/', '_') |
| 127 unnamed_metric_count += 1 |
| 128 assert unnamed_metric_count <= 1 |
| 129 values = [float(v.replace(',', '')) for v in match.group(2).split()] |
| 130 units = match.group(3) |
114 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 131 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
115 results.current_page, metric, units, values)) | 132 results.current_page, metric, units, values)) |
116 | 133 |
117 break | |
118 | |
119 print log | 134 print log |
120 | 135 |
121 | 136 |
122 class _SharedPywebsocketPageState(shared_page_state.SharedPageState): | 137 class _SharedPywebsocketPageState(shared_page_state.SharedPageState): |
123 """Runs a pywebsocket server.""" | 138 """Runs a pywebsocket server.""" |
124 | 139 |
125 def __init__(self, test, finder_options, user_story_set): | 140 def __init__(self, test, finder_options, user_story_set): |
126 super(_SharedPywebsocketPageState, self).__init__( | 141 super(_SharedPywebsocketPageState, self).__init__( |
127 test, finder_options, user_story_set) | 142 test, finder_options, user_story_set) |
128 self.platform.StartLocalServer(pywebsocket_server.PywebsocketServer()) | 143 self.platform.StartLocalServer(pywebsocket_server.PywebsocketServer()) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 348 |
334 def CreateStorySet(self, options): | 349 def CreateStorySet(self, options): |
335 path = os.path.join(BLINK_PERF_BASE_DIR, 'Pywebsocket') | 350 path = os.path.join(BLINK_PERF_BASE_DIR, 'Pywebsocket') |
336 return CreateStorySetFromPath( | 351 return CreateStorySetFromPath( |
337 path, SKIPPED_FILE, | 352 path, SKIPPED_FILE, |
338 shared_page_state_class=_SharedPywebsocketPageState) | 353 shared_page_state_class=_SharedPywebsocketPageState) |
339 | 354 |
340 @classmethod | 355 @classmethod |
341 def ShouldDisable(cls, possible_browser): | 356 def ShouldDisable(cls, possible_browser): |
342 return cls.IsSvelte(possible_browser) # http://crbug.com/551950 | 357 return cls.IsSvelte(possible_browser) # http://crbug.com/551950 |
| 358 |
| 359 |
| 360 class BlinkHTMLToDOM(perf_benchmark.PerfBenchmark): |
| 361 tag = 'html_to_dom' |
| 362 test = _BlinkPerfMeasurement |
| 363 |
| 364 @classmethod |
| 365 def Name(cls): |
| 366 return 'blink_perf.html_to_dom' |
| 367 |
| 368 def CreateStorySet(self, options): |
| 369 path = os.path.join(BLINK_PERF_BASE_DIR, 'HTMLToDOM') |
| 370 return CreateStorySetFromPath(path, SKIPPED_FILE) |
OLD | NEW |