| 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 |
| 11 collections are performed in between the page loads (in the beforeunload event). | 11 collections are performed in between the page loads (in the beforeunload event). |
| 12 This extra garbage collection time is not included in the measurement times. | 12 This extra garbage collection time is not included in the measurement times. |
| 13 | 13 |
| 14 Finally, various memory and IO statistics are gathered at the very end of | 14 Finally, various memory and IO statistics are gathered at the very end of |
| 15 cycling all pages. | 15 cycling all pages. |
| 16 """ | 16 """ |
| 17 | 17 |
| 18 import collections | 18 import collections |
| 19 import os | 19 import os |
| 20 | 20 |
| 21 from measurements.decorators import Power |
| 21 from metrics import cpu | 22 from metrics import cpu |
| 22 from metrics import iometric | 23 from metrics import iometric |
| 23 from metrics import memory | 24 from metrics import memory |
| 24 from metrics import power | |
| 25 from metrics import speedindex | 25 from metrics import speedindex |
| 26 from metrics import v8_object_stats | 26 from metrics import v8_object_stats |
| 27 from telemetry.core import util | 27 from telemetry.core import util |
| 28 from telemetry.page import page_measurement | 28 from telemetry.page import page_measurement |
| 29 | 29 |
| 30 @Power |
| 30 class PageCycler(page_measurement.PageMeasurement): | 31 class PageCycler(page_measurement.PageMeasurement): |
| 31 options = {'pageset_repeat': 10} | 32 options = {'pageset_repeat': 10} |
| 32 | 33 |
| 33 def __init__(self, *args, **kwargs): | 34 def __init__(self, *args, **kwargs): |
| 34 super(PageCycler, self).__init__(*args, **kwargs) | 35 super(PageCycler, self).__init__(*args, **kwargs) |
| 35 | 36 |
| 36 with open(os.path.join(os.path.dirname(__file__), | 37 with open(os.path.join(os.path.dirname(__file__), |
| 37 'page_cycler.js'), 'r') as f: | 38 'page_cycler.js'), 'r') as f: |
| 38 self._page_cycler_js = f.read() | 39 self._page_cycler_js = f.read() |
| 39 | 40 |
| 40 self._speedindex_metric = speedindex.SpeedIndexMetric() | 41 self._speedindex_metric = speedindex.SpeedIndexMetric() |
| 41 self._memory_metric = None | 42 self._memory_metric = None |
| 42 self._power_metric = power.PowerMetric() | |
| 43 self._cpu_metric = None | 43 self._cpu_metric = None |
| 44 self._v8_object_stats_metric = None | 44 self._v8_object_stats_metric = None |
| 45 self._cold_run_start_index = None | 45 self._cold_run_start_index = None |
| 46 self._has_loaded_page = collections.defaultdict(int) | 46 self._has_loaded_page = collections.defaultdict(int) |
| 47 | 47 |
| 48 @classmethod | 48 @classmethod |
| 49 def AddCommandLineArgs(cls, parser): | 49 def AddCommandLineArgs(cls, parser): |
| 50 parser.add_option('--v8-object-stats', | 50 parser.add_option('--v8-object-stats', |
| 51 action='store_true', | 51 action='store_true', |
| 52 help='Enable detailed V8 object statistics.') | 52 help='Enable detailed V8 object statistics.') |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 | 77 |
| 78 def WillNavigateToPage(self, page, tab): | 78 def WillNavigateToPage(self, page, tab): |
| 79 page.script_to_evaluate_on_commit = self._page_cycler_js | 79 page.script_to_evaluate_on_commit = self._page_cycler_js |
| 80 if self.ShouldRunCold(page.url): | 80 if self.ShouldRunCold(page.url): |
| 81 tab.ClearCache(force=True) | 81 tab.ClearCache(force=True) |
| 82 if self._report_speed_index: | 82 if self._report_speed_index: |
| 83 self._speedindex_metric.Start(page, tab) | 83 self._speedindex_metric.Start(page, tab) |
| 84 | 84 |
| 85 def DidNavigateToPage(self, page, tab): | 85 def DidNavigateToPage(self, page, tab): |
| 86 self._memory_metric.Start(page, tab) | 86 self._memory_metric.Start(page, tab) |
| 87 self._power_metric.Start(page, tab) | |
| 88 # TODO(qyearsley): Uncomment the following line and move it to | 87 # TODO(qyearsley): Uncomment the following line and move it to |
| 89 # WillNavigateToPage once the cpu metric has been changed. | 88 # WillNavigateToPage once the cpu metric has been changed. |
| 90 # This is being temporarily commented out to let the page cycler | 89 # This is being temporarily commented out to let the page cycler |
| 91 # results return to how they were before the cpu metric was added. | 90 # results return to how they were before the cpu metric was added. |
| 92 # self._cpu_metric.Start(page, tab) See crbug.com/301714. | 91 # self._cpu_metric.Start(page, tab) See crbug.com/301714. |
| 93 if self._record_v8_object_stats: | 92 if self._record_v8_object_stats: |
| 94 self._v8_object_stats_metric.Start(page, tab) | 93 self._v8_object_stats_metric.Start(page, tab) |
| 95 | 94 |
| 96 def CustomizeBrowserOptions(self, options): | 95 def CustomizeBrowserOptions(self, options): |
| 97 memory.MemoryMetric.CustomizeBrowserOptions(options) | 96 memory.MemoryMetric.CustomizeBrowserOptions(options) |
| 98 power.PowerMetric.CustomizeBrowserOptions(options) | |
| 99 iometric.IOMetric.CustomizeBrowserOptions(options) | 97 iometric.IOMetric.CustomizeBrowserOptions(options) |
| 100 options.AppendExtraBrowserArgs('--js-flags=--expose_gc') | 98 options.AppendExtraBrowserArgs('--js-flags=--expose_gc') |
| 101 | 99 |
| 102 if self._record_v8_object_stats: | 100 if self._record_v8_object_stats: |
| 103 v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options) | 101 v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options) |
| 104 if self._report_speed_index: | 102 if self._report_speed_index: |
| 105 self._speedindex_metric.CustomizeBrowserOptions(options) | 103 self._speedindex_metric.CustomizeBrowserOptions(options) |
| 106 | 104 |
| 107 # TODO: Move the rest of this method to ProcessCommandLineArgs. | 105 # TODO: Move the rest of this method to ProcessCommandLineArgs. |
| 108 cold_runs_percent_set = (options.cold_load_percent != None) | 106 cold_runs_percent_set = (options.cold_load_percent != None) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 122 options.repeat_options.page_repeat) | 120 options.repeat_options.page_repeat) |
| 123 self._cold_run_start_index = (number_warm_runs + | 121 self._cold_run_start_index = (number_warm_runs + |
| 124 options.repeat_options.page_repeat) | 122 options.repeat_options.page_repeat) |
| 125 self.discard_first_result = (not options.cold_load_percent or | 123 self.discard_first_result = (not options.cold_load_percent or |
| 126 self.discard_first_result) | 124 self.discard_first_result) |
| 127 else: | 125 else: |
| 128 self._cold_run_start_index = ( | 126 self._cold_run_start_index = ( |
| 129 options.repeat_options.pageset_repeat * | 127 options.repeat_options.pageset_repeat * |
| 130 options.repeat_options.page_repeat) | 128 options.repeat_options.page_repeat) |
| 131 | 129 |
| 132 def MeasurePage(self, page, tab, results): | 130 def WillMeasurePage(self, page, tab): |
| 133 tab.WaitForJavaScriptExpression('__pc_load_time', 60) | 131 tab.WaitForJavaScriptExpression('__pc_load_time', 60) |
| 134 | 132 |
| 133 def MeasurePage(self, page, tab, results): |
| 135 chart_name_prefix = ('cold_' if self.IsRunCold(page.url) else | 134 chart_name_prefix = ('cold_' if self.IsRunCold(page.url) else |
| 136 'warm_') | 135 'warm_') |
| 137 | 136 |
| 138 results.Add('page_load_time', 'ms', | 137 results.Add('page_load_time', 'ms', |
| 139 int(float(tab.EvaluateJavaScript('__pc_load_time'))), | 138 int(float(tab.EvaluateJavaScript('__pc_load_time'))), |
| 140 chart_name=chart_name_prefix+'times') | 139 chart_name=chart_name_prefix+'times') |
| 141 | 140 |
| 142 self._has_loaded_page[page.url] += 1 | 141 self._has_loaded_page[page.url] += 1 |
| 143 | 142 |
| 144 self._power_metric.Stop(page, tab) | |
| 145 self._memory_metric.Stop(page, tab) | 143 self._memory_metric.Stop(page, tab) |
| 146 self._memory_metric.AddResults(tab, results) | 144 self._memory_metric.AddResults(tab, results) |
| 147 self._power_metric.AddResults(tab, results) | |
| 148 | 145 |
| 149 # TODO(qyearsley): Uncomment the following line when CPU metric is | 146 # TODO(qyearsley): Uncomment the following line when CPU metric is |
| 150 # changed. See crbug.com/301714. | 147 # changed. See crbug.com/301714. |
| 151 # self._cpu_metric.Stop(page, tab) | 148 # self._cpu_metric.Stop(page, tab) |
| 152 # self._cpu_metric.AddResults(tab, results) | 149 # self._cpu_metric.AddResults(tab, results) |
| 153 if self._record_v8_object_stats: | 150 if self._record_v8_object_stats: |
| 154 self._v8_object_stats_metric.Stop(page, tab) | 151 self._v8_object_stats_metric.Stop(page, tab) |
| 155 self._v8_object_stats_metric.AddResults(tab, results) | 152 self._v8_object_stats_metric.AddResults(tab, results) |
| 156 | 153 |
| 157 if self._report_speed_index: | 154 if self._report_speed_index: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 174 # preserve any initial profile cache for as long as possible. | 171 # preserve any initial profile cache for as long as possible. |
| 175 # The second is that, if we did cold runs first, we'd have a transition | 172 # The second is that, if we did cold runs first, we'd have a transition |
| 176 # page set during which we wanted the run for each URL to both | 173 # page set during which we wanted the run for each URL to both |
| 177 # contribute to the cold data and warm the catch for the following | 174 # contribute to the cold data and warm the catch for the following |
| 178 # warm run, and clearing the cache before the load of the following | 175 # warm run, and clearing the cache before the load of the following |
| 179 # URL would eliminate the intended warmup for the previous URL. | 176 # URL would eliminate the intended warmup for the previous URL. |
| 180 return (self._has_loaded_page[url] >= self._cold_run_start_index) | 177 return (self._has_loaded_page[url] >= self._cold_run_start_index) |
| 181 | 178 |
| 182 def results_are_the_same_on_every_page(self): | 179 def results_are_the_same_on_every_page(self): |
| 183 return False | 180 return False |
| OLD | NEW |