| 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 timeline_based_metric | 5 from metrics import timeline_based_metric |
| 6 from metrics import rendering_stats | 6 from metrics import rendering_stats |
| 7 from metrics import statistics | |
| 8 from telemetry.core.timeline import bounds | 7 from telemetry.core.timeline import bounds |
| 9 from telemetry.page import page_measurement | 8 from telemetry.page import page_measurement |
| 10 from telemetry.page.perf_tests_helper import FlattenList | 9 from telemetry.page.perf_tests_helper import FlattenList |
| 10 from telemetry.util import statistics |
| 11 | 11 |
| 12 | 12 |
| 13 class NotEnoughFramesError(page_measurement.MeasurementFailure): | 13 class NotEnoughFramesError(page_measurement.MeasurementFailure): |
| 14 def __init__(self): | 14 def __init__(self): |
| 15 super(NotEnoughFramesError, self).__init__( | 15 super(NotEnoughFramesError, self).__init__( |
| 16 'Page output less than two frames') | 16 'Page output less than two frames') |
| 17 | 17 |
| 18 | 18 |
| 19 class NoSupportedActionError(page_measurement.MeasurementFailure): | 19 class NoSupportedActionError(page_measurement.MeasurementFailure): |
| 20 def __init__(self): | 20 def __init__(self): |
| 21 super(NoSupportedActionError, self).__init__( | 21 super(NoSupportedActionError, self).__init__( |
| 22 'None of the actions is supported by smoothness measurement') | 22 'None of the actions is supported by smoothness measurement') |
| 23 | 23 |
| 24 class SmoothnessMetric(timeline_based_metric.TimelineBasedMetric): | 24 class SmoothnessMetric(timeline_based_metric.TimelineBasedMetric): |
| 25 def __init__(self): | 25 def __init__(self): |
| 26 super(SmoothnessMetric, self).__init__() | 26 super(SmoothnessMetric, self).__init__() |
| 27 | 27 |
| 28 def AddResults(self, model, renderer_thread, interaction_record, results): | 28 def AddResults(self, model, renderer_thread, interaction_record, results): |
| 29 renderer_process = renderer_thread.parent | 29 renderer_process = renderer_thread.parent |
| 30 time_bounds = bounds.Bounds() | 30 time_bounds = bounds.Bounds() |
| 31 time_bounds.AddValue(interaction_record.start) | 31 time_bounds.AddValue(interaction_record.start) |
| 32 time_bounds.AddValue(interaction_record.end) | 32 time_bounds.AddValue(interaction_record.end) |
| 33 stats = rendering_stats.RenderingStats( | 33 stats = rendering_stats.RenderingStats( |
| 34 renderer_process, model.browser_process, [time_bounds]) | 34 renderer_process, model.browser_process, [time_bounds]) |
| 35 if stats.mouse_wheel_scroll_latency: | 35 if stats.mouse_wheel_scroll_latency: |
| 36 mean_mouse_wheel_scroll_latency = statistics.ArithmeticMean( | 36 mean_mouse_wheel_scroll_latency = statistics.ArithmeticMean( |
| 37 stats.mouse_wheel_scroll_latency, | 37 stats.mouse_wheel_scroll_latency) |
| 38 len(stats.mouse_wheel_scroll_latency)) | |
| 39 mouse_wheel_scroll_latency_discrepancy = statistics.DurationsDiscrepancy( | 38 mouse_wheel_scroll_latency_discrepancy = statistics.DurationsDiscrepancy( |
| 40 stats.mouse_wheel_scroll_latency) | 39 stats.mouse_wheel_scroll_latency) |
| 41 results.Add('mean_mouse_wheel_scroll_latency', 'ms', | 40 results.Add('mean_mouse_wheel_scroll_latency', 'ms', |
| 42 round(mean_mouse_wheel_scroll_latency, 3)) | 41 round(mean_mouse_wheel_scroll_latency, 3)) |
| 43 results.Add('mouse_wheel_scroll_latency_discrepancy', '', | 42 results.Add('mouse_wheel_scroll_latency_discrepancy', '', |
| 44 round(mouse_wheel_scroll_latency_discrepancy, 4)) | 43 round(mouse_wheel_scroll_latency_discrepancy, 4)) |
| 45 | 44 |
| 46 if stats.touch_scroll_latency: | 45 if stats.touch_scroll_latency: |
| 47 mean_touch_scroll_latency = statistics.ArithmeticMean( | 46 mean_touch_scroll_latency = statistics.ArithmeticMean( |
| 48 stats.touch_scroll_latency, | 47 stats.touch_scroll_latency) |
| 49 len(stats.touch_scroll_latency)) | |
| 50 touch_scroll_latency_discrepancy = statistics.DurationsDiscrepancy( | 48 touch_scroll_latency_discrepancy = statistics.DurationsDiscrepancy( |
| 51 stats.touch_scroll_latency) | 49 stats.touch_scroll_latency) |
| 52 results.Add('mean_touch_scroll_latency', 'ms', | 50 results.Add('mean_touch_scroll_latency', 'ms', |
| 53 round(mean_touch_scroll_latency, 3)) | 51 round(mean_touch_scroll_latency, 3)) |
| 54 results.Add('touch_scroll_latency_discrepancy', '', | 52 results.Add('touch_scroll_latency_discrepancy', '', |
| 55 round(touch_scroll_latency_discrepancy, 4)) | 53 round(touch_scroll_latency_discrepancy, 4)) |
| 56 | 54 |
| 57 if stats.js_touch_scroll_latency: | 55 if stats.js_touch_scroll_latency: |
| 58 mean_js_touch_scroll_latency = statistics.ArithmeticMean( | 56 mean_js_touch_scroll_latency = statistics.ArithmeticMean( |
| 59 stats.js_touch_scroll_latency, | 57 stats.js_touch_scroll_latency) |
| 60 len(stats.js_touch_scroll_latency)) | |
| 61 js_touch_scroll_latency_discrepancy = statistics.DurationsDiscrepancy( | 58 js_touch_scroll_latency_discrepancy = statistics.DurationsDiscrepancy( |
| 62 stats.js_touch_scroll_latency) | 59 stats.js_touch_scroll_latency) |
| 63 results.Add('mean_js_touch_scroll_latency', 'ms', | 60 results.Add('mean_js_touch_scroll_latency', 'ms', |
| 64 round(mean_js_touch_scroll_latency, 3)) | 61 round(mean_js_touch_scroll_latency, 3)) |
| 65 results.Add('js_touch_scroll_latency_discrepancy', '', | 62 results.Add('js_touch_scroll_latency_discrepancy', '', |
| 66 round(js_touch_scroll_latency_discrepancy, 4)) | 63 round(js_touch_scroll_latency_discrepancy, 4)) |
| 67 | 64 |
| 68 # List of raw frame times. | 65 # List of raw frame times. |
| 69 frame_times = FlattenList(stats.frame_times) | 66 frame_times = FlattenList(stats.frame_times) |
| 70 results.Add('frame_times', 'ms', frame_times) | 67 results.Add('frame_times', 'ms', frame_times) |
| 71 | 68 |
| 72 # Arithmetic mean of frame times. | 69 # Arithmetic mean of frame times. |
| 73 mean_frame_time = statistics.ArithmeticMean(frame_times, | 70 mean_frame_time = statistics.ArithmeticMean(frame_times) |
| 74 len(frame_times)) | |
| 75 results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3)) | 71 results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3)) |
| 76 | 72 |
| 77 # Absolute discrepancy of frame time stamps. | 73 # Absolute discrepancy of frame time stamps. |
| 78 frame_discrepancy = statistics.TimestampsDiscrepancy( | 74 frame_discrepancy = statistics.TimestampsDiscrepancy( |
| 79 stats.frame_timestamps) | 75 stats.frame_timestamps) |
| 80 results.Add('jank', 'ms', round(frame_discrepancy, 4)) | 76 results.Add('jank', 'ms', round(frame_discrepancy, 4)) |
| 81 | 77 |
| 82 # Are we hitting 60 fps for 95 percent of all frames? | 78 # Are we hitting 60 fps for 95 percent of all frames? |
| 83 # We use 19ms as a somewhat looser threshold, instead of 1000.0/60.0. | 79 # We use 19ms as a somewhat looser threshold, instead of 1000.0/60.0. |
| 84 percentile_95 = statistics.Percentile(frame_times, 95.0) | 80 percentile_95 = statistics.Percentile(frame_times, 95.0) |
| 85 results.Add('mostly_smooth', 'score', 1.0 if percentile_95 < 19.0 else 0.0) | 81 results.Add('mostly_smooth', 'score', 1.0 if percentile_95 < 19.0 else 0.0) |
| OLD | NEW |