[Telemetry] Add deprecation tag for page_test.CleanUpAfterPage hook & add
[chromium-blink-merge.git] / tools / perf / measurements / oilpan_gc_times.py
blob7fd5dcf5a734e54ac6e31c46cd54caf4fd9f2f3f
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 telemetry.page import action_runner
8 from telemetry.page import page_test
9 from telemetry.timeline.model import TimelineModel
10 from telemetry.timeline import tracing_category_filter
11 from telemetry.timeline import tracing_options
12 from telemetry.value import list_of_scalar_values
13 from telemetry.value import scalar
16 _CR_RENDERER_MAIN = 'CrRendererMain'
17 _RUN_SMOOTH_ACTIONS = 'RunSmoothAllActions'
20 def _AddTracingResults(thread, results):
21 _GC_REASONS = ['precise', 'conservative', 'idle', 'forced']
22 _GC_STAGES = ['mark', 'lazy_sweep', 'complete_sweep']
24 def GetGcReason(event, async_slices):
25 args = event.args
27 # Old format
28 if 'precise' in args:
29 if args['forced']:
30 return 'forced'
31 return 'precise' if args['precise'] else 'conservative'
33 if args['gcReason'] == 'ConservativeGC':
34 return 'conservative'
35 if args['gcReason'] == 'PreciseGC':
36 return 'precise'
37 if args['gcReason'] == 'ForcedGCForTesting':
38 for s in async_slices:
39 if s.start <= event.start and event.end <= s.end:
40 return 'forced'
41 # Ignore this forced GC being out of target ranges
42 return None
43 if args['gcReason'] == 'IdleGC':
44 return 'idle'
45 return None # Unknown
47 def DumpMetric(page, name, values, unit, results):
48 if values[name]:
49 results.AddValue(list_of_scalar_values.ListOfScalarValues(
50 page, name, unit, values[name]))
51 results.AddValue(scalar.ScalarValue(
52 page, name + '_max', unit, max(values[name])))
53 results.AddValue(scalar.ScalarValue(
54 page, name + '_total', unit, sum(values[name])))
56 events = thread.all_slices
57 async_slices = [s for s in thread.async_slices
58 if s.name == 'BlinkGCTimeMeasurement']
60 # Prepare
61 values = {'oilpan_coalesce': []}
62 for reason in _GC_REASONS:
63 for stage in _GC_STAGES:
64 values['oilpan_%s_%s' % (reason, stage)] = []
66 # Parse trace events
67 reason = None
68 mark_time = 0
69 lazy_sweep_time = 0
70 complete_sweep_time = 0
71 for event in events:
72 duration = event.thread_duration or event.duration
73 if event.name == 'ThreadHeap::coalesce':
74 values['oilpan_coalesce'].append(duration)
75 continue
76 if event.name == 'Heap::collectGarbage':
77 if reason is not None:
78 values['oilpan_%s_mark' % reason].append(mark_time)
79 values['oilpan_%s_lazy_sweep' % reason].append(lazy_sweep_time)
80 values['oilpan_%s_complete_sweep' % reason].append(complete_sweep_time)
82 reason = GetGcReason(event, async_slices)
83 mark_time = duration
84 lazy_sweep_time = 0
85 complete_sweep_time = 0
86 continue
87 if event.name == 'ThreadHeap::lazySweepPages':
88 lazy_sweep_time += duration
89 continue
90 if event.name == 'ThreadState::completeSweep':
91 complete_sweep_time += duration
92 continue
94 if reason is not None:
95 values['oilpan_%s_mark' % reason].append(mark_time)
96 values['oilpan_%s_lazy_sweep' % reason].append(lazy_sweep_time)
97 values['oilpan_%s_complete_sweep' % reason].append(complete_sweep_time)
99 page = results.current_page
100 unit = 'ms'
102 # Dump each metric
103 DumpMetric(page, 'oilpan_coalesce', values, unit, results)
104 for reason in _GC_REASONS:
105 for stage in _GC_STAGES:
106 DumpMetric(page, 'oilpan_%s_%s' % (reason, stage), values, unit, results)
108 # Summarize each stage
109 for stage in _GC_STAGES:
110 total_time = 0
111 for reason in _GC_REASONS:
112 total_time += sum(values['oilpan_%s_%s' % (reason, stage)])
113 results.AddValue(
114 scalar.ScalarValue(page, 'oilpan_%s' % stage, unit, total_time))
116 # Summarize sweeping time
117 total_sweep_time = 0
118 for stage in ['lazy_sweep', 'complete_sweep']:
119 sweep_time = 0
120 for reason in _GC_REASONS:
121 sweep_time += sum(values['oilpan_%s_%s' % (reason, stage)])
122 key = 'oilpan_%s' % stage
123 results.AddValue(scalar.ScalarValue(page, key, unit, sweep_time))
124 total_sweep_time += sweep_time
125 results.AddValue(
126 scalar.ScalarValue(page, 'oilpan_sweep', unit, total_sweep_time))
128 gc_time = 0
129 for key in values:
130 gc_time += sum(values[key])
131 results.AddValue(scalar.ScalarValue(page, 'oilpan_gc', unit, gc_time))
134 class _OilpanGCTimesBase(page_test.PageTest):
135 def __init__(self, action_name=''):
136 super(_OilpanGCTimesBase, self).__init__(action_name)
138 def WillNavigateToPage(self, page, tab):
139 # FIXME: Remove webkit.console when blink.console lands in chromium and
140 # the ref builds are updated. crbug.com/386847
141 categories = ['webkit.console', 'blink.console', 'blink_gc']
142 category_filter = tracing_category_filter.TracingCategoryFilter()
143 for c in categories:
144 category_filter.AddIncludedCategory(c)
145 options = tracing_options.TracingOptions()
146 options.enable_chrome_trace = True
147 tab.browser.platform.tracing_controller.Start(options, category_filter,
148 timeout=1000)
150 def ValidateAndMeasurePage(self, page, tab, results):
151 timeline_data = tab.browser.platform.tracing_controller.Stop()
152 timeline_model = TimelineModel(timeline_data)
153 threads = timeline_model.GetAllThreads()
154 for thread in threads:
155 if thread.name == _CR_RENDERER_MAIN:
156 _AddTracingResults(thread, results)
158 def DidRunPage(self, platform):
159 if platform.tracing_controller.is_tracing_running:
160 platform.tracing_controller.Stop()
163 class OilpanGCTimesForSmoothness(_OilpanGCTimesBase):
164 def __init__(self):
165 super(OilpanGCTimesForSmoothness, self).__init__()
166 self._interaction = None
168 def DidNavigateToPage(self, page, tab):
169 runner = action_runner.ActionRunner(tab)
170 self._interaction = runner.CreateInteraction(_RUN_SMOOTH_ACTIONS)
171 self._interaction.Begin()
173 def ValidateAndMeasurePage(self, page, tab, results):
174 self._interaction.End()
175 super(OilpanGCTimesForSmoothness, self).ValidateAndMeasurePage(
176 page, tab, results)
179 class OilpanGCTimesForBlinkPerf(_OilpanGCTimesBase):
180 def __init__(self):
181 super(OilpanGCTimesForBlinkPerf, self).__init__()
182 with open(os.path.join(os.path.dirname(__file__), '..', 'benchmarks',
183 'blink_perf.js'), 'r') as f:
184 self._blink_perf_js = f.read()
186 def WillNavigateToPage(self, page, tab):
187 page.script_to_evaluate_on_commit = self._blink_perf_js
188 super(OilpanGCTimesForBlinkPerf, self).WillNavigateToPage(page, tab)
190 def ValidateAndMeasurePage(self, page, tab, results):
191 tab.WaitForJavaScriptExpression('testRunner.isDone', 600)
192 super(OilpanGCTimesForBlinkPerf, self).ValidateAndMeasurePage(
193 page, tab, results)
196 class OilpanGCTimesForInternals(OilpanGCTimesForBlinkPerf):
197 def __init__(self):
198 super(OilpanGCTimesForInternals, self).__init__()
200 @classmethod
201 def CustomizeBrowserOptions(cls, options):
202 # 'expose-internals-for-testing' can be enabled on content shell.
203 assert 'content-shell' in options.browser_type
204 options.AppendExtraBrowserArgs(['--expose-internals-for-testing',
205 '--js-flags=--expose-gc'])