OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import collections | 4 import collections |
5 | 5 |
6 from telemetry.web_perf.metrics import timeline_based_metric | 6 from telemetry.web_perf.metrics import timeline_based_metric |
7 from telemetry.value import scalar | 7 from telemetry.value import scalar |
8 | 8 |
9 | 9 |
10 class LoadTimesTimelineMetric(timeline_based_metric.TimelineBasedMetric): | 10 class LoadTimesTimelineMetric(timeline_based_metric.TimelineBasedMetric): |
11 def __init__(self): | 11 def __init__(self): |
12 super(LoadTimesTimelineMetric, self).__init__() | 12 super(LoadTimesTimelineMetric, self).__init__() |
13 self.report_main_thread_only = True | 13 self.report_main_thread_only = True |
14 | 14 |
15 def AddResults(self, model, renderer_thread, interaction_records, results): | 15 def AddResults(self, model, interaction_records, results): |
16 assert model | 16 assert model |
17 assert len(interaction_records) == 1, ( | 17 assert len(interaction_records) == 1, ( |
18 'LoadTimesTimelineMetric cannot compute metrics for more than 1 time ' | 18 'LoadTimesTimelineMetric cannot compute metrics for more than 1 time ' |
19 'range.') | 19 'range.') |
| 20 self.VerifyAllRecordsIssuedBySameThread(interaction_records) |
20 interaction_record = interaction_records[0] | 21 interaction_record = interaction_records[0] |
| 22 renderer_thread = interaction_record.async_event.start_thread |
21 if self.report_main_thread_only: | 23 if self.report_main_thread_only: |
22 thread_filter = 'CrRendererMain' | 24 thread_filter = 'CrRendererMain' |
23 else: | 25 else: |
24 thread_filter = None | 26 thread_filter = None |
25 | 27 |
26 events_by_name = collections.defaultdict(list) | 28 events_by_name = collections.defaultdict(list) |
27 renderer_process = renderer_thread.parent | 29 renderer_process = renderer_thread.parent |
28 | 30 |
29 for thread in renderer_process.threads.itervalues(): | 31 for thread in renderer_process.threads.itervalues(): |
30 | 32 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 self.results_to_report = AllThreads | 219 self.results_to_report = AllThreads |
218 self.details_to_report = NoThreads | 220 self.details_to_report = NoThreads |
219 | 221 |
220 def CountSlices(self, slices, substring): | 222 def CountSlices(self, slices, substring): |
221 count = 0 | 223 count = 0 |
222 for event in slices: | 224 for event in slices: |
223 if substring in event.name: | 225 if substring in event.name: |
224 count += 1 | 226 count += 1 |
225 return count | 227 return count |
226 | 228 |
227 def AddResults(self, model, _, interaction_records, results): | 229 def AddResults(self, model, interaction_records, results): |
228 # Set up each thread category for consistant results. | 230 # Set up each thread category for consistant results. |
229 thread_category_results = {} | 231 thread_category_results = {} |
230 for name in TimelineThreadCategories.values(): | 232 for name in TimelineThreadCategories.values(): |
231 thread_category_results[name] = ResultsForThread( | 233 thread_category_results[name] = ResultsForThread( |
232 model, [r.GetBounds() for r in interaction_records], name) | 234 model, [r.GetBounds() for r in interaction_records], name) |
233 | 235 |
234 # Group the slices by their thread category. | 236 # Group the slices by their thread category. |
235 for thread in model.GetAllThreads(): | 237 for thread in model.GetAllThreads(): |
236 thread_category = ThreadCategoryName(thread.name) | 238 thread_category = ThreadCategoryName(thread.name) |
237 thread_category_results[thread_category].AppendThreadSlices(thread) | 239 thread_category_results[thread_category].AppendThreadSlices(thread) |
(...skipping 12 matching lines...) Expand all Loading... |
250 num_frames = self.CountSlices(frame_slices, FrameTraceName) | 252 num_frames = self.CountSlices(frame_slices, FrameTraceName) |
251 | 253 |
252 # Report the desired results and details. | 254 # Report the desired results and details. |
253 for thread_results in thread_category_results.values(): | 255 for thread_results in thread_category_results.values(): |
254 if thread_results.name in self.results_to_report: | 256 if thread_results.name in self.results_to_report: |
255 thread_results.AddResults(num_frames, results) | 257 thread_results.AddResults(num_frames, results) |
256 # TOOD(nduca): When generic results objects are done, this special case | 258 # TOOD(nduca): When generic results objects are done, this special case |
257 # can be replaced with a generic UI feature. | 259 # can be replaced with a generic UI feature. |
258 if thread_results.name in self.details_to_report: | 260 if thread_results.name in self.details_to_report: |
259 thread_results.AddDetailedResults(num_frames, results) | 261 thread_results.AddDetailedResults(num_frames, results) |
OLD | NEW |