Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / tools / perf / measurements / oilpan_gc_times.py
blob49e0a2e382c999880fb74c11ad414d30b31fb5a9
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 os
7 from measurements import smoothness_controller
8 from measurements import timeline_controller
9 from telemetry.core.platform import tracing_category_filter
10 from telemetry.core.platform import tracing_options
11 from telemetry.page import page_test
12 from telemetry.page.actions import action_runner
13 from telemetry.timeline.model import TimelineModel
14 from telemetry.util import statistics
15 from telemetry.value import list_of_scalar_values
16 from telemetry.value import scalar
17 from telemetry.value import trace
20 _CR_RENDERER_MAIN = 'CrRendererMain'
21 _RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions'
22 _NAMES_TO_DUMP = ['oilpan_precise_mark',
23 'oilpan_precise_lazy_sweep',
24 'oilpan_precise_complete_sweep',
25 'oilpan_conservative_mark',
26 'oilpan_conservative_lazy_sweep',
27 'oilpan_conservative_complete_sweep',
28 'oilpan_coalesce']
30 def _AddTracingResults(events, results):
31 # Prepare
32 values = {}
33 for name in _NAMES_TO_DUMP:
34 values[name] = []
36 # Parse in time line
37 gc_type = None
38 forced = False
39 mark_time = 0
40 lazy_sweep_time = 0
41 complete_sweep_time = 0
42 for event in events:
43 duration = event.thread_duration or event.duration
44 if event.name == 'ThreadHeap::coalesce':
45 values['oilpan_coalesce'].append(duration)
46 continue
47 if event.name == 'Heap::collectGarbage':
48 if not gc_type is None and not forced:
49 values['oilpan_%s_mark' % gc_type].append(mark_time)
50 values['oilpan_%s_lazy_sweep' % gc_type].append(lazy_sweep_time)
51 values['oilpan_%s_complete_sweep' % gc_type].append(complete_sweep_time)
53 gc_type = 'precise' if event.args['precise'] else 'conservative'
54 forced = event.args['forced']
55 mark_time = duration
56 lazy_sweep_time = 0
57 complete_sweep_time = 0
58 continue
59 if event.name == 'ThreadHeap::lazySweepPages':
60 lazy_sweep_time += duration
61 continue
62 if event.name == 'ThreadState::completeSweep':
63 complete_sweep_time += duration
64 continue
66 if not gc_type is None and not forced:
67 values['oilpan_%s_mark' % gc_type].append(mark_time)
68 values['oilpan_%s_lazy_sweep' % gc_type].append(lazy_sweep_time)
69 values['oilpan_%s_complete_sweep' % gc_type].append(complete_sweep_time)
71 # Dump
72 page = results.current_page
73 unit = 'ms'
74 for name in _NAMES_TO_DUMP:
75 if values[name]:
76 results.AddValue(list_of_scalar_values.ListOfScalarValues(
77 page, name, unit, values[name]))
78 results.AddValue(scalar.ScalarValue(
79 page, name + '_max', unit, max(values[name])))
80 results.AddValue(scalar.ScalarValue(
81 page, name + '_total', unit, sum(values[name])))
83 # Summarize marking time
84 total_mark_time = 0
85 for gc_type in ['precise', 'conservative']:
86 total_mark_time += sum(values['oilpan_%s_mark' % gc_type])
87 results.AddValue(
88 scalar.ScalarValue(page, 'oilpan_mark', unit, total_mark_time))
90 # Summarize sweeping time
91 total_sweep_time = 0
92 for do_type in ['lazy_sweep', 'complete_sweep']:
93 sweep_time = 0
94 for gc_type in ['precise', 'conservative']:
95 sweep_time += sum(values['oilpan_%s_%s' % (gc_type, do_type)])
96 key = 'oilpan_%s' % do_type
97 results.AddValue(scalar.ScalarValue(page, key, unit, sweep_time))
98 total_sweep_time += sweep_time
99 results.AddValue(
100 scalar.ScalarValue(page, 'oilpan_sweep', unit, total_sweep_time))
102 gc_time = 0
103 for key in values:
104 gc_time += sum(values[key])
105 results.AddValue(scalar.ScalarValue(page, 'oilpan_gc', unit, gc_time))
108 class _OilpanGCTimesBase(page_test.PageTest):
109 def __init__(self, action_name = ''):
110 super(_OilpanGCTimesBase, self).__init__(action_name)
111 self._timeline_model = None
113 def WillNavigateToPage(self, page, tab):
114 # FIXME: Remove webkit.console when blink.console lands in chromium and
115 # the ref builds are updated. crbug.com/386847
116 categories = ['webkit.console', 'blink.console', 'blink_gc']
117 category_filter = tracing_category_filter.TracingCategoryFilter()
118 for c in categories:
119 category_filter.AddIncludedCategory(c)
120 options = tracing_options.TracingOptions()
121 options.enable_chrome_trace = True
122 tab.browser.platform.tracing_controller.Start(options, category_filter,
123 timeout=1000)
125 def DidRunActions(self, page, tab):
126 timeline_data = tab.browser.platform.tracing_controller.Stop()
127 self._timeline_model = TimelineModel(timeline_data)
129 def ValidateAndMeasurePage(self, page, tab, results):
130 threads = self._timeline_model.GetAllThreads()
131 for thread in threads:
132 if thread.name == _CR_RENDERER_MAIN:
133 _AddTracingResults(thread.all_slices, results)
135 def CleanUpAfterPage(self, page, tab):
136 if tab.browser.platform.tracing_controller.is_tracing_running:
137 tab.browser.platform.tracing_controller.Stop()
140 class OilpanGCTimesForSmoothness(_OilpanGCTimesBase):
141 def __init__(self):
142 super(OilpanGCTimesForSmoothness, self).__init__('RunPageInteractions')
143 self._interaction = None
145 def WillRunActions(self, page, tab):
146 runner = action_runner.ActionRunner(tab)
147 self._interaction = runner.BeginInteraction(_RUN_SMOOTH_ACTIONS,
148 is_smooth=True)
150 def DidRunActions(self, page, tab):
151 self._interaction.End()
152 super(OilpanGCTimesForSmoothness, self).DidRunActions(page, tab)
155 class OilpanGCTimesForBlinkPerf(_OilpanGCTimesBase):
156 def __init__(self):
157 super(OilpanGCTimesForBlinkPerf, self).__init__()
158 with open(os.path.join(os.path.dirname(__file__), '..', 'benchmarks',
159 'blink_perf.js'), 'r') as f:
160 self._blink_perf_js = f.read()
162 def WillNavigateToPage(self, page, tab):
163 page.script_to_evaluate_on_commit = self._blink_perf_js
164 super(OilpanGCTimesForBlinkPerf, self).WillNavigateToPage(page, tab)
166 def DidRunActions(self, page, tab):
167 tab.WaitForJavaScriptExpression('testRunner.isDone', 600)
168 super(OilpanGCTimesForBlinkPerf, self).DidRunActions(page, tab)
171 class OilpanGCTimesForInternals(_OilpanGCTimesBase):
172 def __init__(self):
173 super(OilpanGCTimesForInternals, self).__init__()
175 @classmethod
176 def CustomizeBrowserOptions(cls, options):
177 # 'expose-internals-for-testing' can be enabled on content shell.
178 assert 'content-shell' in options.browser_type
179 options.AppendExtraBrowserArgs('--expose-internals-for-testing')