1 #!/usr/bin/env python2.7 2 """ Cut the number bins in half in fio histogram output. Example usage: 3 4 $ half-bins.py -c 2 output_clat_hist.1.log > smaller_clat_hist.1.log 5 6 Which merges e.g. bins [0 .. 3], [4 .. 7], ..., [1212 .. 1215] resulting in 7 304 = 1216 / (2**2) merged bins per histogram sample. 8 9 @author Karl Cronburg <karl.cronburg (at] gmail.com> 10 """ 11 import sys 12 13 def main(ctx): 14 stride = 1 << ctx.coarseness 15 with open(ctx.FILENAME, 'r') as fp: 16 for line in fp.readlines(): 17 vals = line.split(', ') 18 sys.stdout.write("%s, %s, %s, " % tuple(vals[:3])) 19 20 hist = list(map(int, vals[3:])) 21 for i in range(0, len(hist) - stride, stride): 22 sys.stdout.write("%d, " % sum(hist[i : i + stride],)) 23 sys.stdout.write("%d\n" % sum(hist[len(hist) - stride:])) 24 25 if __name__ == '__main__': 26 import argparse 27 p = argparse.ArgumentParser() 28 arg = p.add_argument 29 arg( 'FILENAME', help='clat_hist file for which we will reduce' 30 ' (by half or more) the number of bins.') 31 arg('-c', '--coarseness', 32 default=1, 33 type=int, 34 help='number of times to reduce number of bins by half, ' 35 'e.g. coarseness of 4 merges each 2^4 = 16 consecutive ' 36 'bins.') 37 main(p.parse_args()) 38 39