Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / web_perf / metrics / smoothness.py
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
3 # found in the LICENSE file.
4
5 from telemetry.web_perf.metrics import timeline_based_metric
6 from telemetry.web_perf.metrics import rendering_stats
7 from telemetry.page.perf_tests_helper import FlattenList
8 from telemetry.util import statistics
9
10
11 class SmoothnessMetric(timeline_based_metric.TimelineBasedMetric):
12   def __init__(self):
13     super(SmoothnessMetric, self).__init__()
14
15   def AddResults(self, model, renderer_thread, interaction_records, results):
16     renderer_process = renderer_thread.parent
17     stats = rendering_stats.RenderingStats(
18       renderer_process, model.browser_process,
19       [r.GetBounds() for r in interaction_records])
20     if stats.mouse_wheel_scroll_latency:
21       mean_mouse_wheel_scroll_latency = statistics.ArithmeticMean(
22         stats.mouse_wheel_scroll_latency)
23       mouse_wheel_scroll_latency_discrepancy = statistics.DurationsDiscrepancy(
24         stats.mouse_wheel_scroll_latency)
25       results.Add('mean_mouse_wheel_scroll_latency', 'ms',
26                   round(mean_mouse_wheel_scroll_latency, 3))
27       results.Add('mouse_wheel_scroll_latency_discrepancy', 'ms',
28                   round(mouse_wheel_scroll_latency_discrepancy, 4))
29
30     if stats.touch_scroll_latency:
31       mean_touch_scroll_latency = statistics.ArithmeticMean(
32         stats.touch_scroll_latency)
33       touch_scroll_latency_discrepancy = statistics.DurationsDiscrepancy(
34         stats.touch_scroll_latency)
35       results.Add('mean_touch_scroll_latency', 'ms',
36                   round(mean_touch_scroll_latency, 3))
37       results.Add('touch_scroll_latency_discrepancy', 'ms',
38                   round(touch_scroll_latency_discrepancy, 4))
39
40     if stats.js_touch_scroll_latency:
41       mean_js_touch_scroll_latency = statistics.ArithmeticMean(
42         stats.js_touch_scroll_latency)
43       js_touch_scroll_latency_discrepancy = statistics.DurationsDiscrepancy(
44         stats.js_touch_scroll_latency)
45       results.Add('mean_js_touch_scroll_latency', 'ms',
46                   round(mean_js_touch_scroll_latency, 3))
47       results.Add('js_touch_scroll_latency_discrepancy', 'ms',
48                   round(js_touch_scroll_latency_discrepancy, 4))
49
50     # List of raw frame times.
51     frame_times = FlattenList(stats.frame_times)
52     results.Add('frame_times', 'ms', frame_times)
53
54     # Arithmetic mean of frame times.
55     mean_frame_time = statistics.ArithmeticMean(frame_times)
56     results.Add('mean_frame_time', 'ms', round(mean_frame_time, 3))
57
58     # Absolute discrepancy of frame time stamps.
59     frame_discrepancy = statistics.TimestampsDiscrepancy(
60       stats.frame_timestamps)
61     results.Add('jank', 'ms', round(frame_discrepancy, 4))
62
63     # Are we hitting 60 fps for 95 percent of all frames?
64     # We use 19ms as a somewhat looser threshold, instead of 1000.0/60.0.
65     percentile_95 = statistics.Percentile(frame_times, 95.0)
66     results.Add('mostly_smooth', 'score', 1.0 if percentile_95 < 19.0 else 0.0)
67
68     # Mean percentage of pixels approximated (missing tiles, low resolution
69     # tiles, non-ideal resolution tiles)
70     results.Add('mean_pixels_approximated', 'percent',
71                 round(statistics.ArithmeticMean(
72                     FlattenList(stats.approximated_pixel_percentages)), 3))