Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 from telemetry.core.platform import tracing_category_filter | |
| 6 from telemetry.core.platform import tracing_options | |
| 7 from telemetry.timeline.model import TimelineModel | |
| 8 from telemetry.page import page_test | |
| 9 from telemetry.util import statistics | |
| 10 from telemetry.value import scalar | |
| 11 from telemetry.value import skip | |
| 12 | |
| 13 _CATEGORIES = ['webkit.console', | |
| 14 'blink.console', | |
| 15 'benchmark', | |
| 16 'toplevel', | |
| 17 'blink', | |
| 18 'cc', | |
| 19 'v8'] | |
| 20 | |
| 21 _TIME_OUT_IN_SECONDS = 60 | |
| 22 _NUMBER_OF_RESULTS_TO_DISPLAY = 10 | |
| 23 | |
| 24 class TaskExecutionTime(page_test.PageTest): | |
| 25 | |
|
Sami
2014/10/09 10:28:14
Extra blank line here.
picksi1
2014/10/09 13:02:20
Done.
| |
| 26 def __init__(self): | |
| 27 super(TaskExecutionTime, self).__init__('RunTaskExecutionTime') | |
| 28 self._renderer_thread = None | |
| 29 | |
| 30 def WillNavigateToPage(self, page, tab): | |
| 31 category_filter = tracing_category_filter.TracingCategoryFilter() | |
| 32 | |
| 33 for category in _CATEGORIES: | |
| 34 category_filter.AddIncludedCategory(category) | |
| 35 | |
| 36 options = tracing_options.TracingOptions() | |
| 37 options.enable_chrome_trace = True | |
| 38 | |
| 39 tab.browser.platform.tracing_controller.Start( | |
| 40 options, category_filter, _TIME_OUT_IN_SECONDS) | |
| 41 | |
| 42 def DidRunActions(self, page, tab): | |
| 43 timeline_data = tab.browser.platform.tracing_controller.Stop() | |
| 44 timeline_model = TimelineModel(timeline_data=timeline_data) | |
| 45 self._renderer_thread = timeline_model.GetRendererThreadFromTabId(tab.id) | |
| 46 | |
| 47 def ValidateAndMeasurePage(self, page, tab, results): | |
| 48 tasks = self.GetTasks(self._renderer_thread.parent) | |
| 49 | |
| 50 sorted_tasks = sorted(tasks, | |
| 51 key = lambda slice: slice.medianSelfDuration, reverse = True) | |
| 52 | |
| 53 # Tell summary code to not generate results for single pages as it makes | |
| 54 # the results page difficult to read | |
| 55 results.AddValue(skip.SkipValue.SetOnlyShowingSummaries(page)) | |
| 56 | |
| 57 for task in sorted_tasks[:_NUMBER_OF_RESULTS_TO_DISPLAY]: | |
| 58 results.AddValue(scalar.ScalarValue( | |
| 59 results.current_page, | |
| 60 task.key, | |
| 61 'ms', | |
| 62 task.medianSelfDuration, | |
| 63 description = 'Slowest tasks')) | |
| 64 | |
| 65 def GetTasks(self, process): | |
| 66 task_dictionary = {} | |
| 67 depth = 1 | |
| 68 for parent, task_slice in enumerate( | |
| 69 process.IterAllSlicesOfName('MessageLoop::RunTask')): | |
| 70 ProcessTasksForSlice(task_dictionary, task_slice, depth, parent) | |
| 71 # Return dictionary flattened into a list | |
| 72 return task_dictionary.values() | |
| 73 | |
| 74 class SliceData: | |
| 75 def __init__(self, key, self_duration, total_duration, depth, parent): | |
| 76 self.key = key | |
| 77 self.count = 1 | |
| 78 | |
| 79 self.self_durations = [self_duration] | |
| 80 self.min_self_duration = self_duration | |
| 81 self.max_self_duration = self_duration | |
| 82 | |
| 83 self.total_durations = [total_duration] | |
| 84 self.min_total_duration = total_duration | |
| 85 self.max_total_duration = total_duration | |
| 86 | |
| 87 self.tree_location = [(depth, parent)] | |
| 88 | |
| 89 def Update(self, self_duration, total_duration, depth, parent): | |
| 90 self.count += 1 | |
| 91 | |
| 92 self.self_durations.append(self_duration) | |
| 93 self.min_self_duration = min(self.min_self_duration, self_duration) | |
| 94 self.max_self_duration = max(self.max_self_duration, self_duration) | |
| 95 | |
| 96 self.total_durations.append(total_duration) | |
| 97 self.min_total_duration = min(self.min_total_duration, total_duration) | |
| 98 self.max_total_duration = max(self.max_total_duration, total_duration) | |
| 99 | |
| 100 self.tree_location.append((depth, parent)) | |
| 101 | |
| 102 @property | |
| 103 def medianSelfDuration(self): | |
|
Sami
2014/10/09 10:28:14
hacker_style instead of camelCase please.
picksi1
2014/10/09 13:02:20
Done.
| |
| 104 return statistics.Median(self.self_durations) | |
| 105 | |
| 106 def ProcessTasksForSlice(dictionary, task_slice, depth, parent): | |
| 107 # Deal with TRACE_EVENT_INSTANTs that have no duration | |
| 108 self_duration = task_slice.self_thread_time or 0.0 | |
| 109 total_duration = task_slice.thread_duration or 0.0 | |
| 110 | |
| 111 # There is at least one task that is tracked as both uppercase and lowercase, | |
| 112 # forcing the name to lowercase coalesces both. | |
| 113 key = task_slice.name.lower() | |
| 114 if key in dictionary: | |
| 115 dictionary[key].Update( | |
| 116 self_duration, total_duration, depth, parent) | |
| 117 else: | |
| 118 dictionary[key] = SliceData( | |
| 119 key, self_duration, total_duration, depth, parent) | |
| 120 | |
| 121 # Process sub slices recursively | |
| 122 for sub_slice in task_slice.sub_slices: | |
| 123 ProcessTasksForSlice(dictionary, sub_slice, depth + 1, parent) | |
| OLD | NEW |