OLD | NEW |
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 |
(...skipping 10 matching lines...) Expand all Loading... |
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): | 25 class Result(object): |
26 def __init__(self, name, value, unit): | 26 def __init__(self, name, value, unit): |
27 self.name = name | 27 self.name = name |
28 self.value = value | 28 self.value = value |
29 self.unit = unit | 29 self.unit = unit |
30 | 30 |
31 def __init__(self, adb, trace_tag): | 31 def __init__(self, adb, trace_tag=''): |
32 self._adb = adb | 32 self._adb = adb |
33 self._trace_tag = trace_tag | |
34 self._collector_thread = None | 33 self._collector_thread = None |
35 self._use_legacy_method = False | 34 self._use_legacy_method = False |
36 self._surface_before = None | 35 self._surface_before = None |
37 self._get_data_event = None | 36 self._get_data_event = None |
38 self._data_queue = None | 37 self._data_queue = None |
39 self._stop_event = None | 38 self._stop_event = None |
40 self._print_perf_results = True | |
41 self._results = [] | 39 self._results = [] |
42 | 40 |
43 def __enter__(self): | 41 def __enter__(self): |
| 42 self.Start() |
| 43 |
| 44 def Start(self): |
44 assert not self._collector_thread | 45 assert not self._collector_thread |
45 | 46 |
46 if self._ClearSurfaceFlingerLatencyData(): | 47 if self._ClearSurfaceFlingerLatencyData(): |
47 self._get_data_event = threading.Event() | 48 self._get_data_event = threading.Event() |
48 self._stop_event = threading.Event() | 49 self._stop_event = threading.Event() |
49 self._data_queue = Queue.Queue() | 50 self._data_queue = Queue.Queue() |
50 self._collector_thread = threading.Thread(target=self._CollectorThread) | 51 self._collector_thread = threading.Thread(target=self._CollectorThread) |
51 self._collector_thread.start() | 52 self._collector_thread.start() |
52 else: | 53 else: |
53 self._use_legacy_method = True | 54 self._use_legacy_method = True |
54 self._surface_before = self._GetSurfaceStatsLegacy() | 55 self._surface_before = self._GetSurfaceStatsLegacy() |
55 | 56 |
56 def __exit__(self, *args): | 57 def __exit__(self, *args): |
| 58 self.Stop() |
| 59 |
| 60 def Stop(self): |
57 self._StorePerfResults() | 61 self._StorePerfResults() |
58 self._PrintPerfResults() | |
59 if self._collector_thread: | 62 if self._collector_thread: |
60 self._stop_event.set() | 63 self._stop_event.set() |
61 self._collector_thread.join() | 64 self._collector_thread.join() |
62 self._collector_thread = None | 65 self._collector_thread = None |
63 | 66 |
64 def GetResults(self): | 67 def GetResults(self): |
65 return self._results | 68 return self._results |
66 | 69 |
67 def SuppressPrintingResults(self): | |
68 self._print_perf_results = False | |
69 | |
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): | 70 def _StorePerfResults(self): |
78 if self._use_legacy_method: | 71 if self._use_legacy_method: |
79 surface_after = self._GetSurfaceStatsLegacy() | 72 surface_after = self._GetSurfaceStatsLegacy() |
80 td = surface_after['timestamp'] - self._surface_before['timestamp'] | 73 td = surface_after['timestamp'] - self._surface_before['timestamp'] |
81 seconds = td.seconds + td.microseconds / 1e6 | 74 seconds = td.seconds + td.microseconds / 1e6 |
82 frame_count = (surface_after['page_flip_count'] - | 75 frame_count = (surface_after['page_flip_count'] - |
83 self._surface_before['page_flip_count']) | 76 self._surface_before['page_flip_count']) |
84 else: | 77 else: |
85 assert self._collector_thread | 78 assert self._collector_thread |
86 (seconds, latencies) = self._GetDataFromThread() | 79 (seconds, latencies) = self._GetDataFromThread() |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 try: | 244 try: |
252 cur_surface = int(match.group(1), 16) | 245 cur_surface = int(match.group(1), 16) |
253 except Exception: | 246 except Exception: |
254 logging.error('Failed to parse current surface from ' + match.group(1)) | 247 logging.error('Failed to parse current surface from ' + match.group(1)) |
255 else: | 248 else: |
256 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) | 249 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) |
257 return { | 250 return { |
258 'page_flip_count': cur_surface, | 251 'page_flip_count': cur_surface, |
259 'timestamp': datetime.datetime.now(), | 252 'timestamp': datetime.datetime.now(), |
260 } | 253 } |
OLD | NEW |