diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-04-19 18:37:00 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-04-19 18:37:00 -0400 |
commit | 5cae4926d7084c8b152b1eb48162b48169d86d70 (patch) | |
tree | d0e38239b0660b33c8324d200874b421903b3949 | |
parent | e4f64bb8f90c51eb1ff76457364b032ee8e29901 (diff) |
auto-size CSV column width in ft-compute-stats output
-rwxr-xr-x | ft-compute-stats | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/ft-compute-stats b/ft-compute-stats index e07fd16..45e08cf 100755 --- a/ft-compute-stats +++ b/ft-compute-stats | |||
@@ -10,6 +10,7 @@ import os | |||
10 | 10 | ||
11 | from os.path import splitext | 11 | from os.path import splitext |
12 | 12 | ||
13 | import itertools as it | ||
13 | 14 | ||
14 | def decode_key_value_filename(name): | 15 | def decode_key_value_filename(name): |
15 | "Map key=value_otherkey=other-value names to proper dictionary." | 16 | "Map key=value_otherkey=other-value names to proper dictionary." |
@@ -22,6 +23,24 @@ def decode_key_value_filename(name): | |||
22 | params[k] = v | 23 | params[k] = v |
23 | return params | 24 | return params |
24 | 25 | ||
26 | def print_rows(rows, first_row_prefix='#', other_rows_prefix=' '): | ||
27 | col = 0 | ||
28 | col_widths = [] | ||
29 | field_widths = True | ||
30 | while field_widths: | ||
31 | field_widths = [len(str(row[col])) for row in rows if len(row) > col] | ||
32 | if field_widths: | ||
33 | col_widths.append(max(field_widths)) | ||
34 | col += 1 | ||
35 | |||
36 | prefs = it.chain([first_row_prefix], it.repeat(other_rows_prefix)) | ||
37 | |||
38 | for prefix, row in it.izip(prefs, rows): | ||
39 | print '%s%s' % (prefix, | ||
40 | ", ".join([' ' * (c - len(str(f))) + str(f) | ||
41 | for (c, f) in it.izip(col_widths, row)])) | ||
42 | |||
43 | |||
25 | 44 | ||
26 | def stats_for_file(fname, scale): | 45 | def stats_for_file(fname, scale): |
27 | n = 0 | 46 | n = 0 |
@@ -68,24 +87,23 @@ defaults = { | |||
68 | 87 | ||
69 | options = None | 88 | options = None |
70 | 89 | ||
71 | def fmt_cell(x): | 90 | def to_str(x): |
72 | if type(x) == str: | 91 | if type(x) == str: |
73 | return "%25s" % x | 92 | return x |
74 | if type(x) == int: | 93 | if type(x) == int: |
75 | return "%25d" % x | 94 | return "%d" % x |
76 | else: | 95 | else: |
77 | return "%25.5f" % x | 96 | return "%.5f" % x |
78 | |||
79 | def write_header(): | ||
80 | labels = ["Plugin", "#cores", "Overhead", 'Unit', "#tasks", | ||
81 | "#samples", | ||
82 | "max", "99.9th perc.", "99th perc.", "95th perc.", | ||
83 | "avg", "med", "min", "std", "var", "file"] | ||
84 | header = ", ".join(fmt_cell(x) for x in labels) | ||
85 | print '#%s' % header[1:] | ||
86 | 97 | ||
98 | STATS_HEADERS = [ | ||
99 | "Plugin", "#cores", "Overhead", 'Unit', "#tasks", | ||
100 | "#samples", | ||
101 | "max", "99.9th perc.", "99th perc.", "95th perc.", | ||
102 | "avg", "med", "min", "std", "var", | ||
103 | "file" | ||
104 | ] | ||
87 | 105 | ||
88 | def stats_file(fname): | 106 | def get_stats(fname): |
89 | name, ext = splitext(fname) | 107 | name, ext = splitext(fname) |
90 | conf = decode_key_value_filename(name) | 108 | conf = decode_key_value_filename(name) |
91 | 109 | ||
@@ -115,8 +133,7 @@ def stats_file(fname): | |||
115 | 133 | ||
116 | info = [sched, m, ohead, unit, n] | 134 | info = [sched, m, ohead, unit, n] |
117 | finfo = [fname] | 135 | finfo = [fname] |
118 | print ", ".join([fmt_cell(x) for x in info + stats + finfo]) | 136 | return [to_str(x) for x in info + stats + finfo] |
119 | sys.stdout.flush() | ||
120 | 137 | ||
121 | if __name__ == '__main__': | 138 | if __name__ == '__main__': |
122 | # FIXME: would be nicer with argparse | 139 | # FIXME: would be nicer with argparse |
@@ -125,11 +142,13 @@ if __name__ == '__main__': | |||
125 | (options, files) = parser.parse_args() | 142 | (options, files) = parser.parse_args() |
126 | 143 | ||
127 | try: | 144 | try: |
128 | write_header() | 145 | rows = [] |
146 | rows.append(STATS_HEADERS) | ||
129 | for f in files: | 147 | for f in files: |
130 | try: | 148 | try: |
131 | stats_file(f) | 149 | rows.append(get_stats(f)) |
132 | except IOError, msg: | 150 | except IOError, msg: |
133 | print >> sys.stderr, msg | 151 | print >> sys.stderr, msg |
152 | print_rows(rows) | ||
134 | except KeyboardInterrupt: | 153 | except KeyboardInterrupt: |
135 | pass | 154 | pass |