Revert of Enable ServiceWorkerPerfTest (service_worker.service_worker) (patchset...
[chromium-blink-merge.git] / tools / perf / benchmarks / service_worker.py
blob7f1c8a94c6de421870398250c226aaa883cd8884
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import collections
6 import page_sets
7 import re
9 from measurements import timeline_controller
10 from metrics import speedindex
11 from telemetry import benchmark
12 from telemetry.core import util
13 from telemetry.page import page_test
14 from telemetry.timeline import async_slice as async_slice_module
15 from telemetry.timeline import slice as slice_module
16 from telemetry.value import scalar
19 class _ServiceWorkerTimelineMetric(object):
20 def AddResultsOfCounters(self, process, counter_regex_string, results):
21 counter_filter = re.compile(counter_regex_string)
22 for counter_name, counter in process.counters.iteritems():
23 if not counter_filter.search(counter_name):
24 continue
26 total = sum(counter.totals)
28 # Results objects cannot contain the '.' character, so remove that here.
29 sanitized_counter_name = counter_name.replace('.', '_')
31 results.AddValue(scalar.ScalarValue(
32 results.current_page, sanitized_counter_name, 'count', total))
33 results.AddValue(scalar.ScalarValue(
34 results.current_page, sanitized_counter_name + '_avg', 'count',
35 total / float(len(counter.totals))))
37 def AddResultsOfEvents(
38 self, process, thread_regex_string, event_regex_string, results):
39 thread_filter = re.compile(thread_regex_string)
40 event_filter = re.compile(event_regex_string)
42 for thread in process.threads.itervalues():
43 thread_name = thread.name.replace('/', '_')
44 if not thread_filter.search(thread_name):
45 continue
47 filtered_events = []
48 for event in thread.IterAllEvents():
49 event_name = event.name.replace('.', '_')
50 if event_filter.search(event_name):
51 filtered_events.append(event)
53 async_events_by_name = collections.defaultdict(list)
54 sync_events_by_name = collections.defaultdict(list)
55 for event in filtered_events:
56 if isinstance(event, async_slice_module.AsyncSlice):
57 async_events_by_name[event.name].append(event)
58 elif isinstance(event, slice_module.Slice):
59 sync_events_by_name[event.name].append(event)
61 for event_name, event_group in async_events_by_name.iteritems():
62 times = [e.duration for e in event_group]
63 self._AddResultOfEvent(thread_name, event_name, times, results)
65 for event_name, event_group in sync_events_by_name.iteritems():
66 times = [e.self_time for e in event_group]
67 self._AddResultOfEvent(thread_name, event_name, times, results)
69 def _AddResultOfEvent(self, thread_name, event_name, times, results):
70 total = sum(times)
71 biggest_jank = max(times)
73 # Results objects cannot contain the '.' character, so remove that here.
74 sanitized_event_name = event_name.replace('.', '_')
76 full_name = thread_name + '|' + sanitized_event_name
77 results.AddValue(scalar.ScalarValue(
78 results.current_page, full_name, 'ms', total))
79 results.AddValue(scalar.ScalarValue(
80 results.current_page, full_name + '_max', 'ms', biggest_jank))
81 results.AddValue(scalar.ScalarValue(
82 results.current_page, full_name + '_avg', 'ms', total / len(times)))
85 class _ServiceWorkerMeasurement(page_test.PageTest):
86 """Measure Speed Index and TRACE_EVENTs"""
88 def __init__(self):
89 super(_ServiceWorkerMeasurement, self).__init__(
90 action_name_to_run='RunPageInteractions')
91 self._timeline_controller = timeline_controller.TimelineController()
92 self._speed_index = speedindex.SpeedIndexMetric()
93 self._page_open_times = collections.defaultdict(int)
95 def CustomizeBrowserOptions(self, options):
96 options.AppendExtraBrowserArgs([
97 '--enable-experimental-web-platform-features'
100 def WillNavigateToPage(self, page, tab):
101 self._timeline_controller.SetUp(page, tab)
102 self._timeline_controller.Start(tab)
103 self._speed_index.Start(page, tab)
105 def ValidateAndMeasurePage(self, page, tab, results):
106 tab.WaitForDocumentReadyStateToBeComplete(40)
107 self._timeline_controller.Stop(tab, results)
109 # Retrieve TRACE_EVENTs
110 timeline_metric = _ServiceWorkerTimelineMetric()
111 browser_process = self._timeline_controller.model.browser_process
112 filter_text = '(RegisterServiceWorker|'\
113 'UnregisterServiceWorker|'\
114 'ProcessAllocate|'\
115 'FindRegistrationForDocument|'\
116 'DispatchFetchEvent)'
117 timeline_metric.AddResultsOfEvents(
118 browser_process, 'IOThread', filter_text , results)
120 # Record Speed Index
121 def SpeedIndexIsFinished():
122 return self._speed_index.IsFinished(tab)
123 util.WaitFor(SpeedIndexIsFinished, 60)
124 self._speed_index.Stop(page, tab)
125 # Distinguish the first and second load from the subsequent loads
126 url = str(page)
127 chart_prefix = 'page_load'
128 self._page_open_times[url] += 1
129 if self._page_open_times[url] == 1:
130 chart_prefix += '_1st'
131 elif self._page_open_times[url] == 2:
132 chart_prefix += '_2nd'
133 else:
134 chart_prefix += '_later'
135 self._speed_index.AddResults(tab, results, chart_prefix)
138 class _ServiceWorkerMicroBenchmarkMeasurement(page_test.PageTest):
139 """Measure JS land values and TRACE_EVENTs"""
141 def __init__(self):
142 super(_ServiceWorkerMicroBenchmarkMeasurement, self).__init__(
143 action_name_to_run='RunPageInteractions')
144 self._timeline_controller = timeline_controller.TimelineController()
146 def CustomizeBrowserOptions(self, options):
147 options.AppendExtraBrowserArgs([
148 '--enable-experimental-web-platform-features'
151 def WillNavigateToPage(self, page, tab):
152 self._timeline_controller.SetUp(page, tab)
153 self._timeline_controller.Start(tab)
155 def ValidateAndMeasurePage(self, page, tab, results):
156 tab.WaitForJavaScriptExpression('window.done', 40)
157 self._timeline_controller.Stop(tab, results)
159 # Measure JavaScript-land
160 json = tab.EvaluateJavaScript('window.results || {}')
161 for key, value in json.iteritems():
162 results.AddValue(scalar.ScalarValue(
163 results.current_page, key, value['units'], value['value']))
165 # Retrieve TRACE_EVENTs
166 timeline_metric = _ServiceWorkerTimelineMetric()
167 browser_process = self._timeline_controller.model.browser_process
168 filter_text = '(RegisterServiceWorker|'\
169 'UnregisterServiceWorker|'\
170 'ProcessAllocate|'\
171 'FindRegistrationForDocument|'\
172 'DispatchFetchEvent)'
173 timeline_metric.AddResultsOfEvents(
174 browser_process, 'IOThread', filter_text , results)
177 # TODO(simonhatch): Temporarily disabling (http://crbug.com/433943)
178 @benchmark.Disabled
179 class ServiceWorkerPerfTest(benchmark.Benchmark):
180 """Performance test on public applications using ServiceWorker"""
181 test = _ServiceWorkerMeasurement
182 page_set = page_sets.ServiceWorkerPageSet
184 @classmethod
185 def Name(cls):
186 return 'service_worker.service_worker'
189 # Disabled due to redness on the tree. crbug.com/442752
190 # TODO(horo): Enable after the reference build newer than M39 will be rolled.
191 @benchmark.Disabled('reference')
192 class ServiceWorkerMicroBenchmarkPerfTest(benchmark.Benchmark):
193 """This test measures the performance of pages using ServiceWorker.
195 As a page set, two benchamrk pages (many registration, many concurrent
196 fetching) and one application (Trained-to-thrill:
197 https://jakearchibald.github.io/trained-to-thrill/) are included. Execution
198 time of these pages will be shown as Speed Index, and TRACE_EVENTs are
199 subsidiary information to know more detail performance regression.
201 test = _ServiceWorkerMicroBenchmarkMeasurement
202 page_set = page_sets.ServiceWorkerMicroBenchmarkPageSet
203 @classmethod
204 def Name(cls):
205 return 'service_worker.service_worker_micro_benchmark'