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 import itertools | 5 import itertools |
6 | 6 |
7 from metrics import Metric | 7 from metrics import Metric |
8 from telemetry.core.timeline import bounds | 8 from telemetry.core.timeline import bounds |
9 from telemetry.page import page_measurement | 9 from telemetry.page import page_measurement |
10 | 10 |
11 TRACING_MODE = 'tracing-mode' | 11 TRACING_MODE = 'tracing-mode' |
12 TIMELINE_MODE = 'timeline-mode' | 12 TIMELINE_MODE = 'timeline-mode' |
13 | 13 |
| 14 # All tracing categories not disabled-by-default |
| 15 DEFAULT_TRACE_CATEGORIES = None |
| 16 |
| 17 # Categories for absolute minimum overhead tracing. This contains no |
| 18 # sub-traces of thread tasks, so it's only useful for capturing the |
| 19 # cpu-time spent on threads (as well as needed benchmark traces) |
| 20 MINIMAL_TRACE_CATEGORIES = ("toplevel," |
| 21 "benchmark," |
| 22 "cc-benchmark," |
| 23 "webkit.console," |
| 24 "trace_event_overhead") |
| 25 |
14 | 26 |
15 class MissingFramesError(page_measurement.MeasurementFailure): | 27 class MissingFramesError(page_measurement.MeasurementFailure): |
16 def __init__(self): | 28 def __init__(self): |
17 super(MissingFramesError, self).__init__( | 29 super(MissingFramesError, self).__init__( |
18 'No frames found in trace. Unable to normalize results.') | 30 'No frames found in trace. Unable to normalize results.') |
19 | 31 |
20 | 32 |
21 class TimelineMetric(Metric): | 33 class TimelineMetric(Metric): |
22 def __init__(self, mode): | 34 def __init__(self, mode): |
23 """ Initializes a TimelineMetric object. | 35 """ Initializes a TimelineMetric object. |
24 """ | 36 """ |
25 super(TimelineMetric, self).__init__() | 37 super(TimelineMetric, self).__init__() |
26 assert mode in (TRACING_MODE, TIMELINE_MODE) | 38 assert mode in (TRACING_MODE, TIMELINE_MODE) |
| 39 self.trace_categories = DEFAULT_TRACE_CATEGORIES |
27 self._mode = mode | 40 self._mode = mode |
28 self._model = None | 41 self._model = None |
29 self._renderer_process = None | 42 self._renderer_process = None |
30 self._actions = [] | 43 self._actions = [] |
31 self._action_ranges = [] | 44 self._action_ranges = [] |
32 | 45 |
33 def Start(self, page, tab): | 46 def Start(self, page, tab): |
34 """Starts gathering timeline data. | 47 """Starts gathering timeline data. |
35 | 48 |
36 mode: TRACING_MODE or TIMELINE_MODE | 49 mode: TRACING_MODE or TIMELINE_MODE |
37 """ | 50 """ |
38 self._model = None | 51 self._model = None |
39 if self._mode == TRACING_MODE: | 52 if self._mode == TRACING_MODE: |
40 if not tab.browser.supports_tracing: | 53 if not tab.browser.supports_tracing: |
41 raise Exception('Not supported') | 54 raise Exception('Not supported') |
42 tab.browser.StartTracing() | 55 tab.browser.StartTracing(self.trace_categories) |
43 else: | 56 else: |
44 assert self._mode == TIMELINE_MODE | 57 assert self._mode == TIMELINE_MODE |
45 tab.StartTimelineRecording() | 58 tab.StartTimelineRecording() |
46 | 59 |
47 def Stop(self, page, tab): | 60 def Stop(self, page, tab): |
48 if self._mode == TRACING_MODE: | 61 if self._mode == TRACING_MODE: |
49 trace_result = tab.browser.StopTracing() | 62 trace_result = tab.browser.StopTracing() |
50 self._model = trace_result.AsTimelineModel() | 63 self._model = trace_result.AsTimelineModel() |
51 self._renderer_process = self._model.GetRendererProcessFromTab(tab) | 64 self._renderer_process = self._model.GetRendererProcessFromTab(tab) |
52 self._action_ranges = [ action.GetActiveRangeOnTimeline(self._model) | 65 self._action_ranges = [ action.GetActiveRangeOnTimeline(self._model) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 idle_time_result = (float(idle_time) / num_frames) if num_frames else 0 | 289 idle_time_result = (float(idle_time) / num_frames) if num_frames else 0 |
277 results.Add(ThreadDetailResultName(self.name, "idle"), | 290 results.Add(ThreadDetailResultName(self.name, "idle"), |
278 'ms', idle_time_result) | 291 'ms', idle_time_result) |
279 | 292 |
280 | 293 |
281 class ThreadTimesTimelineMetric(TimelineMetric): | 294 class ThreadTimesTimelineMetric(TimelineMetric): |
282 def __init__(self): | 295 def __init__(self): |
283 super(ThreadTimesTimelineMetric, self).__init__(TRACING_MODE) | 296 super(ThreadTimesTimelineMetric, self).__init__(TRACING_MODE) |
284 self.results_to_report = AllThreads | 297 self.results_to_report = AllThreads |
285 self.details_to_report = NoThreads | 298 self.details_to_report = NoThreads |
| 299 self.trace_categories = MINIMAL_TRACE_CATEGORIES |
286 | 300 |
287 def CountSlices(self, slices, substring): | 301 def CountSlices(self, slices, substring): |
288 count = 0 | 302 count = 0 |
289 for event in slices: | 303 for event in slices: |
290 if substring in event.name: | 304 if substring in event.name: |
291 count += 1 | 305 count += 1 |
292 return count | 306 return count |
293 | 307 |
294 def AddResults(self, tab, results): | 308 def AddResults(self, tab, results): |
295 # We need at least one action or we won't count any slices. | 309 # We need at least one action or we won't count any slices. |
(...skipping 25 matching lines...) Expand all Loading... |
321 num_frames = self.CountSlices(frame_slices, FrameTraceName) | 335 num_frames = self.CountSlices(frame_slices, FrameTraceName) |
322 | 336 |
323 # Report the desired results and details. | 337 # Report the desired results and details. |
324 for thread_results in thread_category_results.values(): | 338 for thread_results in thread_category_results.values(): |
325 if thread_results.name in self.results_to_report: | 339 if thread_results.name in self.results_to_report: |
326 thread_results.AddResults(num_frames, results) | 340 thread_results.AddResults(num_frames, results) |
327 # TOOD(nduca): When generic results objects are done, this special case | 341 # TOOD(nduca): When generic results objects are done, this special case |
328 # can be replaced with a generic UI feature. | 342 # can be replaced with a generic UI feature. |
329 if thread_results.name in self.details_to_report: | 343 if thread_results.name in self.details_to_report: |
330 thread_results.AddDetailedResults(num_frames, results) | 344 thread_results.AddDetailedResults(num_frames, results) |
OLD | NEW |