| 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 sys | 4 import sys |
| 5 | 5 |
| 6 from measurements import smooth_gesture_util | 6 from measurements import smooth_gesture_util |
| 7 from telemetry.core.platform import tracing_category_filter | 7 from telemetry.core.platform import tracing_category_filter |
| 8 from telemetry.core.platform import tracing_options | 8 from telemetry.core.platform import tracing_options |
| 9 from telemetry.timeline import trace_data as trace_data_module | 9 from telemetry.timeline import trace_data as trace_data_module |
| 10 from telemetry.timeline.model import TimelineModel | 10 from telemetry.timeline.model import TimelineModel |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 category_filter.AddIncludedCategory(c) | 37 category_filter.AddIncludedCategory(c) |
| 38 options = tracing_options.TracingOptions() | 38 options = tracing_options.TracingOptions() |
| 39 options.enable_chrome_trace = True | 39 options.enable_chrome_trace = True |
| 40 options.enable_platform_display_trace = True | 40 options.enable_platform_display_trace = True |
| 41 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) | 41 tab.browser.platform.tracing_controller.Start(options, category_filter, 60) |
| 42 | 42 |
| 43 def Start(self, tab): | 43 def Start(self, tab): |
| 44 # Start the smooth marker for all smooth actions. | 44 # Start the smooth marker for all smooth actions. |
| 45 runner = action_runner.ActionRunner(tab) | 45 runner = action_runner.ActionRunner(tab) |
| 46 self._interaction = runner.BeginInteraction( | 46 self._interaction = runner.BeginInteraction( |
| 47 RUN_SMOOTH_ACTIONS, is_smooth=True) | 47 RUN_SMOOTH_ACTIONS) |
| 48 | 48 |
| 49 def Stop(self, tab): | 49 def Stop(self, tab): |
| 50 # End the smooth marker for all smooth actions. | 50 # End the smooth marker for all smooth actions. |
| 51 self._interaction.End() | 51 self._interaction.End() |
| 52 self._trace_data = tab.browser.platform.tracing_controller.Stop() | 52 self._trace_data = tab.browser.platform.tracing_controller.Stop() |
| 53 self._timeline_model = TimelineModel(self._trace_data) | 53 self._timeline_model = TimelineModel(self._trace_data) |
| 54 | 54 |
| 55 def AddResults(self, tab, results): | 55 def AddResults(self, tab, results): |
| 56 # Add results of smoothness metric. This computes the smoothness metric for | 56 # Add results of smoothness metric. This computes the smoothness metric for |
| 57 # the time ranges of gestures, if there is at least one, else the the time | 57 # the time ranges of gestures, if there is at least one, else the the time |
| 58 # ranges from the first action to the last action. | 58 # ranges from the first action to the last action. |
| 59 results.AddValue(trace.TraceValue( | 59 results.AddValue(trace.TraceValue( |
| 60 results.current_page, self._trace_data)) | 60 results.current_page, self._trace_data)) |
| 61 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( | 61 renderer_thread = self._timeline_model.GetRendererThreadFromTabId( |
| 62 tab.id) | 62 tab.id) |
| 63 run_smooth_actions_record = None | 63 run_smooth_actions_record = None |
| 64 smooth_records = [] | 64 smooth_records = [] |
| 65 for event in renderer_thread.async_slices: | 65 for event in renderer_thread.async_slices: |
| 66 if not tir_module.IsTimelineInteractionRecord(event.name): | 66 if not tir_module.IsTimelineInteractionRecord(event.name): |
| 67 continue | 67 continue |
| 68 r = tir_module.TimelineInteractionRecord.FromAsyncEvent(event) | 68 r = tir_module.TimelineInteractionRecord.FromAsyncEvent(event) |
| 69 if r.label == RUN_SMOOTH_ACTIONS: | 69 if r.label == RUN_SMOOTH_ACTIONS: |
| 70 assert run_smooth_actions_record is None, ( | 70 assert run_smooth_actions_record is None, ( |
| 71 'SmoothnessController cannot issue more than 1 %s record' % | 71 'SmoothnessController cannot issue more than 1 %s record' % |
| 72 RUN_SMOOTH_ACTIONS) | 72 RUN_SMOOTH_ACTIONS) |
| 73 run_smooth_actions_record = r | 73 run_smooth_actions_record = r |
| 74 elif r.is_smooth: | 74 else: |
| 75 smooth_records.append( | 75 smooth_records.append( |
| 76 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( | 76 smooth_gesture_util.GetAdjustedInteractionIfContainGesture( |
| 77 self._timeline_model, r)) | 77 self._timeline_model, r)) |
| 78 | 78 |
| 79 # If there is no other smooth records, we make measurements on time range | 79 # If there is no other smooth records, we make measurements on time range |
| 80 # marked smoothness_controller itself. | 80 # marked smoothness_controller itself. |
| 81 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that | 81 # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that |
| 82 # page sets are responsible for issueing the markers themselves. | 82 # page sets are responsible for issueing the markers themselves. |
| 83 if len(smooth_records) == 0: | 83 if len(smooth_records) == 0: |
| 84 if run_smooth_actions_record is None: | 84 if run_smooth_actions_record is None: |
| 85 sys.stderr.write('Raw tracing data:\n') | 85 sys.stderr.write('Raw tracing data:\n') |
| 86 self._trace_data.Serialize(sys.stderr) | 86 self._trace_data.Serialize(sys.stderr) |
| 87 sys.stderr.write('\n') | 87 sys.stderr.write('\n') |
| 88 raise Exception('SmoothnessController failed to issue markers for the ' | 88 raise Exception('SmoothnessController failed to issue markers for the ' |
| 89 'whole interaction.') | 89 'whole interaction.') |
| 90 else: | 90 else: |
| 91 smooth_records = [run_smooth_actions_record] | 91 smooth_records = [run_smooth_actions_record] |
| 92 | 92 |
| 93 # Create an interaction_record for this legacy measurement. Since we don't | 93 # Create an interaction_record for this legacy measurement. Since we don't |
| 94 # wrap the results that are sent to smoothness metric, the label will | 94 # wrap the results that are sent to smoothness metric, the label will |
| 95 # not be used. | 95 # not be used. |
| 96 smoothness_metric = smoothness.SmoothnessMetric() | 96 smoothness_metric = smoothness.SmoothnessMetric() |
| 97 smoothness_metric.AddResults( | 97 smoothness_metric.AddResults( |
| 98 self._timeline_model, renderer_thread, smooth_records, results) | 98 self._timeline_model, renderer_thread, smooth_records, results) |
| 99 | 99 |
| 100 def CleanUp(self, tab): | 100 def CleanUp(self, tab): |
| 101 if tab.browser.platform.tracing_controller.is_tracing_running: | 101 if tab.browser.platform.tracing_controller.is_tracing_running: |
| 102 tab.browser.platform.tracing_controller.Stop() | 102 tab.browser.platform.tracing_controller.Stop() |
| OLD | NEW |