Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: build/android/pylib/surface_stats_collector.py

Issue 12499006: Telemetry on android: improves RawDisplayFrameRateMeasurement. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/perf/perf_tools/smoothness_benchmark.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 import Queue 5 import Queue
6 import datetime 6 import datetime
7 import logging 7 import logging
8 import re 8 import re
9 import threading 9 import threading
10 10
11 from pylib import perf_tests_helper 11 from pylib import perf_tests_helper
12 12
13 13
14 # Log marker containing SurfaceTexture timestamps. 14 # Log marker containing SurfaceTexture timestamps.
15 _SURFACE_TEXTURE_TIMESTAMPS_MESSAGE = 'SurfaceTexture update timestamps' 15 _SURFACE_TEXTURE_TIMESTAMPS_MESSAGE = 'SurfaceTexture update timestamps'
16 _SURFACE_TEXTURE_TIMESTAMP_RE = '\d+' 16 _SURFACE_TEXTURE_TIMESTAMP_RE = '\d+'
17 17
18 18
19 class SurfaceStatsCollector(object): 19 class SurfaceStatsCollector(object):
20 """Collects surface stats for a SurfaceView from the output of SurfaceFlinger. 20 """Collects surface stats for a SurfaceView from the output of SurfaceFlinger.
21 21
22 Args: 22 Args:
23 adb: the adb connection to use. 23 adb: the adb connection to use.
24 """ 24 """
25 class Result(object):
26 def __init__(self, name, value, unit):
27 self.name = name
28 self.value = value
29 self.unit = unit
30
25 def __init__(self, adb, trace_tag): 31 def __init__(self, adb, trace_tag):
26 self._adb = adb 32 self._adb = adb
27 self._trace_tag = trace_tag 33 self._trace_tag = trace_tag
28 self._collector_thread = None 34 self._collector_thread = None
29 self._use_legacy_method = False 35 self._use_legacy_method = False
30 self._surface_before = None 36 self._surface_before = None
31 self._get_data_event = None 37 self._get_data_event = None
32 self._data_queue = None 38 self._data_queue = None
33 self._stop_event = None 39 self._stop_event = None
40 self._print_perf_results = True
41 self._results = []
34 42
35 def __enter__(self): 43 def __enter__(self):
36 assert not self._collector_thread 44 assert not self._collector_thread
37 45
38 if self._ClearSurfaceFlingerLatencyData(): 46 if self._ClearSurfaceFlingerLatencyData():
39 self._get_data_event = threading.Event() 47 self._get_data_event = threading.Event()
40 self._stop_event = threading.Event() 48 self._stop_event = threading.Event()
41 self._data_queue = Queue.Queue() 49 self._data_queue = Queue.Queue()
42 self._collector_thread = threading.Thread(target=self._CollectorThread) 50 self._collector_thread = threading.Thread(target=self._CollectorThread)
43 self._collector_thread.start() 51 self._collector_thread.start()
44 else: 52 else:
45 self._use_legacy_method = True 53 self._use_legacy_method = True
46 self._surface_before = self._GetSurfaceStatsLegacy() 54 self._surface_before = self._GetSurfaceStatsLegacy()
47 55
48 def __exit__(self, *args): 56 def __exit__(self, *args):
57 self._StorePerfResults()
49 self._PrintPerfResults() 58 self._PrintPerfResults()
50 if self._collector_thread: 59 if self._collector_thread:
51 self._stop_event.set() 60 self._stop_event.set()
52 self._collector_thread.join() 61 self._collector_thread.join()
53 self._collector_thread = None 62 self._collector_thread = None
54 63
64 def GetResults(self):
65 return self._results
66
67 def SuppressPrintingResults(self):
68 self._print_perf_results = False
69
55 def _PrintPerfResults(self): 70 def _PrintPerfResults(self):
71 if not self._print_perf_results:
72 return
73 for r in self._results:
74 perf_tests_helper.PrintPerfResult(r.name, r.name + self._trace_tag,
75 r.value, r.unit)
76
77 def _StorePerfResults(self):
56 if self._use_legacy_method: 78 if self._use_legacy_method:
57 surface_after = self._GetSurfaceStatsLegacy() 79 surface_after = self._GetSurfaceStatsLegacy()
58 td = surface_after['timestamp'] - self._surface_before['timestamp'] 80 td = surface_after['timestamp'] - self._surface_before['timestamp']
59 seconds = td.seconds + td.microseconds / 1e6 81 seconds = td.seconds + td.microseconds / 1e6
60 frame_count = (surface_after['page_flip_count'] - 82 frame_count = (surface_after['page_flip_count'] -
61 self._surface_before['page_flip_count']) 83 self._surface_before['page_flip_count'])
62 else: 84 else:
63 assert self._collector_thread 85 assert self._collector_thread
64 (seconds, latencies) = self._GetDataFromThread() 86 (seconds, latencies) = self._GetDataFromThread()
65 if not seconds or not len(latencies): 87 if not seconds or not len(latencies):
66 logging.warning('Surface stat data is empty') 88 logging.warning('Surface stat data is empty')
67 return 89 return
68 90
69 frame_count = len(latencies) 91 frame_count = len(latencies)
70 jitter_count = 0 92 jitter_count = 0
71 last_latency = latencies[0] 93 last_latency = latencies[0]
72 for latency in latencies[1:]: 94 for latency in latencies[1:]:
73 if latency > last_latency: 95 if latency > last_latency:
74 jitter_count = jitter_count + 1 96 jitter_count = jitter_count + 1
75 last_latency = latency 97 last_latency = latency
76 98
77 perf_tests_helper.PrintPerfResult( 99 self._results.append(SurfaceStatsCollector.Result(
78 'surface_latencies', 'surface_latencies' + self._trace_tag, 100 'surface_latencies', latencies, ''))
79 latencies, '') 101 self._results.append(SurfaceStatsCollector.Result(
80 perf_tests_helper.PrintPerfResult( 102 'peak_jitter', [max(latencies)], ''))
81 'peak_jitter', 'peak_jitter' + self._trace_tag, [max(latencies)], '') 103 self._results.append(SurfaceStatsCollector.Result(
82 perf_tests_helper.PrintPerfResult( 104 'jitter_percent', [jitter_count * 100.0 / frame_count], 'percent'))
83 'jitter_percent', 'jitter_percent' + self._trace_tag, 105 self._results.append(SurfaceStatsCollector.Result(
84 [jitter_count * 100.0 / frame_count], 'percent') 106 'avg_surface_fps', [int(round(frame_count / seconds))], 'fps'))
85
86 print 'SurfaceMonitorTime: %fsecs' % seconds
87 perf_tests_helper.PrintPerfResult(
88 'avg_surface_fps', 'avg_surface_fps' + self._trace_tag,
89 [int(round(frame_count / seconds))], 'fps')
90 107
91 def _CollectorThread(self): 108 def _CollectorThread(self):
92 last_timestamp = 0 109 last_timestamp = 0
93 first_timestamp = 0 110 first_timestamp = 0
94 latencies = [] 111 latencies = []
95 retries = 0 112 retries = 0
96 has_collected_data = False 113 has_collected_data = False
97 114
98 while not self._stop_event.is_set(): 115 while not self._stop_event.is_set():
99 self._get_data_event.wait(1) 116 self._get_data_event.wait(1)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 try: 251 try:
235 cur_surface = int(match.group(1), 16) 252 cur_surface = int(match.group(1), 16)
236 except Exception: 253 except Exception:
237 logging.error('Failed to parse current surface from ' + match.group(1)) 254 logging.error('Failed to parse current surface from ' + match.group(1))
238 else: 255 else:
239 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) 256 logging.warning('Failed to call SurfaceFlinger surface ' + results[0])
240 return { 257 return {
241 'page_flip_count': cur_surface, 258 'page_flip_count': cur_surface,
242 'timestamp': datetime.datetime.now(), 259 'timestamp': datetime.datetime.now(),
243 } 260 }
OLDNEW
« no previous file with comments | « no previous file | tools/perf/perf_tools/smoothness_benchmark.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698