Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: build/android/surface_stats.py

Issue 13046007: android: Add interactive surface statistics viewer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Indent fix. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/surface_stats_collector.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 optparse
12 import sys
13 import time
14
15 from pylib import android_commands, surface_stats_collector
16 from pylib.utils import run_tests_helper
17
18
19 _FIELD_FORMAT = {
20 'jank_count (janks)': '%d',
21 'max_frame_delay (vsyncs)': '%d',
22 'avg_surface_fps (fps)': '%.2f',
23 'frame_lengths (vsyncs)': '%.3f',
24 'refresh_period (seconds)': '%.6f',
25 }
26
27
28 def MergeResults(results, fields):
29 merged_results = {}
bulach 2013/03/27 10:05:03 import collections, then merged_results = collecti
Sami 2013/03/27 11:47:40 Done.
30 for result in results:
31 if fields != ['all'] and not result.name in fields:
32 continue
33 name = '%s (%s)' % (result.name, result.unit)
34 if isinstance(result.value, list):
35 value = result.value
36 else:
37 value = [result.value]
38 if name in merged_results:
39 merged_results[name] += value
40 else:
41 merged_results[name] = value
42 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.
43 values = merged_results[name]
44 merged_results[name] = sum(values) / float(len(values))
45 return merged_results
46
47 def GetTerminalSize():
48 try:
49 import fcntl, termios, struct
50 except ImportError:
51 return 0, 0
52 height, width, _, _ = struct.unpack('HHHH',
53 fcntl.ioctl(0, termios.TIOCGWINSZ,
54 struct.pack('HHHH', 0, 0, 0, 0)))
55 return width, height
56
57 def PrintColumnTitles(results):
58 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.
59 print '%s ' % name,
60 print
61 for name, value in results.iteritems():
62 print '%s ' % ('-' * len(name)),
63 print
64
65 def PrintResults(results):
66 for name, value in results.iteritems():
67 value = _FIELD_FORMAT.get(name, '%s') % value
68 value = ' ' * max(0, len(name) - len(value)) + value
69 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 :)
70 print
71
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.
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,
bulach 2013/03/27 10:05:03 nit: type='float'
Sami 2013/03/27 11:47:40 Done.
93 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.
94
95 options, args = parser.parse_args(argv)
96 run_tests_helper.SetLogLevel(options.verbose_count)
97
98 adb = android_commands.AndroidCommands(options.device)
99 collector = surface_stats_collector.SurfaceStatsCollector(adb)
100 collector.DisableWarningAboutEmptyData()
101
102 fields = options.fields.split(',')
103 row_count = None
104
105 try:
106 collector.Start()
107 while True:
108 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.
109 results = collector.SampleResults()
110 results = MergeResults(results, fields)
111
112 if not results:
113 continue
114
115 _, terminal_height = GetTerminalSize()
116 if row_count is None or (terminal_height and
117 row_count >= terminal_height - 3):
118 PrintColumnTitles(results)
119 row_count = 0
120
121 PrintResults(results)
122 row_count += 1
123 except KeyboardInterrupt:
124 sys.exit(0)
125 finally:
126 collector.Stop()
127
128
129 if __name__ == '__main__':
130 main(sys.argv)
OLDNEW
« no previous file with comments | « build/android/pylib/surface_stats_collector.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698