| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import os | |
| 5 | |
| 6 from telemetry import multi_page_benchmark | 4 from telemetry import multi_page_benchmark |
| 7 from telemetry import util | |
| 8 | |
| 9 class DidNotScrollException(multi_page_benchmark.MeasurementFailure): | |
| 10 def __init__(self): | |
| 11 super(DidNotScrollException, self).__init__('Page did not scroll') | |
| 12 | 5 |
| 13 def GetOrZero(stat, rendering_stats_deltas): | 6 def GetOrZero(stat, rendering_stats_deltas): |
| 14 if stat in rendering_stats_deltas: | 7 if stat in rendering_stats_deltas: |
| 15 return rendering_stats_deltas[stat] | 8 return rendering_stats_deltas[stat] |
| 16 return 0 | 9 return 0 |
| 17 | 10 |
| 18 def DivideIfPossibleOrZero(numerator, denominator): | 11 def DivideIfPossibleOrZero(numerator, denominator): |
| 19 if denominator == 0: | 12 if denominator == 0: |
| 20 return 0 | 13 return 0 |
| 21 return numerator / denominator | 14 return numerator / denominator |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 results.Add('total_pixels_painted', '', totalPixelsPainted) | 52 results.Add('total_pixels_painted', '', totalPixelsPainted) |
| 60 results.Add('total_pixels_rasterized', '', totalPixelsRasterized) | 53 results.Add('total_pixels_rasterized', '', totalPixelsRasterized) |
| 61 results.Add('megapixels_painted_per_second', '', megapixelsPaintedPerSecond) | 54 results.Add('megapixels_painted_per_second', '', megapixelsPaintedPerSecond) |
| 62 results.Add('megapixels_rasterized_per_second', '', | 55 results.Add('megapixels_rasterized_per_second', '', |
| 63 megapixelsRasterizedPerSecond) | 56 megapixelsRasterizedPerSecond) |
| 64 results.Add('total_paint_and_rasterize_time', 'seconds', totalPaintTime + | 57 results.Add('total_paint_and_rasterize_time', 'seconds', totalPaintTime + |
| 65 totalRasterizeTime) | 58 totalRasterizeTime) |
| 66 | 59 |
| 67 class ScrollingBenchmark(multi_page_benchmark.MultiPageBenchmark): | 60 class ScrollingBenchmark(multi_page_benchmark.MultiPageBenchmark): |
| 68 def __init__(self): | 61 def __init__(self): |
| 69 super(ScrollingBenchmark, self).__init__() | 62 super(ScrollingBenchmark, self).__init__('scrolling') |
| 70 | 63 |
| 71 def AddCommandLineOptions(self, parser): | 64 def AddCommandLineOptions(self, parser): |
| 72 parser.add_option('--no-gpu-benchmarking-extension', action='store_true', | 65 parser.add_option('--no-gpu-benchmarking-extension', action='store_true', |
| 73 dest='no_gpu_benchmarking_extension', | 66 dest='no_gpu_benchmarking_extension', |
| 74 help='Disable the chrome.gpuBenchmarking extension.') | 67 help='Disable the chrome.gpuBenchmarking extension.') |
| 75 parser.add_option('--report-all-results', dest='report_all_results', | 68 parser.add_option('--report-all-results', dest='report_all_results', |
| 76 action='store_true', | 69 action='store_true', |
| 77 help='Reports all data collected, not just FPS') | 70 help='Reports all data collected, not just FPS') |
| 78 | 71 |
| 79 @staticmethod | |
| 80 def ScrollPageFully(page, tab): | |
| 81 scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js') | |
| 82 scroll_js = open(scroll_js_path, 'r').read() | |
| 83 | |
| 84 # Run scroll test. | |
| 85 tab.runtime.Execute(scroll_js) | |
| 86 | |
| 87 with tab.browser.platform.GetSurfaceCollector(''): | |
| 88 | |
| 89 start_scroll_js = """ | |
| 90 window.__renderingStatsDeltas = null; | |
| 91 new __ScrollTest(function(rendering_stats_deltas) { | |
| 92 window.__renderingStatsDeltas = rendering_stats_deltas; | |
| 93 }).start(element); | |
| 94 """ | |
| 95 # scrollable_element_function is a function that passes the scrollable | |
| 96 # element on the page to a callback. For example: | |
| 97 # function (callback) { | |
| 98 # callback(document.getElementById('foo')); | |
| 99 # } | |
| 100 if hasattr(page, 'scrollable_element_function'): | |
| 101 tab.runtime.Execute('(%s)(function(element) { %s });' % | |
| 102 (page.scrollable_element_function, start_scroll_js)) | |
| 103 else: | |
| 104 tab.runtime.Execute( | |
| 105 '(function() { var element = document.body; %s})();' % | |
| 106 start_scroll_js) | |
| 107 | |
| 108 # Poll for scroll benchmark completion. | |
| 109 util.WaitFor(lambda: tab.runtime.Evaluate( | |
| 110 'window.__renderingStatsDeltas'), 60) | |
| 111 | |
| 112 rendering_stats_deltas = tab.runtime.Evaluate( | |
| 113 'window.__renderingStatsDeltas') | |
| 114 | |
| 115 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): | |
| 116 raise DidNotScrollException() | |
| 117 return rendering_stats_deltas | |
| 118 | |
| 119 def CustomizeBrowserOptions(self, options): | 72 def CustomizeBrowserOptions(self, options): |
| 120 if not options.no_gpu_benchmarking_extension: | 73 if not options.no_gpu_benchmarking_extension: |
| 121 options.extra_browser_args.append('--enable-gpu-benchmarking') | 74 options.extra_browser_args.append('--enable-gpu-benchmarking') |
| 122 | 75 |
| 76 def CanRunForPage(self, page): |
| 77 return hasattr(page, 'scrolling') |
| 78 |
| 123 def MeasurePage(self, page, tab, results): | 79 def MeasurePage(self, page, tab, results): |
| 124 rendering_stats_deltas = self.ScrollPageFully(page, tab) | 80 rendering_stats_deltas = page.scroll_results |
| 125 CalcScrollResults(rendering_stats_deltas, results) | 81 CalcScrollResults(rendering_stats_deltas, results) |
| 126 if self.options.report_all_results: | 82 if self.options.report_all_results: |
| 127 for k, v in rendering_stats_deltas.iteritems(): | 83 for k, v in rendering_stats_deltas.iteritems(): |
| 128 results.Add(k, '', v) | 84 results.Add(k, '', v) |
| OLD | NEW |