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 import sys | 20 import sys |
21 | 21 |
22 from metrics import io | 22 from metrics import io |
23 from metrics import memory | 23 from metrics import memory |
| 24 from metrics import v8_object_stats |
24 from telemetry.core import util | 25 from telemetry.core import util |
25 from telemetry.page import page_measurement | 26 from telemetry.page import page_measurement |
26 | 27 |
27 class PageCycler(page_measurement.PageMeasurement): | 28 class PageCycler(page_measurement.PageMeasurement): |
28 def __init__(self, *args, **kwargs): | 29 def __init__(self, *args, **kwargs): |
29 super(PageCycler, self).__init__(*args, **kwargs) | 30 super(PageCycler, self).__init__(*args, **kwargs) |
30 | 31 |
31 with open(os.path.join(os.path.dirname(__file__), | 32 with open(os.path.join(os.path.dirname(__file__), |
32 'page_cycler.js'), 'r') as f: | 33 'page_cycler.js'), 'r') as f: |
33 self._page_cycler_js = f.read() | 34 self._page_cycler_js = f.read() |
34 | 35 |
| 36 self._record_v8_object_stats = False |
| 37 |
35 self._memory_metric = None | 38 self._memory_metric = None |
| 39 self._v8_object_stats_metric = None |
36 self._number_warm_runs = None | 40 self._number_warm_runs = None |
37 self._cold_runs_requested = False | 41 self._cold_runs_requested = False |
38 self._has_loaded_page = collections.defaultdict(int) | 42 self._has_loaded_page = collections.defaultdict(int) |
39 | 43 |
40 def AddCommandLineOptions(self, parser): | 44 def AddCommandLineOptions(self, parser): |
41 # The page cyclers should default to 10 iterations. In order to change the | 45 # The page cyclers should default to 10 iterations. In order to change the |
42 # default of an option, we must remove and re-add it. | 46 # default of an option, we must remove and re-add it. |
43 # TODO: Remove this after transition to run_benchmark. | 47 # TODO: Remove this after transition to run_benchmark. |
44 pageset_repeat_option = parser.get_option('--pageset-repeat') | 48 pageset_repeat_option = parser.get_option('--pageset-repeat') |
45 pageset_repeat_option.default = 10 | 49 pageset_repeat_option.default = 10 |
46 parser.remove_option('--pageset-repeat') | 50 parser.remove_option('--pageset-repeat') |
47 parser.add_option(pageset_repeat_option) | 51 parser.add_option(pageset_repeat_option) |
48 | 52 |
| 53 parser.add_option('--v8-object-stats', |
| 54 action='store_true', |
| 55 help='Enable detailed V8 object statistics.') |
| 56 |
49 parser.add_option('--cold-load-percent', type='int', default=0, | 57 parser.add_option('--cold-load-percent', type='int', default=0, |
50 help='%d of page visits for which a cold load is forced') | 58 help='%d of page visits for which a cold load is forced') |
51 | 59 |
| 60 |
52 def DidStartBrowser(self, browser): | 61 def DidStartBrowser(self, browser): |
53 """Initialize metrics once right after the browser has been launched.""" | 62 """Initialize metrics once right after the browser has been launched.""" |
54 self._memory_metric = memory.MemoryMetric(browser) | 63 self._memory_metric = memory.MemoryMetric(browser) |
| 64 if self._record_v8_object_stats: |
| 65 self._v8_object_stats_metric = v8_object_stats.V8ObjectStatsMetric() |
55 | 66 |
56 def DidStartHTTPServer(self, tab): | 67 def DidStartHTTPServer(self, tab): |
57 # Avoid paying for a cross-renderer navigation on the first page on legacy | 68 # Avoid paying for a cross-renderer navigation on the first page on legacy |
58 # page cyclers which use the filesystem. | 69 # page cyclers which use the filesystem. |
59 tab.Navigate(tab.browser.http_server.UrlOf('nonexistent.html')) | 70 tab.Navigate(tab.browser.http_server.UrlOf('nonexistent.html')) |
60 | 71 |
61 def WillNavigateToPage(self, page, tab): | 72 def WillNavigateToPage(self, page, tab): |
62 page.script_to_evaluate_on_commit = self._page_cycler_js | 73 page.script_to_evaluate_on_commit = self._page_cycler_js |
63 if self.ShouldRunCold(page.url): | 74 if self.ShouldRunCold(page.url): |
64 tab.ClearCache() | 75 tab.ClearCache() |
65 | 76 |
66 def DidNavigateToPage(self, page, tab): | 77 def DidNavigateToPage(self, page, tab): |
67 self._memory_metric.Start(page, tab) | 78 self._memory_metric.Start(page, tab) |
| 79 if self._record_v8_object_stats: |
| 80 self._v8_object_stats_metric.Start(page, tab) |
68 | 81 |
69 def CustomizeBrowserOptions(self, options): | 82 def CustomizeBrowserOptions(self, options): |
70 memory.MemoryMetric.CustomizeBrowserOptions(options) | 83 memory.MemoryMetric.CustomizeBrowserOptions(options) |
71 io.IOMetric.CustomizeBrowserOptions(options) | 84 io.IOMetric.CustomizeBrowserOptions(options) |
72 options.AppendExtraBrowserArg('--js-flags=--expose_gc') | 85 options.AppendExtraBrowserArg('--js-flags=--expose_gc') |
73 | 86 |
| 87 if options.v8_object_stats: |
| 88 self._record_v8_object_stats = True |
| 89 v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options) |
| 90 |
74 # A disk cache bug causes some page cyclers to hang on mac. | 91 # A disk cache bug causes some page cyclers to hang on mac. |
75 # TODO(tonyg): Re-enable these tests when crbug.com/268646 is fixed. | 92 # TODO(tonyg): Re-enable these tests when crbug.com/268646 is fixed. |
76 if (sys.platform == 'darwin' and | 93 if (sys.platform == 'darwin' and |
77 (sys.argv[-1].endswith('/intl_hi_ru.json') or | 94 (sys.argv[-1].endswith('/intl_hi_ru.json') or |
78 sys.argv[-1].endswith('/tough_layout_cases.json') or | 95 sys.argv[-1].endswith('/tough_layout_cases.json') or |
79 sys.argv[-1].endswith('/typical_25.json'))): | 96 sys.argv[-1].endswith('/typical_25.json'))): |
80 print '%s is currently disabled on mac. Skipping test.' % sys.argv[-1] | 97 print '%s is currently disabled on mac. Skipping test.' % sys.argv[-1] |
81 sys.exit(0) | 98 sys.exit(0) |
82 | 99 |
83 # Handle requests for cold cache runs | 100 # Handle requests for cold cache runs |
(...skipping 30 matching lines...) Expand all Loading... |
114 'warm_times') | 131 'warm_times') |
115 | 132 |
116 results.Add('page_load_time', 'ms', | 133 results.Add('page_load_time', 'ms', |
117 int(float(tab.EvaluateJavaScript('__pc_load_time'))), | 134 int(float(tab.EvaluateJavaScript('__pc_load_time'))), |
118 chart_name=chart_name) | 135 chart_name=chart_name) |
119 | 136 |
120 self._has_loaded_page[page.url] += 1 | 137 self._has_loaded_page[page.url] += 1 |
121 | 138 |
122 self._memory_metric.Stop(page, tab) | 139 self._memory_metric.Stop(page, tab) |
123 self._memory_metric.AddResults(tab, results) | 140 self._memory_metric.AddResults(tab, results) |
| 141 if self._record_v8_object_stats: |
| 142 self._v8_object_stats_metric.Stop(page, tab) |
| 143 self._v8_object_stats_metric.AddResults(tab, results) |
124 | 144 |
125 def DidRunTest(self, tab, results): | 145 def DidRunTest(self, tab, results): |
126 self._memory_metric.AddSummaryResults(results) | 146 self._memory_metric.AddSummaryResults(results) |
127 io.IOMetric().AddSummaryResults(tab, results) | 147 io.IOMetric().AddSummaryResults(tab, results) |
128 | 148 |
129 def ShouldRunCold(self, url): | 149 def ShouldRunCold(self, url): |
130 # We do the warm runs first for two reasons. The first is so we can | 150 # We do the warm runs first for two reasons. The first is so we can |
131 # preserve any initial profile cache for as long as possible. | 151 # preserve any initial profile cache for as long as possible. |
132 # The second is that, if we did cold runs first, we'd have a transition | 152 # The second is that, if we did cold runs first, we'd have a transition |
133 # page set during which we wanted the run for each URL to both | 153 # page set during which we wanted the run for each URL to both |
134 # contribute to the cold data and warm the catch for the following | 154 # contribute to the cold data and warm the catch for the following |
135 # warm run, and clearing the cache before the load of the following | 155 # warm run, and clearing the cache before the load of the following |
136 # URL would eliminate the intended warmup for the previous URL. | 156 # URL would eliminate the intended warmup for the previous URL. |
137 return self._has_loaded_page[url] >= self._number_warm_runs + 1 | 157 return self._has_loaded_page[url] >= self._number_warm_runs + 1 |
138 | 158 |
139 def results_are_the_same_on_every_page(self): | 159 def results_are_the_same_on_every_page(self): |
140 return not self._cold_runs_requested | 160 return not self._cold_runs_requested |
OLD | NEW |