#!/usr/bin/env python
import binary_data as bd
from plot import decode
from oplot import load_outliers
import optparse
import sys
from os.path import splitext
o = optparse.make_option
opts = [
o('-p', '--cycles-per-usec', action='store', dest='cycles', type='int',
help='how many cycles per usec'),
o('-i', '--iqr-extent', action='store', dest='extent', type='float',
help='what extent to use for outlier removal'),
o('-c', '--cut-off', action='store', dest='cutoff', type='int',
help='max number of samples to use'),
o('-o', '--outlier-list', action='store', dest='outlier_file',
help='list of outliers to remove'),
o('-m', '--max-value', action='store', dest='maxval', type='float',
help='maximum sample threshold (higher values discarded)'),
]
defaults = {
'cycles' : 2128,
'extent' : 0,
'maxval' : 1000.0,
'cutoff' : None,
'outlier_file' : None,
'outliers' : {},
}
options = None
def fmt_cell(x):
if type(x) == str:
return "%25s" % x
if type(x) == int:
return "%25d" % x
else:
return "%25.5f" % x
def write_header():
labels = ["Plugin", "Overhead", "#tasks",
"#samples", "#filtered",
"max", "avg", "min", "med", "std", "var",
"iqr_max", "iqr_min"]
header = ", ".join(fmt_cell(x) for x in labels)
print '#%s' % header[1:]
def stats_file(fname):
name, ext = splitext(fname)
conf = decode(name)
scale = 1.0 / options.cycles
if conf['overhead'] == 'RELEASE-LATENCY':
scale = 1.0 / 1000 # convert from nanoseconds
take_off = None
if options.outlier_file:
if conf['scheduler'] in options.outliers:
n = int(conf['n'])
for (i, t) in options.outliers[conf['scheduler']]:
if i == n:
take_off = t
break
stats = bd.compact_file(fname,
extent=options.extent,
scale=scale,
maxval=options.maxval,
cutoff=options.cutoff,
manual=take_off)
if 'locks' in conf:
sched = '%s_locks=%s' % (conf['scheduler'], conf['locks'])
else:
sched = conf['scheduler']
info = [sched, conf['overhead'], conf['n']]
print ", ".join([fmt_cell(x) for x in info + stats])
sys.stdout.flush()
if __name__ == '__main__':
parser = optparse.OptionParser(option_list=opts)
parser.set_defaults(**defaults)
(options, files) = parser.parse_args()
try:
if options.outlier_file:
options.outliers = load_outliers(options.outlier_file)
write_header()
for f in files:
try:
stats_file(f)
except IOError, msg:
print >> sys.stderr, msg
except KeyboardInterrupt:
pass