| 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): |
| 32 self._adb = adb | 32 self._adb = adb |
| 33 self._collector_thread = None | 33 self._collector_thread = None |
| 34 self._use_legacy_method = False | 34 self._use_legacy_method = False |
| 35 self._surface_before = None | 35 self._surface_before = None |
| 36 self._get_data_event = None | 36 self._get_data_event = None |
| 37 self._data_queue = None | 37 self._data_queue = None |
| 38 self._stop_event = None | 38 self._stop_event = None |
| 39 self._results = [] | 39 self._results = [] |
| 40 | 40 |
| 41 def __enter__(self): | |
| 42 self.Start() | |
| 43 | |
| 44 def Start(self): | 41 def Start(self): |
| 45 assert not self._collector_thread | 42 assert not self._collector_thread |
| 46 | 43 |
| 47 if self._ClearSurfaceFlingerLatencyData(): | 44 if self._ClearSurfaceFlingerLatencyData(): |
| 48 self._get_data_event = threading.Event() | 45 self._get_data_event = threading.Event() |
| 49 self._stop_event = threading.Event() | 46 self._stop_event = threading.Event() |
| 50 self._data_queue = Queue.Queue() | 47 self._data_queue = Queue.Queue() |
| 51 self._collector_thread = threading.Thread(target=self._CollectorThread) | 48 self._collector_thread = threading.Thread(target=self._CollectorThread) |
| 52 self._collector_thread.start() | 49 self._collector_thread.start() |
| 53 else: | 50 else: |
| 54 self._use_legacy_method = True | 51 self._use_legacy_method = True |
| 55 self._surface_before = self._GetSurfaceStatsLegacy() | 52 self._surface_before = self._GetSurfaceStatsLegacy() |
| 56 | 53 |
| 57 def __exit__(self, *args): | |
| 58 self.Stop() | |
| 59 | |
| 60 def Stop(self): | 54 def Stop(self): |
| 61 self._StorePerfResults() | 55 self._StorePerfResults() |
| 62 if self._collector_thread: | 56 if self._collector_thread: |
| 63 self._stop_event.set() | 57 self._stop_event.set() |
| 64 self._collector_thread.join() | 58 self._collector_thread.join() |
| 65 self._collector_thread = None | 59 self._collector_thread = None |
| 66 | 60 |
| 67 def GetResults(self): | 61 def GetResults(self): |
| 68 return self._results | 62 return self._results |
| 69 | 63 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 try: | 238 try: |
| 245 cur_surface = int(match.group(1), 16) | 239 cur_surface = int(match.group(1), 16) |
| 246 except Exception: | 240 except Exception: |
| 247 logging.error('Failed to parse current surface from ' + match.group(1)) | 241 logging.error('Failed to parse current surface from ' + match.group(1)) |
| 248 else: | 242 else: |
| 249 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) | 243 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) |
| 250 return { | 244 return { |
| 251 'page_flip_count': cur_surface, | 245 'page_flip_count': cur_surface, |
| 252 'timestamp': datetime.datetime.now(), | 246 'timestamp': datetime.datetime.now(), |
| 253 } | 247 } |
| OLD | NEW |