Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 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. | |
| 4 | |
| 5 from telemetry.core.platform import tracing_category_filter | |
| 6 from telemetry.core.platform import tracing_options | |
| 7 from telemetry.page import page_test | |
| 8 from telemetry.timeline.model import TimelineModel | |
| 9 from telemetry.util import statistics | |
| 10 from telemetry.value import scalar | |
| 11 | |
| 12 | |
| 13 class V8GCTimes(page_test.PageTest): | |
| 14 | |
| 15 _TIME_OUT_IN_SECONDS = 60 | |
| 16 _CATEGORIES = ['blink.console', | |
| 17 'renderer.scheduler', | |
| 18 'toplevel', | |
| 19 'v8', | |
| 20 'webkit.console'] | |
| 21 _RENDERER_MAIN_THREAD = 'CrRendererMain' | |
| 22 _IDLE_TASK_PARENT = 'SingleThreadIdleTaskRunner::RunTask' | |
| 23 | |
| 24 def __init__(self): | |
| 25 super(V8GCTimes, self).__init__('RunPageInteractions') | |
| 26 self._v8_event_stats = [ | |
| 27 V8EventStat('V8.GCIncrementalMarking', | |
| 28 'gc_incremental_marking', | |
|
Sami
2015/02/04 19:19:28
I wonder if we should have v8 somewhere in the nam
rmcilroy
2015/02/05 16:23:25
Sounds good, done.
| |
| 29 'incremental marking steps'), | |
| 30 V8EventStat('V8.GCScavenger', | |
| 31 'gc_scavenger', | |
| 32 'scavenges'), | |
| 33 V8EventStat('V8.GCCompactor', | |
| 34 'gc_mark_compactor', | |
| 35 'mark-sweep-compactor')] | |
| 36 self._renderer_process = None | |
| 37 | |
| 38 def WillNavigateToPage(self, page, tab): | |
| 39 category_filter = tracing_category_filter.TracingCategoryFilter() | |
| 40 | |
| 41 for category in self._CATEGORIES: | |
| 42 category_filter.AddIncludedCategory(category) | |
| 43 | |
| 44 options = tracing_options.TracingOptions() | |
| 45 options.enable_chrome_trace = True | |
| 46 | |
| 47 tab.browser.platform.tracing_controller.Start( | |
| 48 options, category_filter, self._TIME_OUT_IN_SECONDS) | |
| 49 | |
| 50 def DidRunActions(self, page, tab): | |
| 51 trace_data = tab.browser.platform.tracing_controller.Stop() | |
| 52 timeline_model = TimelineModel(trace_data) | |
| 53 | |
| 54 self._renderer_process = timeline_model.GetRendererProcessFromTabId(tab.id) | |
| 55 | |
| 56 def ValidateAndMeasurePage(self, page, tab, results): | |
| 57 self._AddV8MetricsToResults(self._renderer_process, results) | |
| 58 | |
| 59 def _AddV8MetricsToResults(self, process, results): | |
| 60 if process is None: | |
| 61 return | |
| 62 | |
| 63 for thread in process.threads.values(): | |
| 64 if thread.name != self._RENDERER_MAIN_THREAD: | |
| 65 continue | |
| 66 | |
| 67 self._AddV8EventStatsToResults(thread, results) | |
| 68 self._AddCpuTimeStatsToResults(thread, results) | |
| 69 | |
| 70 def _AddV8EventStatsToResults(self, thread, results): | |
| 71 # Find all V8 GC events in the trace. | |
| 72 for event in thread.IterAllSlices(): | |
| 73 event_stat = _FindV8EventStatForEvent(self._v8_event_stats, event.name) | |
| 74 if event_stat: | |
|
Sami
2015/02/04 19:19:28
nit: this and the one below would be a little neat
rmcilroy
2015/02/05 16:23:25
Agree for this one, but not the one below. If you
Sami
2015/02/05 17:29:31
Ok :)
| |
| 75 event_stat.thread_duration += event.thread_duration | |
| 76 parent_idle_task = _ParentIdleTask(event) | |
| 77 if parent_idle_task: | |
| 78 allotted_idle_time = parent_idle_task.args['allotted_time_ms'] | |
| 79 idle_task_overrun = 0 | |
| 80 if event.thread_duration > allotted_idle_time: | |
| 81 idle_task_overrun = event.thread_duration - allotted_idle_time | |
|
Sami
2015/02/04 19:19:28
Should we be looking at the wall clock here instea
rmcilroy
2015/02/05 16:23:25
Hmm yeah, good point. I've done this, but it mean
Sami
2015/02/05 17:29:31
That seems like a reasonable assumption given the
| |
| 82 # Don't count time over the deadline as being inside idle time. | |
| 83 event_stat.thread_duration_inside_idle += ( | |
| 84 event.thread_duration - idle_task_overrun) | |
| 85 event_stat.idle_task_overrun_duration += idle_task_overrun | |
| 86 | |
| 87 for v8_event_stat in self._v8_event_stats: | |
| 88 results.AddValue(scalar.ScalarValue( | |
| 89 results.current_page, v8_event_stat.result_name, 'ms', | |
| 90 v8_event_stat.thread_duration, | |
| 91 'Total thread duration spent in ' + v8_event_stat.result_description)) | |
|
Sami
2015/02/04 19:19:29
nit: string interpolation would be a little easier
rmcilroy
2015/02/05 16:23:25
Done.
| |
| 92 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 93 v8_event_stat.result_name + '_outside_idle', 'ms', | |
| 94 v8_event_stat.thread_duration_outside_idle, | |
| 95 'Total thread duration spent in ' + v8_event_stat.result_description + | |
| 96 'outside of idle tasks')) | |
| 97 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 98 v8_event_stat.result_name + '_idle_deadline_overrun', 'ms', | |
| 99 v8_event_stat.idle_task_overrun_duration, | |
| 100 'Total idle task deadline overrun for ' + | |
| 101 v8_event_stat.result_description + 'idle tasks')) | |
| 102 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 103 v8_event_stat.result_name + '_percentage_idle', '%', | |
| 104 v8_event_stat.percentage_thread_duration_during_idle, | |
| 105 'Percentage of ' + v8_event_stat.result_description + | |
| 106 'spent in idle tasks')) | |
| 107 | |
| 108 # Add total metrics. | |
| 109 gc_total = sum(x.thread_duration for x in self._v8_event_stats) | |
| 110 gc_total_outside_idle = sum( | |
| 111 x.thread_duration_outside_idle for x in self._v8_event_stats) | |
| 112 gc_total_idle_deadline_overrun = sum( | |
| 113 x.idle_task_overrun_duration for x in self._v8_event_stats) | |
| 114 gc_total_percentage_idle = statistics.DivideIfPossibleOrZero( | |
| 115 100 * (gc_total - gc_total_outside_idle), gc_total) | |
| 116 | |
| 117 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 118 'gc_total', 'ms', gc_total, | |
| 119 'Total thread duration of all garbage collection events')) | |
| 120 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 121 'gc_total_outside_idle', 'ms', gc_total_outside_idle, | |
| 122 'Total thread duration of all garbage collection events outside of idle' | |
|
Sami
2015/02/04 19:19:29
Missing a space at end of string.
rmcilroy
2015/02/05 16:23:25
Done.
| |
| 123 'tasks')) | |
| 124 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 125 'gc_total_idle_deadline_overrun', 'ms', gc_total_idle_deadline_overrun, | |
| 126 'Total idle task deadline overrun for all idle tasks garbage collection' | |
|
Sami
2015/02/04 19:19:28
Missing a space at end of string.
rmcilroy
2015/02/05 16:23:25
Done.
| |
| 127 'events')) | |
| 128 results.AddValue(scalar.ScalarValue(results.current_page, | |
| 129 'gc_total_percentage_idle', '%', gc_total_percentage_idle, | |
| 130 'Percentage of the thread duration of all garbage collection events' | |
|
Sami
2015/02/04 19:19:28
Missing a space at end of string.
rmcilroy
2015/02/05 16:23:25
Done.
| |
| 131 'spent inside of idle tasks')) | |
| 132 | |
| 133 def _AddCpuTimeStatsToResults(self, thread, results): | |
| 134 if thread.toplevel_slices: | |
| 135 start_time = min(s.start for s in thread.toplevel_slices) | |
| 136 end_time = max(s.end for s in thread.toplevel_slices) | |
| 137 duration = end_time - start_time | |
| 138 cpu_time = sum(s.thread_duration for s in thread.toplevel_slices) | |
| 139 else: | |
| 140 duration = cpu_time = 0 | |
| 141 | |
| 142 results.AddValue(scalar.ScalarValue( | |
| 143 results.current_page, 'duration', 'ms', duration)) | |
| 144 results.AddValue(scalar.ScalarValue( | |
| 145 results.current_page, 'cpu_time', 'ms', cpu_time)) | |
| 146 | |
| 147 | |
| 148 def _FindV8EventStatForEvent(v8_event_stats_list, event_name): | |
| 149 for v8_event_stat in v8_event_stats_list: | |
| 150 if v8_event_stat.src_event_name == event_name: | |
| 151 return v8_event_stat | |
| 152 return None | |
| 153 | |
| 154 | |
| 155 def _ParentIdleTask(event): | |
| 156 parent = event.parent_slice | |
| 157 while parent: | |
| 158 if parent.name == V8GCTimes._IDLE_TASK_PARENT: | |
| 159 return parent | |
| 160 parent = parent.parent_slice | |
| 161 return None | |
| 162 | |
| 163 | |
| 164 class V8EventStat(object): | |
| 165 | |
| 166 def __init__(self, src_event_name, result_name, result_description): | |
| 167 self.src_event_name = src_event_name | |
| 168 self.result_name = result_name | |
| 169 self.result_description = result_description | |
| 170 self.thread_duration = 0.0 | |
| 171 self.thread_duration_inside_idle = 0.0 | |
| 172 self.idle_task_overrun_duration = 0.0 | |
| 173 | |
| 174 @property | |
| 175 def thread_duration_outside_idle(self): | |
| 176 return self.thread_duration - self.thread_duration_inside_idle | |
| 177 | |
| 178 @property | |
| 179 def percentage_thread_duration_during_idle(self): | |
| 180 return statistics.DivideIfPossibleOrZero( | |
| 181 100 * self.thread_duration_inside_idle, self.thread_duration) | |
| OLD | NEW |