OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 | 4 |
5 from metrics import Metric | 5 from metrics import Metric |
6 from metrics import rendering_stats | 6 from metrics import rendering_stats |
7 from metrics import statistics | 7 from metrics import statistics |
8 from telemetry.core.timeline.model import MarkerMismatchError | 8 from telemetry.core.timeline.model import MarkerMismatchError |
9 from telemetry.core.timeline.model import MarkerOverlapError | 9 from telemetry.core.timeline.model import MarkerOverlapError |
10 from telemetry.page import page_measurement | 10 from telemetry.page import page_measurement |
11 | 11 |
12 TIMELINE_MARKER = 'SmoothnessMetric' | 12 TIMELINE_MARKER = 'Smoothness' |
13 | 13 |
14 | 14 |
15 class NotEnoughFramesError(page_measurement.MeasurementFailure): | 15 class NotEnoughFramesError(page_measurement.MeasurementFailure): |
16 def __init__(self): | 16 def __init__(self): |
17 super(NotEnoughFramesError, self).__init__( | 17 super(NotEnoughFramesError, self).__init__( |
18 'Page output less than two frames') | 18 'Page output less than two frames') |
19 | 19 |
20 | 20 |
21 class NoSupportedActionError(page_measurement.MeasurementFailure): | 21 class NoSupportedActionError(page_measurement.MeasurementFailure): |
22 def __init__(self): | 22 def __init__(self): |
23 super(NoSupportedActionError, self).__init__( | 23 super(NoSupportedActionError, self).__init__( |
24 'None of the actions is supported by smoothness measurement') | 24 'None of the actions is supported by smoothness measurement') |
25 | 25 |
26 | 26 |
27 def GetTimelineMarkerLabelsFromAction(compound_action): | 27 def GetTimelineMarkerNamesFromAction(compound_action): |
28 timeline_marker_labels = [] | 28 timeline_marker_names = [] |
29 if not isinstance(compound_action, list): | 29 if not isinstance(compound_action, list): |
30 compound_action = [compound_action] | 30 compound_action = [compound_action] |
31 for action in compound_action: | 31 for action in compound_action: |
32 if action.GetTimelineMarkerLabel(): | 32 if action.GetTimelineMarkerName(): |
33 timeline_marker_labels.append(action.GetTimelineMarkerLabel()) | 33 timeline_marker_names.append(action.GetTimelineMarkerName()) |
34 if not timeline_marker_labels: | 34 if not timeline_marker_names: |
35 raise NoSupportedActionError() | 35 raise NoSupportedActionError() |
36 return timeline_marker_labels | 36 return timeline_marker_names |
37 | 37 |
38 | 38 |
39 class SmoothnessMetric(Metric): | 39 class SmoothnessMetric(Metric): |
40 def __init__(self, compound_action): | 40 def __init__(self, compound_action): |
41 super(SmoothnessMetric, self).__init__() | 41 super(SmoothnessMetric, self).__init__() |
42 self._stats = None | 42 self._stats = None |
43 self._compound_action = compound_action | 43 self._compound_action = compound_action |
44 | 44 |
45 def Start(self, page, tab): | 45 def Start(self, page, tab): |
46 # TODO(ermst): Remove "webkit" category after Blink r157377 is picked up by | 46 # TODO(ermst): Remove "webkit" category after Blink r157377 is picked up by |
47 # the reference builds. | 47 # the reference builds. |
48 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) | 48 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) |
49 tab.ExecuteJavaScript('console.time("' + TIMELINE_MARKER + '")') | 49 tab.ExecuteJavaScript('console.time("' + TIMELINE_MARKER + '")') |
50 | 50 |
51 def Stop(self, page, tab): | 51 def Stop(self, page, tab): |
52 tab.ExecuteJavaScript('console.timeEnd("' + TIMELINE_MARKER + '")') | 52 tab.ExecuteJavaScript('console.timeEnd("' + TIMELINE_MARKER + '")') |
53 timeline_model = tab.browser.StopTracing().AsTimelineModel() | 53 timeline_model = tab.browser.StopTracing().AsTimelineModel() |
54 render_process_marker = timeline_model.FindTimelineMarkers(TIMELINE_MARKER) | 54 smoothness_marker = timeline_model.FindTimelineMarkers(TIMELINE_MARKER) |
55 timeline_marker_labels = GetTimelineMarkerLabelsFromAction( | 55 timeline_marker_names = GetTimelineMarkerNamesFromAction( |
56 self._compound_action) | 56 self._compound_action) |
57 try: | 57 try: |
58 timeline_markers = timeline_model.FindTimelineMarkers( | 58 timeline_markers = timeline_model.FindTimelineMarkers( |
59 timeline_marker_labels) | 59 timeline_marker_names) |
60 except MarkerMismatchError: | 60 except MarkerMismatchError: |
61 # TODO(ernstm): re-raise exception as MeasurementFailure when the | 61 # TODO(ernstm): re-raise exception as MeasurementFailure when the |
62 # reference build was updated. | 62 # reference build was updated. |
63 timeline_markers = render_process_marker | 63 timeline_markers = smoothness_marker |
64 except MarkerOverlapError as e: | 64 except MarkerOverlapError as e: |
65 raise page_measurement.MeasurementFailure(str(e)) | 65 raise page_measurement.MeasurementFailure(str(e)) |
66 | 66 |
| 67 renderer_process = timeline_model.GetRendererProcessFromTab(tab) |
67 self._stats = rendering_stats.RenderingStats( | 68 self._stats = rendering_stats.RenderingStats( |
68 render_process_marker, timeline_markers) | 69 renderer_process, timeline_markers) |
69 | 70 |
70 if not self._stats.frame_times: | 71 if not self._stats.frame_times: |
71 raise NotEnoughFramesError() | 72 raise NotEnoughFramesError() |
72 | 73 |
| 74 def SetStats(self, stats): |
| 75 """ Pass in a RenderingStats object directly. For unittests that don't call |
| 76 Start/Stop. |
| 77 """ |
| 78 self._stats = stats |
73 | 79 |
74 def AddResults(self, tab, results): | 80 def AddResults(self, tab, results): |
75 # List of raw frame times. | 81 # List of raw frame times. |
76 results.Add('frame_times', 'ms', self._stats.frame_times) | 82 results.Add('frame_times', 'ms', self._stats.frame_times) |
77 | 83 |
78 # Arithmetic mean of frame times. | 84 # Arithmetic mean of frame times. |
79 mean_frame_time = statistics.ArithmeticMean(self._stats.frame_times, | 85 mean_frame_time = statistics.ArithmeticMean(self._stats.frame_times, |
80 len(self._stats.frame_times)) | 86 len(self._stats.frame_times)) |
81 results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3)) | 87 results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3)) |
82 | 88 |
83 # Absolute discrepancy of frame time stamps. | 89 # Absolute discrepancy of frame time stamps. |
84 jank = statistics.FrameDiscrepancy(self._stats.frame_timestamps) | 90 jank = statistics.FrameDiscrepancy(self._stats.frame_timestamps) |
85 results.Add('jank', '', round(jank, 4)) | 91 results.Add('jank', '', round(jank, 4)) |
86 | 92 |
87 # Are we hitting 60 fps for 95 percent of all frames? | 93 # Are we hitting 60 fps for 95 percent of all frames? |
88 # We use 17ms as a slightly looser threshold, instead of 1000.0/60.0. | 94 # We use 17ms as a slightly looser threshold, instead of 1000.0/60.0. |
89 percentile_95 = statistics.Percentile(self._stats.frame_times, 95.0) | 95 percentile_95 = statistics.Percentile(self._stats.frame_times, 95.0) |
90 results.Add('mostly_smooth', '', 1.0 if percentile_95 < 17.0 else 0.0) | 96 results.Add('mostly_smooth', '', 1.0 if percentile_95 < 17.0 else 0.0) |
OLD | NEW |