aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2016-08-29 11:15:32 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2016-08-29 11:15:32 -0400
commit6ac3eeb8d0fd3ae3736a7766f99a8bcd4749c235 (patch)
tree2068ea3da34b6007130be99b363a72d60c910267
parent533198b1624ae74316694da073e4894a52d8efc7 (diff)
Add --percentiles option to ft-compute-stats
Print a table of percentiles
-rwxr-xr-xft-compute-stats50
1 files changed, 48 insertions, 2 deletions
diff --git a/ft-compute-stats b/ft-compute-stats
index 2f0ed9a..a380305 100755
--- a/ft-compute-stats
+++ b/ft-compute-stats
@@ -102,9 +102,13 @@ opts = [
102 help='give relative frequency, not absolute sample counts'), 102 help='give relative frequency, not absolute sample counts'),
103 o('-c', '--cumulative', action='store_true', dest='cumulative', 103 o('-c', '--cumulative', action='store_true', dest='cumulative',
104 help='report cumulative counts (i.e., CDF)'), 104 help='report cumulative counts (i.e., CDF)'),
105 o(None, '--percentiles', action='store_true', dest='want_percentiles',
106 help='produce table of percentiles'),
107 o('-r', '--resolution', action='store', dest='resolution', type='float',
108 help='set resolution of percentiles table'),
105 o(None, '--percent', action='store_true', dest='want_percent', 109 o(None, '--percent', action='store_true', dest='want_percent',
106 help='give relative frequency as a percentage'), 110 help='give relative frequency as a percentage'),
107 ] 111]
108 112
109defaults = { 113defaults = {
110 'cycles' : None, 114 'cycles' : None,
@@ -113,7 +117,9 @@ defaults = {
113 'normalize' : False, 117 'normalize' : False,
114 'want_percent' : False, 118 'want_percent' : False,
115 'cumulative' : False, 119 'cumulative' : False,
116 } 120 'want_percentiles' : False,
121 'resolution' : 0.1,
122}
117 123
118options = None 124options = None
119 125
@@ -169,6 +175,16 @@ def make_bins(max_val):
169 num_bins = int(ceil(max_val / options.bin_size)) + 1 175 num_bins = int(ceil(max_val / options.bin_size)) + 1
170 return [x * options.bin_size for x in range(0, num_bins)] 176 return [x * options.bin_size for x in range(0, num_bins)]
171 177
178def iter_percentiles(resolution):
179 percentile = 0.0
180 while percentile < 100:
181 yield percentile
182 percentile += resolution
183 yield 100.0
184
185def make_percentiles(resolution):
186 return list(iter_percentiles(resolution))
187
172def hist_file(fname, scale): 188def hist_file(fname, scale):
173 max_val = 0 189 max_val = 0
174 hist = [] 190 hist = []
@@ -191,6 +207,20 @@ def hist_file(fname, scale):
191 return (max_val, hist) 207 return (max_val, hist)
192 208
193 209
210def percentiles_file(fname, percentiles):
211 percs = []
212
213 size = os.stat(fname).st_size
214 if size:
215 samples = numpy.memmap(fname, dtype='float32', mode='c')
216
217 n = len(samples)
218 if n > 0:
219 percs = numpy.percentile(samples, percentiles)
220
221 return percs
222
223
194if __name__ == '__main__': 224if __name__ == '__main__':
195 # FIXME: would be nicer with argparse 225 # FIXME: would be nicer with argparse
196 parser = optparse.OptionParser(option_list=opts) 226 parser = optparse.OptionParser(option_list=opts)
@@ -215,6 +245,22 @@ if __name__ == '__main__':
215 print '# Columns:' 245 print '# Columns:'
216 for i, f in enumerate(col_names): 246 for i, f in enumerate(col_names):
217 print '# (%d) %s' % (i + 1, f) 247 print '# (%d) %s' % (i + 1, f)
248 elif options.want_percentiles:
249 cols = []
250 percentiles = make_percentiles(options.resolution)
251 col_names = []
252 for i, f in enumerate(files):
253 try:
254 percs = percentiles_file(f, percentiles)
255 cols.append([i + 1] + [to_str(x) for x in percs])
256 col_names.append(f)
257 except IOError, msg:
258 print >> sys.stderr, msg
259 perc = ['Percentile'] + [to_str(x) for x in percentiles]
260 print_cols([perc] + cols)
261 print '# Columns:'
262 for i, f in enumerate(col_names):
263 print '# (%d) %s' % (i + 1, f)
218 else: 264 else:
219 rows = [] 265 rows = []
220 rows.append(STATS_HEADERS) 266 rows.append(STATS_HEADERS)