| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 itertools import starmap | 5 from itertools import starmap |
| 6 from collections import defaultdict | 6 from collections import defaultdict |
| 7 | |
| 8 from telemetry.core import util | 7 from telemetry.core import util |
| 8 from telemetry.core import exceptions |
| 9 from telemetry.page import page_test | 9 from telemetry.page import page_test |
| 10 from telemetry.value import scalar | 10 from telemetry.value import scalar |
| 11 | 11 |
| 12 from measurements import timeline_controller | 12 from measurements import timeline_controller |
| 13 | 13 |
| 14 | 14 |
| 15 class BlinkStyle(page_test.PageTest): | 15 class BlinkStyle(page_test.PageTest): |
| 16 def __init__(self): | 16 def __init__(self): |
| 17 super(BlinkStyle, self).__init__() | 17 super(BlinkStyle, self).__init__() |
| 18 self._controller = None | 18 self._controller = None |
| 19 | 19 |
| 20 def WillNavigateToPage(self, page, tab): | 20 def WillNavigateToPage(self, page, tab): |
| 21 self._controller = timeline_controller.TimelineController() | 21 self._controller = timeline_controller.TimelineController() |
| 22 self._controller.trace_categories = 'blink,benchmark,blink.console' | 22 self._controller.trace_categories = 'blink_style,blink.console' |
| 23 self._controller.SetUp(page, tab) | 23 self._controller.SetUp(page, tab) |
| 24 self._controller.Start(tab) | 24 self._controller.Start(tab) |
| 25 | 25 |
| 26 def CleanUpAfterPage(self, page, tab): | 26 def CleanUpAfterPage(self, page, tab): |
| 27 if self._controller: | 27 if self._controller: |
| 28 self._controller.CleanUp(tab) | 28 self._controller.CleanUp(tab) |
| 29 | 29 |
| 30 def ValidateAndMeasurePage(self, page, tab, results): | 30 def ValidateAndMeasurePage(self, page, tab, results): |
| 31 tab.WaitForDocumentReadyStateToBeComplete() | 31 tab.ExecuteJavaScript('console.time("wait-for-quiescence");') |
| 32 if not util.WaitFor(tab.HasReachedQuiescence, 30): | 32 try: |
| 33 raise page_test.MeasurementFailure('Failed to reach quiesence.') | 33 util.WaitFor(tab.HasReachedQuiescence, 15) |
| 34 except exceptions.TimeoutException: |
| 35 # Some sites never reach quiesence. As this benchmark normalizes/ |
| 36 # categories results, it shouldn't be necessary to reach the same |
| 37 # state on every run. |
| 38 pass |
| 39 tab.ExecuteJavaScript('console.timeEnd("wait-for-quiescence");') |
| 34 | 40 |
| 35 tab.ExecuteJavaScript( | 41 tab.ExecuteJavaScript( |
| 36 'console.time("style-update");' | 42 'console.time("style-update");' |
| 37 # Occasionally documents will break the APIs we need. | 43 # Occasionally documents will break the APIs we need. |
| 38 'try {' | 44 'try {' |
| 39 # Invalidate style for the whole document. | 45 # Invalidate style for the whole document. |
| 40 ' document && (document.documentElement.lang += "z");' | 46 ' document && (document.documentElement.lang += "z");' |
| 41 # Force a style update (but not layout). | 47 # Force a style update (but not layout). |
| 42 ' getComputedStyle(document.documentElement).color;' | 48 ' getComputedStyle(document.documentElement).color;' |
| 43 '} catch (e) {}' | 49 '} catch (e) {}' |
| (...skipping 11 matching lines...) Expand all Loading... |
| 55 def duration(event): | 61 def duration(event): |
| 56 if event.has_thread_timestamps: | 62 if event.has_thread_timestamps: |
| 57 return event.thread_duration | 63 return event.thread_duration |
| 58 else: | 64 else: |
| 59 return event.duration | 65 return event.duration |
| 60 | 66 |
| 61 for event in renderer.all_slices: | 67 for event in renderer.all_slices: |
| 62 if (event.name == 'Document::updateStyle' | 68 if (event.name == 'Document::updateStyle' |
| 63 and event.start >= marker.start | 69 and event.start >= marker.start |
| 64 and event.end <= marker.end): | 70 and event.end <= marker.end): |
| 65 access_count = event.args['resolverAccessCount'] | 71 access_count = event.get('resolverAccessCount') |
| 72 if access_count is None: |
| 73 # absent in earlier versions |
| 74 continue |
| 66 min_access_count = 50 | 75 min_access_count = 50 |
| 67 | 76 |
| 68 if access_count >= min_access_count: | 77 if access_count >= min_access_count: |
| 69 result = 1000 * (duration(event) / access_count) | 78 result = 1000 * (duration(event) / access_count) |
| 70 results.AddValue(scalar.ScalarValue( | 79 results.AddValue(scalar.ScalarValue( |
| 71 page, 'update_style', 'ms/1000 elements', result)) | 80 page, 'update_style', 'ms/1000 elements', result)) |
| 72 | 81 |
| 73 class ParserEvent(object): | 82 class ParserEvent(object): |
| 74 def __init__(self, summary_event, tokenize_event, parse_event): | 83 def __init__(self, summary_event, tokenize_event, parse_event): |
| 75 min_sheet_length = 1000 | 84 min_sheet_length = 1000 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 tokens = sum(event.tokens for event in events) | 121 tokens = sum(event.tokens for event in events) |
| 113 length = sum(event.length for event in events) | 122 length = sum(event.length for event in events) |
| 114 | 123 |
| 115 results.AddValue( | 124 results.AddValue( |
| 116 scalar.ScalarValue(page, ('parse_css_%s' % category), | 125 scalar.ScalarValue(page, ('parse_css_%s' % category), |
| 117 'tokens/s', 1000 / (parse_duration / tokens))) | 126 'tokens/s', 1000 / (parse_duration / tokens))) |
| 118 | 127 |
| 119 results.AddValue( | 128 results.AddValue( |
| 120 scalar.ScalarValue(page, ('tokenize_css_%s' % category), | 129 scalar.ScalarValue(page, ('tokenize_css_%s' % category), |
| 121 'char/s', 1000 / (tokenize_duration / length))) | 130 'char/s', 1000 / (tokenize_duration / length))) |
| OLD | NEW |