Index: build/android/surface_stats.py |
diff --git a/build/android/surface_stats.py b/build/android/surface_stats.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..a94f3dbcd97cbbd9f428ecc18b9a53690e0f05d3 |
--- /dev/null |
+++ b/build/android/surface_stats.py |
@@ -0,0 +1,130 @@ |
+#!/usr/bin/env python |
+# |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Command line tool for continuously printing Android graphics surface |
+statistics on the console. |
+""" |
+ |
+import optparse |
+import sys |
+import time |
+ |
+from pylib import android_commands, surface_stats_collector |
+from pylib.utils import run_tests_helper |
+ |
+ |
+_FIELD_FORMAT = { |
+ 'jank_count (janks)': '%d', |
+ 'max_frame_delay (vsyncs)': '%d', |
+ 'avg_surface_fps (fps)': '%.2f', |
+ 'frame_lengths (vsyncs)': '%.3f', |
+ 'refresh_period (seconds)': '%.6f', |
+} |
+ |
+ |
+def MergeResults(results, fields): |
+ merged_results = {} |
bulach
2013/03/27 10:05:03
import collections, then merged_results = collecti
Sami
2013/03/27 11:47:40
Done.
|
+ for result in results: |
+ if fields != ['all'] and not result.name in fields: |
+ continue |
+ name = '%s (%s)' % (result.name, result.unit) |
+ if isinstance(result.value, list): |
+ value = result.value |
+ else: |
+ value = [result.value] |
+ if name in merged_results: |
+ merged_results[name] += value |
+ else: |
+ merged_results[name] = value |
+ for name in merged_results.keys(): |
bulach
2013/03/27 10:05:03
nit:
for name, values in merged_results.iteritems(
Sami
2013/03/27 11:47:40
Done.
|
+ values = merged_results[name] |
+ merged_results[name] = sum(values) / float(len(values)) |
+ return merged_results |
+ |
+def GetTerminalSize(): |
+ try: |
+ import fcntl, termios, struct |
+ except ImportError: |
+ return 0, 0 |
+ height, width, _, _ = struct.unpack('HHHH', |
+ fcntl.ioctl(0, termios.TIOCGWINSZ, |
+ struct.pack('HHHH', 0, 0, 0, 0))) |
+ return width, height |
+ |
+def PrintColumnTitles(results): |
+ for name, value in results.iteritems(): |
bulach
2013/03/27 10:05:03
nit: for name in results.keys() (and below)
Sami
2013/03/27 11:47:40
Done.
|
+ print '%s ' % name, |
+ for name, value in results.iteritems(): |
+ print '%s ' % ('-' * len(name)), |
+ |
+def PrintResults(results): |
+ for name, value in results.iteritems(): |
+ value = _FIELD_FORMAT.get(name, '%s') % value |
+ value = ' ' * max(0, len(name) - len(value)) + value |
+ print '%s ' % value, |
bulach
2013/03/27 10:05:03
nit:
print value.rjust(len(name)) + ' ',
Sami
2013/03/27 11:47:40
Comes with batteries indeed :)
|
+ |
bulach
2013/03/27 10:05:03
nit: add another \n between all of the functions a
Sami
2013/03/27 11:47:40
Done.
|
+def main(argv): |
+ parser = optparse.OptionParser(usage='Usage: %prog [options]', |
+ description=__doc__) |
+ parser.add_option('-v', |
+ '--verbose', |
+ dest='verbose_count', |
+ default=0, |
+ action='count', |
+ help='Verbose level (multiple times for more)') |
+ parser.add_option('--device', |
+ help='Serial number of device we should use.') |
+ parser.add_option('-f', |
+ '--fields', |
+ dest='fields', |
+ default='jank_count,max_frame_delay,avg_surface_fps,' |
+ 'frame_lengths', |
+ help='Comma separated list of fields to display or "all".') |
+ parser.add_option('-d', |
+ '--delay', |
+ dest='delay', |
+ default=1, |
bulach
2013/03/27 10:05:03
nit: type='float'
Sami
2013/03/27 11:47:40
Done.
|
+ help='Time to sleep between statistics updates.') |
bulach
2013/03/27 10:05:03
nit: (in seconds)
Sami
2013/03/27 11:47:40
Done.
|
+ |
+ options, args = parser.parse_args(argv) |
+ run_tests_helper.SetLogLevel(options.verbose_count) |
+ |
+ adb = android_commands.AndroidCommands(options.device) |
+ collector = surface_stats_collector.SurfaceStatsCollector(adb) |
+ collector.DisableWarningAboutEmptyData() |
+ |
+ fields = options.fields.split(',') |
+ row_count = None |
+ |
+ try: |
+ collector.Start() |
+ while True: |
+ time.sleep(float(options.delay)) |
bulach
2013/03/27 10:05:03
nit: with type='float' above, no need to convert h
Sami
2013/03/27 11:47:40
Done.
|
+ results = collector.SampleResults() |
+ results = MergeResults(results, fields) |
+ |
+ if not results: |
+ continue |
+ |
+ _, terminal_height = GetTerminalSize() |
+ if row_count is None or (terminal_height and |
+ row_count >= terminal_height - 3): |
+ PrintColumnTitles(results) |
+ row_count = 0 |
+ |
+ PrintResults(results) |
+ row_count += 1 |
+ except KeyboardInterrupt: |
+ sys.exit(0) |
+ finally: |
+ collector.Stop() |
+ |
+ |
+if __name__ == '__main__': |
+ main(sys.argv) |