Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: tools/perf/measurements/page_cycler.py

Issue 714273004: mac: Expose keychain access frequency to Telemetry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mock_keychain_sleep
Patch Set: Respond to offline comments from tonyg. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 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 metrics import cpu 21 from metrics import cpu
22 from metrics import iometric 22 from metrics import iometric
23 from metrics import keychain_metric
23 from metrics import memory 24 from metrics import memory
24 from metrics import power 25 from metrics import power
25 from metrics import speedindex 26 from metrics import speedindex
26 from metrics import v8_object_stats 27 from metrics import v8_object_stats
27 from telemetry.core import util 28 from telemetry.core import util
28 from telemetry.page import page_test 29 from telemetry.page import page_test
29 from telemetry.value import scalar 30 from telemetry.value import scalar
30 31
31 32
32 class PageCycler(page_test.PageTest): 33 class PageCycler(page_test.PageTest):
33 def __init__(self, page_repeat, pageset_repeat, cold_load_percent=50, 34 def __init__(self, page_repeat, pageset_repeat, cold_load_percent=50,
34 record_v8_object_stats=False, report_speed_index=False, 35 record_v8_object_stats=False, report_speed_index=False,
35 clear_cache_before_each_run=False): 36 clear_cache_before_each_run=False):
36 super(PageCycler, self).__init__( 37 super(PageCycler, self).__init__(
37 clear_cache_before_each_run=clear_cache_before_each_run) 38 clear_cache_before_each_run=clear_cache_before_each_run)
38 39
39 with open(os.path.join(os.path.dirname(__file__), 40 with open(os.path.join(os.path.dirname(__file__),
40 'page_cycler.js'), 'r') as f: 41 'page_cycler.js'), 'r') as f:
41 self._page_cycler_js = f.read() 42 self._page_cycler_js = f.read()
42 43
43 self._record_v8_object_stats = record_v8_object_stats 44 self._record_v8_object_stats = record_v8_object_stats
44 self._report_speed_index = report_speed_index 45 self._report_speed_index = report_speed_index
45 self._speedindex_metric = speedindex.SpeedIndexMetric() 46 self._speedindex_metric = speedindex.SpeedIndexMetric()
46 self._memory_metric = None 47 self._memory_metric = None
47 self._power_metric = None 48 self._power_metric = None
48 self._cpu_metric = None 49 self._cpu_metric = None
49 self._v8_object_stats_metric = None 50 self._v8_object_stats_metric = None
50 self._has_loaded_page = collections.defaultdict(int) 51 self._has_loaded_page = collections.defaultdict(int)
51 self._initial_renderer_url = None # to avoid cross-renderer navigation 52 self._initial_renderer_url = None # to avoid cross-renderer navigation
53 self._in_unit_test = False
52 54
53 cold_runs_percent_set = (cold_load_percent != None) 55 cold_runs_percent_set = (cold_load_percent != None)
54 # Handle requests for cold cache runs 56 # Handle requests for cold cache runs
55 if (cold_runs_percent_set and 57 if (cold_runs_percent_set and
56 (cold_load_percent < 0 or cold_load_percent > 100)): 58 (cold_load_percent < 0 or cold_load_percent > 100)):
57 raise Exception('cold-load-percent must be in the range [0-100]') 59 raise Exception('cold-load-percent must be in the range [0-100]')
58 60
59 # Make sure _cold_run_start_index is an integer multiple of page_repeat. 61 # Make sure _cold_run_start_index is an integer multiple of page_repeat.
60 # Without this, --pageset_shuffle + --page_repeat could lead to 62 # Without this, --pageset_shuffle + --page_repeat could lead to
61 # assertion failures on _started_warm in WillNavigateToPage. 63 # assertion failures on _started_warm in WillNavigateToPage.
62 if cold_runs_percent_set: 64 if cold_runs_percent_set:
63 number_warm_pageset_runs = int( 65 number_warm_pageset_runs = int(
64 (int(pageset_repeat) - 1) * (100 - cold_load_percent) / 100) 66 (int(pageset_repeat) - 1) * (100 - cold_load_percent) / 100)
65 number_warm_runs = number_warm_pageset_runs * page_repeat 67 number_warm_runs = number_warm_pageset_runs * page_repeat
66 self._cold_run_start_index = number_warm_runs + page_repeat 68 self._cold_run_start_index = number_warm_runs + page_repeat
67 self._discard_first_result = (not cold_load_percent or 69 self._discard_first_result = (not cold_load_percent or
68 self._discard_first_result) 70 self._discard_first_result)
69 else: 71 else:
70 self._cold_run_start_index = pageset_repeat * page_repeat 72 self._cold_run_start_index = pageset_repeat * page_repeat
71 73
74 def SetInUnitTest(self, in_unit_test):
75 """Setter for the property |_in_unit_test|."""
76 self._in_unit_test = in_unit_test
77
72 def WillStartBrowser(self, platform): 78 def WillStartBrowser(self, platform):
73 """Initialize metrics once right before the browser has been launched.""" 79 """Initialize metrics once right before the browser has been launched."""
74 self._power_metric = power.PowerMetric(platform) 80 self._power_metric = power.PowerMetric(platform)
75 81
76 def DidStartBrowser(self, browser): 82 def DidStartBrowser(self, browser):
77 """Initialize metrics once right after the browser has been launched.""" 83 """Initialize metrics once right after the browser has been launched."""
78 self._memory_metric = memory.MemoryMetric(browser) 84 self._memory_metric = memory.MemoryMetric(browser)
79 self._cpu_metric = cpu.CpuMetric(browser) 85 self._cpu_metric = cpu.CpuMetric(browser)
80 if self._record_v8_object_stats: 86 if self._record_v8_object_stats:
81 self._v8_object_stats_metric = v8_object_stats.V8ObjectStatsMetric() 87 self._v8_object_stats_metric = v8_object_stats.V8ObjectStatsMetric()
(...skipping 24 matching lines...) Expand all
106 memory.MemoryMetric.CustomizeBrowserOptions(options) 112 memory.MemoryMetric.CustomizeBrowserOptions(options)
107 power.PowerMetric.CustomizeBrowserOptions(options) 113 power.PowerMetric.CustomizeBrowserOptions(options)
108 iometric.IOMetric.CustomizeBrowserOptions(options) 114 iometric.IOMetric.CustomizeBrowserOptions(options)
109 options.AppendExtraBrowserArgs('--js-flags=--expose_gc') 115 options.AppendExtraBrowserArgs('--js-flags=--expose_gc')
110 116
111 if self._record_v8_object_stats: 117 if self._record_v8_object_stats:
112 v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options) 118 v8_object_stats.V8ObjectStatsMetric.CustomizeBrowserOptions(options)
113 if self._report_speed_index: 119 if self._report_speed_index:
114 self._speedindex_metric.CustomizeBrowserOptions(options) 120 self._speedindex_metric.CustomizeBrowserOptions(options)
115 121
122 if (keychain_metric.KeychainMetric.ShouldCollectKeychainMetrics()
123 and not self._in_unit_test):
124 keychain_metric.KeychainMetric.CustomizeBrowserOptions(options)
125
116 def ValidateAndMeasurePage(self, page, tab, results): 126 def ValidateAndMeasurePage(self, page, tab, results):
117 tab.WaitForJavaScriptExpression('__pc_load_time', 60) 127 tab.WaitForJavaScriptExpression('__pc_load_time', 60)
118 128
119 chart_name_prefix = ('cold_' if self.IsRunCold(page.url) else 129 chart_name_prefix = ('cold_' if self.IsRunCold(page.url) else
120 'warm_') 130 'warm_')
121 131
122 results.AddValue(scalar.ScalarValue( 132 results.AddValue(scalar.ScalarValue(
123 results.current_page, '%stimes.page_load_time' % chart_name_prefix, 133 results.current_page, '%stimes.page_load_time' % chart_name_prefix,
124 'ms', tab.EvaluateJavaScript('__pc_load_time'), 134 'ms', tab.EvaluateJavaScript('__pc_load_time'),
125 description='Average page load time. Measured from ' 135 description='Average page load time. Measured from '
(...skipping 16 matching lines...) Expand all
142 self._v8_object_stats_metric.Stop(page, tab) 152 self._v8_object_stats_metric.Stop(page, tab)
143 self._v8_object_stats_metric.AddResults(tab, results) 153 self._v8_object_stats_metric.AddResults(tab, results)
144 154
145 if self._report_speed_index: 155 if self._report_speed_index:
146 def SpeedIndexIsFinished(): 156 def SpeedIndexIsFinished():
147 return self._speedindex_metric.IsFinished(tab) 157 return self._speedindex_metric.IsFinished(tab)
148 util.WaitFor(SpeedIndexIsFinished, 60) 158 util.WaitFor(SpeedIndexIsFinished, 60)
149 self._speedindex_metric.Stop(page, tab) 159 self._speedindex_metric.Stop(page, tab)
150 self._speedindex_metric.AddResults( 160 self._speedindex_metric.AddResults(
151 tab, results, chart_name=chart_name_prefix+'speed_index') 161 tab, results, chart_name=chart_name_prefix+'speed_index')
162 if (keychain_metric.KeychainMetric.ShouldCollectKeychainMetrics()
163 and not self._in_unit_test):
164 keychain_metric.KeychainMetric().AddResults(tab, results)
152 165
153 def DidRunTest(self, browser, results): 166 def DidRunTest(self, browser, results):
154 iometric.IOMetric().AddSummaryResults(browser, results) 167 iometric.IOMetric().AddSummaryResults(browser, results)
155 168
156 def IsRunCold(self, url): 169 def IsRunCold(self, url):
157 return (self.ShouldRunCold(url) or 170 return (self.ShouldRunCold(url) or
158 self._has_loaded_page[url] == 0) 171 self._has_loaded_page[url] == 0)
159 172
160 def ShouldRunCold(self, url): 173 def ShouldRunCold(self, url):
161 # We do the warm runs first for two reasons. The first is so we can 174 # We do the warm runs first for two reasons. The first is so we can
162 # preserve any initial profile cache for as long as possible. 175 # preserve any initial profile cache for as long as possible.
163 # The second is that, if we did cold runs first, we'd have a transition 176 # The second is that, if we did cold runs first, we'd have a transition
164 # page set during which we wanted the run for each URL to both 177 # page set during which we wanted the run for each URL to both
165 # contribute to the cold data and warm the catch for the following 178 # contribute to the cold data and warm the catch for the following
166 # warm run, and clearing the cache before the load of the following 179 # warm run, and clearing the cache before the load of the following
167 # URL would eliminate the intended warmup for the previous URL. 180 # URL would eliminate the intended warmup for the previous URL.
168 return (self._has_loaded_page[url] >= self._cold_run_start_index) 181 return (self._has_loaded_page[url] >= self._cold_run_start_index)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698