| 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 | 4 |
| 5 """The page cycler measurement. | 5 """The page cycler measurement. |
| 6 | 6 |
| 7 This measurement registers a window load handler in which is forces a layout and | 7 This measurement registers a window load handler in which is forces a layout and |
| 8 then records the value of performance.now(). This call to now() measures the | 8 then records the value of performance.now(). This call to now() measures the |
| 9 time from navigationStart (immediately after the previous page's beforeunload | 9 time from navigationStart (immediately after the previous page's beforeunload |
| 10 event) until after the layout in the page's load event. In addition, two garbage | 10 event) until after the layout in the page's load event. In addition, two garbage |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 with open(os.path.join(os.path.dirname(__file__), | 34 with open(os.path.join(os.path.dirname(__file__), |
| 35 'page_cycler.js'), 'r') as f: | 35 'page_cycler.js'), 'r') as f: |
| 36 self._page_cycler_js = f.read() | 36 self._page_cycler_js = f.read() |
| 37 | 37 |
| 38 self._record_v8_object_stats = False | 38 self._record_v8_object_stats = False |
| 39 self._report_speed_index = False | 39 self._report_speed_index = False |
| 40 self._speedindex_metric = speedindex.SpeedIndexMetric() | 40 self._speedindex_metric = speedindex.SpeedIndexMetric() |
| 41 self._memory_metric = None | 41 self._memory_metric = None |
| 42 self._cpu_metric = None | 42 self._cpu_metric = None |
| 43 self._v8_object_stats_metric = None | 43 self._v8_object_stats_metric = None |
| 44 self._number_warm_runs = None | |
| 45 self._cold_runs_requested = False | |
| 46 self._cold_run_start_index = None | 44 self._cold_run_start_index = None |
| 47 self._has_loaded_page = collections.defaultdict(int) | 45 self._has_loaded_page = collections.defaultdict(int) |
| 48 | 46 |
| 49 def AddCommandLineOptions(self, parser): | 47 def AddCommandLineOptions(self, parser): |
| 50 # The page cyclers should default to 10 iterations. In order to change the | 48 # The page cyclers should default to 10 iterations. In order to change the |
| 51 # default of an option, we must remove and re-add it. | 49 # default of an option, we must remove and re-add it. |
| 52 # TODO: Remove this after transition to run_benchmark. | 50 # TODO: Remove this after transition to run_benchmark. |
| 53 pageset_repeat_option = parser.get_option('--pageset-repeat') | 51 pageset_repeat_option = parser.get_option('--pageset-repeat') |
| 54 pageset_repeat_option.default = 10 | 52 pageset_repeat_option.default = 10 |
| 55 parser.remove_option('--pageset-repeat') | 53 parser.remove_option('--pageset-repeat') |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 107 |
| 110 # A disk cache bug causes some page cyclers to hang on mac. | 108 # A disk cache bug causes some page cyclers to hang on mac. |
| 111 # TODO(tonyg): Re-enable these tests when crbug.com/268646 is fixed. | 109 # TODO(tonyg): Re-enable these tests when crbug.com/268646 is fixed. |
| 112 if (sys.platform == 'darwin' and | 110 if (sys.platform == 'darwin' and |
| 113 (sys.argv[-1].endswith('/intl_hi_ru.json') or | 111 (sys.argv[-1].endswith('/intl_hi_ru.json') or |
| 114 sys.argv[-1].endswith('/tough_layout_cases.json') or | 112 sys.argv[-1].endswith('/tough_layout_cases.json') or |
| 115 sys.argv[-1].endswith('/typical_25.json'))): | 113 sys.argv[-1].endswith('/typical_25.json'))): |
| 116 print '%s is currently disabled on mac. Skipping test.' % sys.argv[-1] | 114 print '%s is currently disabled on mac. Skipping test.' % sys.argv[-1] |
| 117 sys.exit(0) | 115 sys.exit(0) |
| 118 | 116 |
| 119 self._cold_runs_requested = (options.cold_load_percent != None) | 117 cold_runs_percent_set = (options.cold_load_percent != None) |
| 120 # Handle requests for cold cache runs | 118 # Handle requests for cold cache runs |
| 121 if (self._cold_runs_requested and | 119 if (cold_runs_percent_set and |
| 122 (options.repeat_options.page_repeat_secs or | 120 (options.repeat_options.page_repeat_secs or |
| 123 options.repeat_options.pageset_repeat_secs)): | 121 options.repeat_options.pageset_repeat_secs)): |
| 124 raise Exception('--cold-load-percent is incompatible with timed repeat') | 122 raise Exception('--cold-load-percent is incompatible with timed repeat') |
| 125 | 123 |
| 126 if (self._cold_runs_requested and | 124 if (cold_runs_percent_set and |
| 127 (options.cold_load_percent < 0 or options.cold_load_percent > 100)): | 125 (options.cold_load_percent < 0 or options.cold_load_percent > 100)): |
| 128 raise Exception('--cold-load-percent must be in the range [0-100]') | 126 raise Exception('--cold-load-percent must be in the range [0-100]') |
| 129 | 127 |
| 130 # TODO(rdsmith): Properly handle interaction of page_repeat with | 128 # Make sure _cold_run_start_index is an integer multiple of page_repeat. |
| 131 # dropping the first run. | |
| 132 number_warm_pageset_runs = int( | |
| 133 (int(options.repeat_options.pageset_repeat_iters) - 1) * | |
| 134 (100 - int(options.cold_load_percent or 0)) / 100) | |
| 135 | |
| 136 # Make sure _number_cold_runs is an integer multiple of page_repeat. | |
| 137 # Without this, --pageset_shuffle + --page_repeat could lead to | 129 # Without this, --pageset_shuffle + --page_repeat could lead to |
| 138 # assertion failures on _started_warm in WillNavigateToPage. | 130 # assertion failures on _started_warm in WillNavigateToPage. |
| 139 self._number_warm_runs = (number_warm_pageset_runs * | 131 if cold_runs_percent_set: |
| 140 options.repeat_options.page_repeat_iters) | 132 number_warm_pageset_runs = int( |
| 141 self._cold_run_start_index = (self._number_warm_runs + | 133 (int(options.repeat_options.pageset_repeat_iters) - 1) * |
| 142 options.repeat_options.page_repeat_iters) | 134 (100 - options.cold_load_percent) / 100) |
| 143 self.discard_first_result = ((self._cold_runs_requested and | 135 number_warm_runs = (number_warm_pageset_runs * |
| 144 not options.cold_load_percent) or | 136 options.repeat_options.page_repeat_iters) |
| 145 self.discard_first_result) | 137 self._cold_run_start_index = (number_warm_runs + |
| 138 options.repeat_options.page_repeat_iters) |
| 139 self.discard_first_result = (not options.cold_load_percent or |
| 140 self.discard_first_result) |
| 141 else: |
| 142 self._cold_run_start_index = ( |
| 143 options.repeat_options.pageset_repeat_iters * |
| 144 options.repeat_options.page_repeat_iters) |
| 146 | 145 |
| 147 def MeasurePage(self, page, tab, results): | 146 def MeasurePage(self, page, tab, results): |
| 148 tab.WaitForJavaScriptExpression('__pc_load_time', 60) | 147 tab.WaitForJavaScriptExpression('__pc_load_time', 60) |
| 149 | 148 |
| 150 chart_name_prefix = ('' if not self._cold_runs_requested else | 149 chart_name_prefix = ('cold_' if self.IsRunCold(page.url) else |
| 151 'cold_' if self.IsRunCold(page.url) else | |
| 152 'warm_') | 150 'warm_') |
| 153 | 151 |
| 154 results.Add('page_load_time', 'ms', | 152 results.Add('page_load_time', 'ms', |
| 155 int(float(tab.EvaluateJavaScript('__pc_load_time'))), | 153 int(float(tab.EvaluateJavaScript('__pc_load_time'))), |
| 156 chart_name=chart_name_prefix+'times') | 154 chart_name=chart_name_prefix+'times') |
| 157 | 155 |
| 158 self._has_loaded_page[page.url] += 1 | 156 self._has_loaded_page[page.url] += 1 |
| 159 | 157 |
| 160 self._memory_metric.Stop(page, tab) | 158 self._memory_metric.Stop(page, tab) |
| 161 self._memory_metric.AddResults(tab, results) | 159 self._memory_metric.AddResults(tab, results) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 self._speedindex_metric.Stop(page, tab) | 172 self._speedindex_metric.Stop(page, tab) |
| 175 self._speedindex_metric.AddResults( | 173 self._speedindex_metric.AddResults( |
| 176 tab, results, chart_name=chart_name_prefix+'speed_index') | 174 tab, results, chart_name=chart_name_prefix+'speed_index') |
| 177 | 175 |
| 178 def DidRunTest(self, browser, results): | 176 def DidRunTest(self, browser, results): |
| 179 self._memory_metric.AddSummaryResults(results) | 177 self._memory_metric.AddSummaryResults(results) |
| 180 io.IOMetric().AddSummaryResults(browser, results) | 178 io.IOMetric().AddSummaryResults(browser, results) |
| 181 | 179 |
| 182 def IsRunCold(self, url): | 180 def IsRunCold(self, url): |
| 183 return (self.ShouldRunCold(url) or | 181 return (self.ShouldRunCold(url) or |
| 184 (self._cold_runs_requested and | 182 self._has_loaded_page[url] == 0) |
| 185 self._has_loaded_page[url] == 0)) | |
| 186 | 183 |
| 187 def ShouldRunCold(self, url): | 184 def ShouldRunCold(self, url): |
| 188 # We do the warm runs first for two reasons. The first is so we can | 185 # We do the warm runs first for two reasons. The first is so we can |
| 189 # preserve any initial profile cache for as long as possible. | 186 # preserve any initial profile cache for as long as possible. |
| 190 # The second is that, if we did cold runs first, we'd have a transition | 187 # The second is that, if we did cold runs first, we'd have a transition |
| 191 # page set during which we wanted the run for each URL to both | 188 # page set during which we wanted the run for each URL to both |
| 192 # contribute to the cold data and warm the catch for the following | 189 # contribute to the cold data and warm the catch for the following |
| 193 # warm run, and clearing the cache before the load of the following | 190 # warm run, and clearing the cache before the load of the following |
| 194 # URL would eliminate the intended warmup for the previous URL. | 191 # URL would eliminate the intended warmup for the previous URL. |
| 195 return (self._cold_runs_requested and | 192 return (self._has_loaded_page[url] >= self._cold_run_start_index) |
| 196 self._has_loaded_page[url] >= self._cold_run_start_index) | |
| 197 | 193 |
| 198 def results_are_the_same_on_every_page(self): | 194 def results_are_the_same_on_every_page(self): |
| 199 return not self._cold_runs_requested | 195 return False |
| OLD | NEW |