Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Command line tool for continuously printing Android graphics surface | |
| 8 statistics on the console. | |
| 9 """ | |
| 10 | |
| 11 import collections | |
| 12 import optparse | |
| 13 import sys | |
| 14 import time | |
| 15 | |
| 16 from pylib import android_commands, surface_stats_collector | |
| 17 from pylib.utils import run_tests_helper | |
| 18 | |
| 19 | |
| 20 _FIELD_FORMAT = { | |
| 21 'jank_count (janks)': '%d', | |
| 22 'max_frame_delay (vsyncs)': '%d', | |
| 23 'avg_surface_fps (fps)': '%.2f', | |
| 24 'frame_lengths (vsyncs)': '%.3f', | |
| 25 'refresh_period (seconds)': '%.6f', | |
| 26 } | |
| 27 | |
| 28 | |
| 29 def _MergeResults(results, fields): | |
| 30 merged_results = collections.defaultdict(list) | |
| 31 for result in results: | |
| 32 if fields != ['all'] and not result.name in fields: | |
| 33 continue | |
| 34 name = '%s (%s)' % (result.name, result.unit) | |
| 35 if isinstance(result.value, list): | |
| 36 value = result.value | |
| 37 else: | |
| 38 value = [result.value] | |
| 39 merged_results[name] += value | |
| 40 for name, values in merged_results.iteritems(): | |
| 41 merged_results[name] = sum(values) / float(len(values)) | |
| 42 return merged_results | |
| 43 | |
| 44 | |
| 45 def _GetTerminalSize(): | |
| 46 try: | |
| 47 import fcntl, termios, struct | |
| 48 except ImportError: | |
| 49 return 0, 0 | |
| 50 height, width, _, _ = struct.unpack('HHHH', | |
|
bulach
2013/03/27 11:53:50
nit: just ignore width too and return height direc
| |
| 51 fcntl.ioctl(0, termios.TIOCGWINSZ, | |
| 52 struct.pack('HHHH', 0, 0, 0, 0))) | |
| 53 return width, height | |
| 54 | |
| 55 | |
| 56 def _PrintColumnTitles(results): | |
| 57 for name in results.keys(): | |
| 58 print '%s ' % name, | |
| 59 print | |
| 60 for name in results.keys(): | |
| 61 print '%s ' % ('-' * len(name)), | |
| 62 print | |
| 63 | |
| 64 | |
| 65 def _PrintResults(results): | |
| 66 for name, value in results.iteritems(): | |
| 67 value = _FIELD_FORMAT.get(name, '%s') % value | |
| 68 print value.rjust(len(name)) + ' ', | |
| 69 print | |
| 70 | |
| 71 | |
| 72 def main(argv): | |
| 73 parser = optparse.OptionParser(usage='Usage: %prog [options]', | |
| 74 description=__doc__) | |
| 75 parser.add_option('-v', | |
| 76 '--verbose', | |
| 77 dest='verbose_count', | |
| 78 default=0, | |
| 79 action='count', | |
| 80 help='Verbose level (multiple times for more)') | |
| 81 parser.add_option('--device', | |
| 82 help='Serial number of device we should use.') | |
| 83 parser.add_option('-f', | |
| 84 '--fields', | |
| 85 dest='fields', | |
| 86 default='jank_count,max_frame_delay,avg_surface_fps,' | |
| 87 'frame_lengths', | |
| 88 help='Comma separated list of fields to display or "all".') | |
| 89 parser.add_option('-d', | |
| 90 '--delay', | |
| 91 dest='delay', | |
| 92 default=1, | |
| 93 type='float', | |
| 94 help='Time in seconds to sleep between updates.') | |
| 95 | |
| 96 options, args = parser.parse_args(argv) | |
| 97 run_tests_helper.SetLogLevel(options.verbose_count) | |
| 98 | |
| 99 adb = android_commands.AndroidCommands(options.device) | |
| 100 collector = surface_stats_collector.SurfaceStatsCollector(adb) | |
| 101 collector.DisableWarningAboutEmptyData() | |
| 102 | |
| 103 fields = options.fields.split(',') | |
| 104 row_count = None | |
| 105 | |
| 106 try: | |
| 107 collector.Start() | |
| 108 while True: | |
| 109 time.sleep(options.delay) | |
| 110 results = collector.SampleResults() | |
| 111 results = _MergeResults(results, fields) | |
| 112 | |
| 113 if not results: | |
| 114 continue | |
| 115 | |
| 116 _, terminal_height = _GetTerminalSize() | |
| 117 if row_count is None or (terminal_height and | |
| 118 row_count >= terminal_height - 3): | |
| 119 _PrintColumnTitles(results) | |
| 120 row_count = 0 | |
| 121 | |
| 122 _PrintResults(results) | |
| 123 row_count += 1 | |
| 124 except KeyboardInterrupt: | |
| 125 sys.exit(0) | |
| 126 finally: | |
| 127 collector.Stop() | |
| 128 | |
| 129 | |
| 130 if __name__ == '__main__': | |
| 131 main(sys.argv) | |
| OLD | NEW |