3 # btt blkno plotting interface
5 # (C) Copyright 2008 Hewlett-Packard Development Company, L.P.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 Utilizes gnuplot to generate a 3D plot of the block number output
29 from btt. If no <files> are specified, it will utilize all files
30 generated after btt was run with -B blknos (meaning: all files of the
31 form blknos*[rw].dat).
33 The -K option forces bno_plot.py to put the keys below the graph,
34 typically all keys for input files are put in the upper right corner
35 of the graph. If the number of devices exceed 10, then bno_plot.py will
36 automatically push the keys under the graph.
38 To exit the plotter, enter 'quit' or ^D at the 'gnuplot> ' prompt.
41 import getopt, glob, os, sys, tempfile
45 set title 'btt Generated Block Accesses'
46 set xlabel 'Time (secs)'
47 set ylabel 'Block Number'
48 set zlabel '# Blocks per IO'
53 #-----------------------------------------------------------------------------
54 def parse_args(in_args):
59 l_opts = [ 'help', 'keys-below', 'verbose' ]
62 (opts, args) = getopt.getopt(in_args, s_opts, l_opts)
63 except getopt.error, msg:
64 print >>sys.stderr, msg
65 print >>sys.stderr, __doc__
69 if o in ('-h', '--help'):
72 elif o in ('-v', '--verbose'):
74 elif o in ('-K', '--keys-below'):
77 if len(args) > 0: bnos = args
78 else: bnos = glob.glob('blknos*[rw].dat')
80 return (bnos, keys_below)
82 #-----------------------------------------------------------------------------
83 if __name__ == '__main__':
84 (bnos, keys_below) = parse_args(sys.argv[1:])
88 for bno in bnos: print bno,
89 if keys_below: print '\nKeys are to be placed below graph'
92 tmpdir = tempfile.mktemp()
97 t = '%s/%s' % (tmpdir, f)
100 for line in open(f, 'r'):
101 fld = line.split(None)
102 print >>fo, fld[0], fld[1], int(fld[2])-int(fld[1])
105 t = t[t.rfind('/')+1:]
106 if plot_cmd == None: plot_cmd = "splot '%s'" % t
107 else: plot_cmd = "%s,'%s'" % (plot_cmd, t)
109 fo = open('%s/plot.cmds' % tmpdir, 'w')
111 if len(bnos) > 10 or keys_below: print >>fo, 'set key below'
117 cmd = 'gnuplot %s/plot.cmds -' % tmpdir
119 if verbose: print 'Executing %s' % cmd
126 os.system('/bin/rm -rf ' + tmpdir)