| 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.page import page_measurement | 8 from telemetry.page import page_measurement |
| 9 from telemetry.page.perf_tests_helper import FlattenList | 9 from telemetry.page.perf_tests_helper import FlattenList |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 def Stop(self, page, tab): | 59 def Stop(self, page, tab): |
| 60 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 60 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 61 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 61 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
| 62 tab.ExecuteJavaScript('console.timeEnd("' + TIMELINE_MARKER + '")') | 62 tab.ExecuteJavaScript('console.timeEnd("' + TIMELINE_MARKER + '")') |
| 63 timeline_model = tab.browser.StopTracing().AsTimelineModel() | 63 timeline_model = tab.browser.StopTracing().AsTimelineModel() |
| 64 timeline_ranges = [ action.GetActiveRangeOnTimeline(timeline_model) | 64 timeline_ranges = [ action.GetActiveRangeOnTimeline(timeline_model) |
| 65 for action in self._actions ] | 65 for action in self._actions ] |
| 66 | 66 |
| 67 renderer_process = timeline_model.GetRendererProcessFromTab(tab) | 67 renderer_process = timeline_model.GetRendererProcessFromTab(tab) |
| 68 self._stats = rendering_stats.RenderingStats( | 68 self._stats = rendering_stats.RenderingStats( |
| 69 renderer_process, timeline_ranges) | 69 renderer_process, timeline_model.browser_process, timeline_ranges) |
| 70 | 70 |
| 71 if not self._stats.frame_times: | 71 if not self._stats.frame_times: |
| 72 raise NotEnoughFramesError() | 72 raise NotEnoughFramesError() |
| 73 | 73 |
| 74 def SetStats(self, stats): | 74 def SetStats(self, stats): |
| 75 """ Pass in a RenderingStats object directly. For unittests that don't call | 75 """ Pass in a RenderingStats object directly. For unittests that don't call |
| 76 Start/Stop. | 76 Start/Stop. |
| 77 """ | 77 """ |
| 78 self._stats = stats | 78 self._stats = stats |
| 79 | 79 |
| 80 def AddResults(self, tab, results): | 80 def AddResults(self, tab, results): |
| 81 if self._stats.mouse_wheel_scroll_latency: |
| 82 mean_mouse_wheel_scroll_latency = statistics.ArithmeticMean( |
| 83 self._stats.mouse_wheel_scroll_latency, |
| 84 len(self._stats.mouse_wheel_scroll_latency)) |
| 85 results.Add('mean_mouse_wheel_scroll_latency', 'ms', |
| 86 round(mean_mouse_wheel_scroll_latency, 3)) |
| 87 |
| 88 if self._stats.touch_scroll_latency: |
| 89 mean_touch_scroll_latency = statistics.ArithmeticMean( |
| 90 self._stats.touch_scroll_latency, |
| 91 len(self._stats.touch_scroll_latency)) |
| 92 results.Add('mean_touch_scroll_latency', 'ms', |
| 93 round(mean_touch_scroll_latency, 3)) |
| 94 |
| 81 # List of raw frame times. | 95 # List of raw frame times. |
| 82 frame_times = FlattenList(self._stats.frame_times) | 96 frame_times = FlattenList(self._stats.frame_times) |
| 83 results.Add('frame_times', 'ms', frame_times) | 97 results.Add('frame_times', 'ms', frame_times) |
| 84 | 98 |
| 85 # Arithmetic mean of frame times. | 99 # Arithmetic mean of frame times. |
| 86 mean_frame_time = statistics.ArithmeticMean(frame_times, | 100 mean_frame_time = statistics.ArithmeticMean(frame_times, |
| 87 len(frame_times)) | 101 len(frame_times)) |
| 88 results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3)) | 102 results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3)) |
| 89 | 103 |
| 90 # Absolute discrepancy of frame time stamps. | 104 # Absolute discrepancy of frame time stamps. |
| 91 jank = statistics.FrameDiscrepancy(self._stats.frame_timestamps) | 105 jank = statistics.FrameDiscrepancy(self._stats.frame_timestamps) |
| 92 results.Add('jank', '', round(jank, 4)) | 106 results.Add('jank', '', round(jank, 4)) |
| 93 | 107 |
| 94 # Are we hitting 60 fps for 95 percent of all frames? | 108 # Are we hitting 60 fps for 95 percent of all frames? |
| 95 # We use 19ms as a somewhat looser threshold, instead of 1000.0/60.0. | 109 # We use 19ms as a somewhat looser threshold, instead of 1000.0/60.0. |
| 96 percentile_95 = statistics.Percentile(frame_times, 95.0) | 110 percentile_95 = statistics.Percentile(frame_times, 95.0) |
| 97 results.Add('mostly_smooth', 'score', 1.0 if percentile_95 < 19.0 else 0.0) | 111 results.Add('mostly_smooth', 'score', 1.0 if percentile_95 < 19.0 else 0.0) |
| 98 | 112 |
| 99 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 113 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 100 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | 114 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
| 101 if r.value is None: | 115 if r.value is None: |
| 102 raise MissingDisplayFrameRateError(r.name) | 116 raise MissingDisplayFrameRateError(r.name) |
| 103 results.Add(r.name, r.unit, r.value) | 117 results.Add(r.name, r.unit, r.value) |
| OLD | NEW |