[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r15601: -resolution can be specified on the command line e.g. -r 40 (torflow/branches/gsoc2008/tools/BTAnalysis)
Author: fallon
Date: 2008-07-02 12:23:50 -0400 (Wed, 02 Jul 2008)
New Revision: 15601
Modified:
torflow/branches/gsoc2008/tools/BTAnalysis/shufflebt.py
Log:
-resolution can be specified on the command line e.g. -r 40
-can now give a directory instead of a list of filenames. the script will shallowly search the directory for files with the suffix '.buildtimes' and process those.
-script can now handle relative paths
Modified: torflow/branches/gsoc2008/tools/BTAnalysis/shufflebt.py
===================================================================
--- torflow/branches/gsoc2008/tools/BTAnalysis/shufflebt.py 2008-07-02 16:12:05 UTC (rev 15600)
+++ torflow/branches/gsoc2008/tools/BTAnalysis/shufflebt.py 2008-07-02 16:23:50 UTC (rev 15601)
@@ -2,12 +2,11 @@
# shufflebt.py
# (c) Fallon Chen 2008
# Shuffles a list of build times and produces a pdf of n of those buildtimes,
-# which are put into 100ms blocks.
+# which are put into res (defaults to 100)ms blocks.
# Requires gnuplot 4.2 and a version coreutils that provides sort -R
# "usage: shufflebt.py [-n <number of circuits>] [-s] [-g] [-k <k value>] [-d outdirname] <list of filenames>"
# if outdir is not specified, the script will write files to the current directory
-# FIXME: you need to be in the directory containing the timefile when you call
-# this script, or supply an absolute path
+# if a directory is given instead of a list of filenames, all files postfixed with '.buildtimes' will be processed
import getopt,sys,os
import popen2
import math,copy
@@ -163,12 +162,13 @@
def usage():
- print "usage: shufflebt.py [-n <number of circuits>] [-s] [-g] [-k <k value>] [-d outdirname] <list of filenames>"
+ print "usage: shufflebt.py [-n <number of circuits>] [-s] [-g] [-k <k value>] [-d outdirname] [-r <res in ms>] <list of filenames>"
sys.exit(1)
def getargs():
# [-n <truncate to # circuits>] [-s] <list of filenames>
k = 3
+ res = 100
sort =False
truncate = None
graph = False
@@ -186,22 +186,26 @@
i += 1
elif sys.argv[i + 1] == '-g': graph = True
elif sys.argv[i + 1] == '-k':
- k = sys.argv[i + 2]
+ k = float(sys.argv[i + 2])
i += 1
elif sys.argv[i+1] == '-d':
outdirname = sys.argv[i + 2]
i += 1
+ elif sys.argv[i+1] == '-r':
+ res = float(sys.argv[i+2])
+ i += 1
else:
filenames += [sys.argv[i+1]]
i += 1
- return sort, truncate,graph,outdirname,filenames,k
+ return sort, truncate,graph,outdirname,filenames,k,res
def shuffle(sort,truncate,filename,newfile):
if not sort and truncate is None: return
- sortlocation = '/usr/local/bin/sort'
+ #sortlocation = '/usr/local/bin/sort' #peculiarity of fallon's system
+ sortlocation = 'sort'
if sort and truncate:
cmd = sortlocation + ' -R ' + filename + ' | head -n ' + truncate + ' > ' + newfile
elif sort and not truncate:
@@ -212,7 +216,7 @@
p = popen2.Popen4(cmd)
p.wait()
if __name__ == "__main__":
- sort, truncate,graph,dirname,filenames,k = getargs()
+ sort, truncate,graph,dirname,filenames,k,res = getargs()
# make new directory
print 'Making new directory:',dirname
@@ -222,11 +226,22 @@
print 'Dir exists, not making a new one'
for filename in filenames:
+ if os.path.isdir(filename):
+ # shallow add of files in dir
+ for f in os.listdir(filename):
+ if f[-11:] == '.buildtimes':
+ filenames += [os.path.join(filename,f)]
+ filenames.remove(filename)
+
+ for filename in filenames:
print 'Processing',filename
+ if not os.path.exists(filename):
+ print filename,'is not a valid path'
+ continue
if truncate and sort or truncate and not sort:
- newfile = dirname + '/' + filename + '.' + truncate + '.shuffled'
+ newfile = os.path.join(dirname, os.path.basename(filename) + '.' + truncate + '.shuffled')
elif sort and not truncate:
- newfile = dirname + '/' + filename + '.shuffled'
+ newfile = os.path.join(dirname , os.path.basename(filename) + '.shuffled')
else:
newfile = filename
# shuffle, create new file
@@ -235,9 +250,9 @@
# create histogram from file
s = Stats(newfile)
if not sort and not truncate:
- s.makehistogram(100,newfile,dirname + '/' + newfile + '.hist')
+ s.makehistogram(res,newfile,os.path.join(dirname ,os.path.basename(newfile )+ '.res' + str(res) + '.hist'))
else:
- s.makehistogram(100,newfile,newfile + '.hist')
+ s.makehistogram(res,newfile,newfile + '.res' + str(res) +'.hist')
mean = s.mean()
stddev = s.stddev()
median = s.median()
@@ -245,6 +260,7 @@
parK = s.paretoK(mode)
modeN = s.modeN(mode)
modeMean = s.modeMean(mode)
+ print 'Resolution of histogram:',res,'ms'
print 'Mean: '+str(mean)+', mode: '+str(mode)
print 'ParK: '+str(parK)
@@ -253,11 +269,11 @@
if graph:
# create gnuplot file
if not sort and not truncate:
- newfile = dirname + '/' + newfile
+ newfile = os.path.join(dirname, newfile)
plotname = newfile + '.plt'
ncircuits = str(len(s.values))
- plotstr = "set terminal png transparent nocrop enhanced size 800,600\nset output '" + newfile + ".png'\nset style fill solid 1.00 border -1\nset style histogram clustered gap 1 title offset character 0, 0, 0\nset datafile missing '-'\nset style data histograms\nset title 'Buildtime Distribution Function for "+ ncircuits +" Circuits k=" + str(k) + "\nset ylabel '# Circuits'\nset xlabel 'time (in 100ms)'\n"
+ plotstr = "set terminal png transparent nocrop enhanced size 800,600\nset output '" + newfile + ".png'\nset style fill solid 1.00 border -1\nset style histogram clustered gap 1 title offset character 0, 0, 0\nset datafile missing '-'\nset style data histograms\nset title 'Buildtime Distribution Function for "+ ncircuits +" Circuits k=" + str(k) + "\nset ylabel '# Circuits'\nset xlabel 'time (in " + str(res) + " ms)'\n"
plotstr += "set label 'std dev=" + str(stddev) + "' at 170,15\n"
# FIXME: Hrmm... http://en.wikipedia.org/wiki/Skewness? Seems like a hack
@@ -297,8 +313,8 @@
f.close()
# plot the file
- # p = popen2.Popen4('gnuplot ' + plotname)
- p = popen2.Popen4('gp4.2 ' + plotname)
+ p = popen2.Popen4('gnuplot ' + plotname)
+ #p = popen2.Popen4('gp4.2 ' + plotname) #peculiarity of fallon's system
p.wait()
for err in p.fromchild: