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 os | 18 import os |
19 import sys | 19 import sys |
20 | 20 |
21 from metrics import io | 21 from metrics import io |
22 from metrics import memory | 22 from metrics import memory |
23 from metrics import v8_object_stats | |
23 from telemetry.core import util | 24 from telemetry.core import util |
24 from telemetry.page import page_measurement | 25 from telemetry.page import page_measurement |
25 | 26 |
26 class PageCycler(page_measurement.PageMeasurement): | 27 class PageCycler(page_measurement.PageMeasurement): |
27 def __init__(self, *args, **kwargs): | 28 def __init__(self, *args, **kwargs): |
28 super(PageCycler, self).__init__(*args, **kwargs) | 29 super(PageCycler, self).__init__(*args, **kwargs) |
29 | 30 |
30 with open(os.path.join(os.path.dirname(__file__), | 31 with open(os.path.join(os.path.dirname(__file__), |
31 'page_cycler.js'), 'r') as f: | 32 'page_cycler.js'), 'r') as f: |
32 self._page_cycler_js = f.read() | 33 self._page_cycler_js = f.read() |
33 | 34 |
35 self._record_v8_object_stats = False | |
36 | |
34 self._memory_metric = None | 37 self._memory_metric = None |
38 self._v8_object_stats_metric = None | |
39 | |
35 | 40 |
36 def AddCommandLineOptions(self, parser): | 41 def AddCommandLineOptions(self, parser): |
37 # The page cyclers should default to 10 iterations. In order to change the | 42 # The page cyclers should default to 10 iterations. In order to change the |
38 # default of an option, we must remove and re-add it. | 43 # default of an option, we must remove and re-add it. |
39 # TODO: Remove this after transition to run_benchmark. | 44 # TODO: Remove this after transition to run_benchmark. |
40 pageset_repeat_option = parser.get_option('--pageset-repeat') | 45 pageset_repeat_option = parser.get_option('--pageset-repeat') |
41 pageset_repeat_option.default = 10 | 46 pageset_repeat_option.default = 10 |
42 parser.remove_option('--pageset-repeat') | 47 parser.remove_option('--pageset-repeat') |
43 parser.add_option(pageset_repeat_option) | 48 parser.add_option(pageset_repeat_option) |
44 | 49 |
50 parser.add_option('--v8-object-stats', | |
51 action='store_true', | |
52 help='Enable detailed V8 object statistics.') | |
53 | |
45 def DidStartBrowser(self, browser): | 54 def DidStartBrowser(self, browser): |
46 """Initialize metrics once right after the browser has been launched.""" | 55 """Initialize metrics once right after the browser has been launched.""" |
47 self._memory_metric = memory.MemoryMetric(browser) | 56 self._memory_metric = memory.MemoryMetric(browser) |
57 if self._record_v8_object_stats: | |
58 self._v8_object_stats_metric = v8_object_stats.V8ObjectStatsMetric() | |
48 | 59 |
49 def DidStartHTTPServer(self, tab): | 60 def DidStartHTTPServer(self, tab): |
50 # Avoid paying for a cross-renderer navigation on the first page on legacy | 61 # Avoid paying for a cross-renderer navigation on the first page on legacy |
51 # page cyclers which use the filesystem. | 62 # page cyclers which use the filesystem. |
52 tab.Navigate(tab.browser.http_server.UrlOf('nonexistent.html')) | 63 tab.Navigate(tab.browser.http_server.UrlOf('nonexistent.html')) |
53 | 64 |
54 def WillNavigateToPage(self, page, tab): | 65 def WillNavigateToPage(self, page, tab): |
55 page.script_to_evaluate_on_commit = self._page_cycler_js | 66 page.script_to_evaluate_on_commit = self._page_cycler_js |
56 | 67 |
57 def DidNavigateToPage(self, page, tab): | 68 def DidNavigateToPage(self, page, tab): |
58 self._memory_metric.Start(page, tab) | 69 self._memory_metric.Start(page, tab) |
70 if self._record_v8_object_stats: | |
71 self._v8_object_stats_metric.Start(page, tab) | |
59 | 72 |
60 def CustomizeBrowserOptions(self, options): | 73 def CustomizeBrowserOptions(self, options): |
61 memory.MemoryMetric.CustomizeBrowserOptions(options) | 74 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') |
tonyg
2013/08/27 15:40:02
Was there a merge error here? Ideally there should
rmcilroy
2013/08/27 18:24:07
Opps, this seems to have been a merge error. Done
| |
62 io.IOMetric.CustomizeBrowserOptions(options) | |
63 options.AppendExtraBrowserArg('--js-flags=--expose_gc') | 75 options.AppendExtraBrowserArg('--js-flags=--expose_gc') |
76 options.AppendExtraBrowserArg('--no-sandbox') | |
77 | |
78 # Old commandline flags used for reference builds. | |
79 options.AppendExtraBrowserArg('--dom-automation') | |
80 | |
81 # Add custom options required by metrics | |
82 if options.v8_object_stats: | |
83 self._record_v8_object_stats = True | |
84 v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options) | |
64 | 85 |
65 # Temporarily disable typical_25 page set on mac. | 86 # Temporarily disable typical_25 page set on mac. |
66 if sys.platform == 'darwin' and sys.argv[-1].endswith('/typical_25.json'): | 87 if sys.platform == 'darwin' and sys.argv[-1].endswith('/typical_25.json'): |
67 print 'typical_25 is currently disabled on mac. Skipping test.' | 88 print 'typical_25 is currently disabled on mac. Skipping test.' |
68 sys.exit(0) | 89 sys.exit(0) |
69 | 90 |
70 def MeasurePage(self, page, tab, results): | 91 def MeasurePage(self, page, tab, results): |
71 def _IsDone(): | 92 def _IsDone(): |
72 return bool(tab.EvaluateJavaScript('__pc_load_time')) | 93 return bool(tab.EvaluateJavaScript('__pc_load_time')) |
73 util.WaitFor(_IsDone, 60) | 94 util.WaitFor(_IsDone, 60) |
74 results.Add('page_load_time', 'ms', | 95 results.Add('page_load_time', 'ms', |
75 int(float(tab.EvaluateJavaScript('__pc_load_time'))), | 96 int(float(tab.EvaluateJavaScript('__pc_load_time'))), |
76 chart_name='times') | 97 chart_name='times') |
77 | 98 |
78 self._memory_metric.Stop(page, tab) | 99 self._memory_metric.Stop(page, tab) |
79 self._memory_metric.AddResults(tab, results) | 100 self._memory_metric.AddResults(tab, results) |
101 if self._record_v8_object_stats: | |
102 self._v8_object_stats_metric.Stop(page, tab) | |
103 self._v8_object_stats_metric.AddResults(tab, results) | |
80 | 104 |
81 def DidRunTest(self, tab, results): | 105 def DidRunTest(self, tab, results): |
82 self._memory_metric.AddSummaryResults(results) | 106 self._memory_metric.AddSummaryResults(results) |
83 io.IOMetric().AddSummaryResults(tab, results) | 107 io.IOMetric().AddSummaryResults(tab, results) |
84 | 108 |
OLD | NEW |