| 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 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   64  |   64  | 
|   65   def SampleResults(self): |   65   def SampleResults(self): | 
|   66     self._StorePerfResults() |   66     self._StorePerfResults() | 
|   67     results = self.GetResults() |   67     results = self.GetResults() | 
|   68     self._results = [] |   68     self._results = [] | 
|   69     return results |   69     return results | 
|   70  |   70  | 
|   71   def GetResults(self): |   71   def GetResults(self): | 
|   72     return self._results or self._GetEmptyResults() |   72     return self._results or self._GetEmptyResults() | 
|   73  |   73  | 
|   74   def _GetEmptyResults(self): |   74   @staticmethod | 
 |   75   def _GetEmptyResults(): | 
|   75     return [ |   76     return [ | 
|   76         SurfaceStatsCollector.Result('refresh_period', None, 'seconds'), |   77         SurfaceStatsCollector.Result('refresh_period', None, 'seconds'), | 
|   77         SurfaceStatsCollector.Result('jank_count', None, 'janks'), |   78         SurfaceStatsCollector.Result('jank_count', None, 'janks'), | 
|   78         SurfaceStatsCollector.Result('max_frame_delay', None, 'vsyncs'), |   79         SurfaceStatsCollector.Result('max_frame_delay', None, 'vsyncs'), | 
|   79         SurfaceStatsCollector.Result('frame_lengths', None, 'vsyncs'), |   80         SurfaceStatsCollector.Result('frame_lengths', None, 'vsyncs'), | 
|   80         SurfaceStatsCollector.Result('avg_surface_fps', None, 'fps') |   81         SurfaceStatsCollector.Result('avg_surface_fps', None, 'fps') | 
|   81     ] |   82     ] | 
|   82  |   83  | 
|   83   @staticmethod |   84   @staticmethod | 
|   84   def _GetNormalizedDeltas(data, refresh_period, min_normalized_delta=None): |   85   def _GetNormalizedDeltas(data, refresh_period, min_normalized_delta=None): | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   95     seconds = timestamps[-1] - timestamps[0] |   96     seconds = timestamps[-1] - timestamps[0] | 
|   96  |   97  | 
|   97     frame_lengths, normalized_frame_lengths = \ |   98     frame_lengths, normalized_frame_lengths = \ | 
|   98         SurfaceStatsCollector._GetNormalizedDeltas( |   99         SurfaceStatsCollector._GetNormalizedDeltas( | 
|   99             timestamps, refresh_period, _MIN_NORMALIZED_FRAME_LENGTH) |  100             timestamps, refresh_period, _MIN_NORMALIZED_FRAME_LENGTH) | 
|  100     if len(frame_lengths) < frame_count - 1: |  101     if len(frame_lengths) < frame_count - 1: | 
|  101       logging.warning('Skipping frame lengths that are too short.') |  102       logging.warning('Skipping frame lengths that are too short.') | 
|  102       frame_count = len(frame_lengths) + 1 |  103       frame_count = len(frame_lengths) + 1 | 
|  103     if len(frame_lengths) == 0: |  104     if len(frame_lengths) == 0: | 
|  104       raise Exception('No valid frames lengths found.') |  105       raise Exception('No valid frames lengths found.') | 
|  105     length_changes, normalized_changes = \ |  106     _length_changes, normalized_changes = \ | 
|  106         SurfaceStatsCollector._GetNormalizedDeltas( |  107         SurfaceStatsCollector._GetNormalizedDeltas( | 
|  107             frame_lengths, refresh_period) |  108             frame_lengths, refresh_period) | 
|  108     jankiness = [max(0, round(change)) for change in normalized_changes] |  109     jankiness = [max(0, round(change)) for change in normalized_changes] | 
|  109     pause_threshold = 20 |  110     pause_threshold = 20 | 
|  110     jank_count = sum(1 for change in jankiness |  111     jank_count = sum(1 for change in jankiness | 
|  111                      if change > 0 and change < pause_threshold) |  112                      if change > 0 and change < pause_threshold) | 
|  112     return [ |  113     return [ | 
|  113         SurfaceStatsCollector.Result( |  114         SurfaceStatsCollector.Result( | 
|  114             'avg_surface_fps' + result_suffix, |  115             'avg_surface_fps' + result_suffix, | 
|  115             int(round((frame_count - 1) / seconds)), 'fps'), |  116             int(round((frame_count - 1) / seconds)), 'fps'), | 
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  298       try: |  299       try: | 
|  299         cur_surface = int(match.group(1), 16) |  300         cur_surface = int(match.group(1), 16) | 
|  300       except Exception: |  301       except Exception: | 
|  301         logging.error('Failed to parse current surface from ' + match.group(1)) |  302         logging.error('Failed to parse current surface from ' + match.group(1)) | 
|  302     else: |  303     else: | 
|  303       logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) |  304       logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) | 
|  304     return { |  305     return { | 
|  305         'page_flip_count': cur_surface, |  306         'page_flip_count': cur_surface, | 
|  306         'timestamp': datetime.datetime.now(), |  307         'timestamp': datetime.datetime.now(), | 
|  307     } |  308     } | 
| OLD | NEW |