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.
7 """Command line tool for continuously printing Android graphics surface
8 statistics on the console.
16 from pylib
import android_commands
, surface_stats_collector
17 from pylib
.utils
import run_tests_helper
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',
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
:
34 name
= '%s (%s)' % (result
.name
, result
.unit
)
35 if isinstance(result
.value
, list):
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
))
45 def _GetTerminalHeight():
47 import fcntl
, termios
, struct
50 height
, _
, _
, _
= struct
.unpack('HHHH',
51 fcntl
.ioctl(0, termios
.TIOCGWINSZ
,
52 struct
.pack('HHHH', 0, 0, 0, 0)))
56 def _PrintColumnTitles(results
):
57 for name
in results
.keys():
60 for name
in results
.keys():
61 print '%s ' % ('-' * len(name
)),
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
)) + ' ',
73 parser
= optparse
.OptionParser(usage
='Usage: %prog [options]',
75 parser
.add_option('-v',
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',
86 default
='jank_count,max_frame_delay,avg_surface_fps,'
88 help='Comma separated list of fields to display or "all".')
89 parser
.add_option('-d',
94 help='Time in seconds to sleep between updates.')
96 options
, args
= parser
.parse_args(argv
)
97 run_tests_helper
.SetLogLevel(options
.verbose_count
)
99 adb
= android_commands
.AndroidCommands(options
.device
)
100 collector
= surface_stats_collector
.SurfaceStatsCollector(adb
)
101 collector
.DisableWarningAboutEmptyData()
103 fields
= options
.fields
.split(',')
109 time
.sleep(options
.delay
)
110 results
= collector
.SampleResults()
111 results
= _MergeResults(results
, fields
)
116 terminal_height
= _GetTerminalHeight()
117 if row_count
is None or (terminal_height
and
118 row_count
>= terminal_height
- 3):
119 _PrintColumnTitles(results
)
122 _PrintResults(results
)
124 except KeyboardInterrupt:
130 if __name__
== '__main__':