[Telemetry] Rename RunSmoothness to RunPageInteractions
[chromium-blink-merge.git] / tools / perf / measurements / oilpan_gc_times.py
blob3e7fd435329724b5f1d885df76b547d02e06b304
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_sweep',
24 'oilpan_conservative_mark',
25 'oilpan_conservative_sweep',
26 'oilpan_coalesce']
28 def _AddTracingResults(events, results):
29 # Prepare
30 values = {}
31 for name in _NAMES_TO_DUMP:
32 values[name] = []
34 # Parse in time line
35 gc_type = None
36 forced = False
37 mark_time = 0
38 sweep_time = 0
39 for event in events:
40 duration = event.thread_duration or event.duration
41 if event.name == 'ThreadHeap::coalesce':
42 values['oilpan_coalesce'].append(duration)
43 continue
44 if event.name == 'Heap::collectGarbage':
45 if not gc_type is None and not forced:
46 values['oilpan_%s_mark' % gc_type].append(mark_time)
47 values['oilpan_%s_sweep' % gc_type].append(sweep_time)
49 gc_type = 'precise' if event.args['precise'] else 'conservative'
50 forced = event.args['forced']
51 mark_time = duration
52 sweep_time = 0
53 continue
54 if event.name == 'ThreadState::performPendingSweep':
55 sweep_time += duration
56 continue
58 if not gc_type is None and not forced:
59 values['oilpan_%s_mark' % gc_type].append(mark_time)
60 values['oilpan_%s_sweep' % gc_type].append(sweep_time)
62 # Dump
63 page = results.current_page
64 unit = 'ms'
65 for name in _NAMES_TO_DUMP:
66 if values[name]:
67 results.AddValue(list_of_scalar_values.ListOfScalarValues(
68 page, name, unit, values[name]))
69 results.AddValue(scalar.ScalarValue(
70 page, name + '_max', unit, max(values[name])))
71 results.AddValue(scalar.ScalarValue(
72 page, name + '_total', unit, sum(values[name])))
74 for do_type in ['mark', 'sweep']:
75 work_time = 0
76 for gc_type in ['precise', 'conservative']:
77 work_time += sum(values['oilpan_%s_%s' % (gc_type, do_type)])
78 key = 'oilpan_%s' % do_type
79 results.AddValue(scalar.ScalarValue(page, key, unit, work_time))
81 gc_time = 0
82 for key in values:
83 gc_time += sum(values[key])
84 results.AddValue(scalar.ScalarValue(page, 'oilpan_gc', unit, gc_time))
87 class _OilpanGCTimesBase(page_test.PageTest):
88 def __init__(self, action_name = ''):
89 super(_OilpanGCTimesBase, self).__init__(action_name)
90 self._timeline_model = None
92 def WillNavigateToPage(self, page, tab):
93 # FIXME: Remove webkit.console when blink.console lands in chromium and
94 # the ref builds are updated. crbug.com/386847
95 categories = ['webkit.console', 'blink.console', 'blink_gc']
96 category_filter = tracing_category_filter.TracingCategoryFilter()
97 for c in categories:
98 category_filter.AddIncludedCategory(c)
99 options = tracing_options.TracingOptions()
100 options.enable_chrome_trace = True
101 tab.browser.platform.tracing_controller.Start(options, category_filter,
102 timeout=1000)
104 def DidRunActions(self, page, tab):
105 timeline_data = tab.browser.platform.tracing_controller.Stop()
106 self._timeline_model = TimelineModel(timeline_data)
108 def ValidateAndMeasurePage(self, page, tab, results):
109 threads = self._timeline_model.GetAllThreads()
110 for thread in threads:
111 if thread.name == _CR_RENDERER_MAIN:
112 _AddTracingResults(thread.all_slices, results)
114 def CleanUpAfterPage(self, page, tab):
115 if tab.browser.platform.tracing_controller.is_tracing_running:
116 tab.browser.platform.tracing_controller.Stop()
119 class OilpanGCTimesForSmoothness(_OilpanGCTimesBase):
120 def __init__(self):
121 super(OilpanGCTimesForSmoothness, self).__init__('RunPageInteractions')
122 self._interaction = None
124 def WillRunActions(self, page, tab):
125 runner = action_runner.ActionRunner(tab)
126 self._interaction = runner.BeginInteraction(_RUN_SMOOTH_ACTIONS,
127 is_smooth=True)
129 def DidRunActions(self, page, tab):
130 self._interaction.End()
131 super(OilpanGCTimesForSmoothness, self).DidRunActions(page, tab)
134 class OilpanGCTimesForBlinkPerf(_OilpanGCTimesBase):
135 def __init__(self):
136 super(OilpanGCTimesForBlinkPerf, self).__init__()
137 with open(os.path.join(os.path.dirname(__file__), '..', 'benchmarks',
138 'blink_perf.js'), 'r') as f:
139 self._blink_perf_js = f.read()
141 def WillNavigateToPage(self, page, tab):
142 page.script_to_evaluate_on_commit = self._blink_perf_js
143 super(OilpanGCTimesForBlinkPerf, self).WillNavigateToPage(page, tab)
145 def DidRunActions(self, page, tab):
146 tab.WaitForJavaScriptExpression('testRunner.isDone', 600)
147 super(OilpanGCTimesForBlinkPerf, self).DidRunActions(page, tab)
150 class OilpanGCTimesForInternals(_OilpanGCTimesBase):
151 def __init__(self):
152 super(OilpanGCTimesForInternals, self).__init__()
154 @classmethod
155 def CustomizeBrowserOptions(cls, options):
156 # 'expose-internals-for-testing' can be enabled on content shell.
157 assert 'content-shell' in options.browser_type
158 options.AppendExtraBrowserArgs('--expose-internals-for-testing')