X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=tools%2Fplot%2Ffio2gnuplot.py;h=31fc219f3c8d3530ce64d97004dee3e1187cc3db;hp=00594ec56799e944411f8fb527f5165a72d761e9;hb=f2a32ce41b360faf2df3ed58eb1e1287c3d554ff;hpb=5923d3a5365d84d4eb0124edfe2f391a05299112 diff --git a/tools/plot/fio2gnuplot.py b/tools/plot/fio2gnuplot.py index 00594ec5..31fc219f 100755 --- a/tools/plot/fio2gnuplot.py +++ b/tools/plot/fio2gnuplot.py @@ -25,6 +25,7 @@ import sys import getopt import re import math +import shutil def find_file(path, pattern): fio_data_file=[] @@ -37,33 +38,93 @@ def find_file(path, pattern): return fio_data_file -def generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf): +def generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir): + if verbose: print "Generating rendering scripts" filename=gnuplot_output_dir+'mygraph' + temporary_files.append(filename) f=open(filename,'w') + + # Plotting 3D or comparing graphs doesn't have a meaning unless if there is at least 2 traces if len(fio_data_file) > 1: - f.write("call \'graph3D.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\'\n" % (title,gnuplot_output_filename,gnuplot_output_filename,mode)) + f.write("call \'%s/graph3D.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\'\n" % (gpm_dir,title,gnuplot_output_filename,gnuplot_output_filename,mode)) + + # Setting up the compare files that will be plot later + compare=open(gnuplot_output_dir + 'compare.gnuplot','w') + compare.write(''' +set title '%s' +set terminal png size 1280,1024 +set ytics axis out auto +set key top left reverse +set xlabel "Time (Seconds)" +set ylabel '%s' +set yrange [0:] +set style line 1 lt 1 lw 3 pt 3 linecolor rgb "green" +'''% (title,mode)) + compare.close() + #Copying the common file for all kind of graph (raw/smooth/trend) + compare_raw_filename="compare-%s-2Draw" % (gnuplot_output_filename) + compare_smooth_filename="compare-%s-2Dsmooth" % (gnuplot_output_filename) + compare_trend_filename="compare-%s-2Dtrend" % (gnuplot_output_filename) + + shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_raw_filename+".gnuplot") + shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_smooth_filename+".gnuplot") + shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_trend_filename+".gnuplot") + temporary_files.append(gnuplot_output_dir+compare_raw_filename+".gnuplot") + temporary_files.append(gnuplot_output_dir+compare_smooth_filename+".gnuplot") + temporary_files.append(gnuplot_output_dir+compare_trend_filename+".gnuplot") + + #Setting up a different output filename for each kind of graph + compare_raw=open(gnuplot_output_dir+compare_raw_filename + ".gnuplot",'a') + compare_raw.write("set output '%s.png'\n" % compare_raw_filename) + compare_smooth=open(gnuplot_output_dir+compare_smooth_filename+".gnuplot",'a') + compare_smooth.write("set output '%s.png'\n" % compare_smooth_filename) + compare_trend=open(gnuplot_output_dir+compare_trend_filename+".gnuplot",'a') + compare_trend.write("set output '%s.png'\n" % compare_trend_filename) + + # Let's plot the average value for all the traces + global_disk_perf = sum(disk_perf, []) + global_avg = average(global_disk_perf) + compare_raw.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg)); + compare_smooth.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg)); + compare_trend.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg)); pos=0 # Let's create a temporary file for each selected fio file for file in fio_data_file: tmp_filename = "gnuplot_temp_file.%d" % pos - png_file=file.replace('.log','') + + # Plotting comparing graphs doesn't have a meaning unless if there is at least 2 traces + if len(fio_data_file) > 1: + # Adding the plot instruction for each kind of comparing graphs + compare_raw.write(",\\\n'%s' using 2:3 with linespoints title '%s'" % (tmp_filename,fio_data_file[pos])) + compare_smooth.write(",\\\n'%s' using 2:3 smooth csplines title '%s'" % (tmp_filename,fio_data_file[pos])) + compare_trend.write(",\\\n'%s' using 2:3 smooth bezier title '%s'" % (tmp_filename,fio_data_file[pos])) + + png_file=file.replace('.log','') raw_filename = "%s-2Draw" % (png_file) smooth_filename = "%s-2Dsmooth" % (png_file) trend_filename = "%s-2Dtrend" % (png_file) avg = average(disk_perf[pos]) - f.write("call \'graph2D.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\' \'%s\' \'%s\' \'%f\'\n" % (title,tmp_filename,raw_filename,mode,smooth_filename,trend_filename,avg)) + f.write("call \'%s/graph2D.gpm\' \'%s' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%s\' \'%f\'\n" % (gpm_dir,title,tmp_filename,fio_data_file[pos],raw_filename,mode,smooth_filename,trend_filename,avg)) pos = pos +1 + # Plotting comparing graphs doesn't have a meaning unless if there is at least 2 traces + if len(fio_data_file) > 1: + os.remove(gnuplot_output_dir+"compare.gnuplot") + compare_raw.close() + compare_smooth.close() + compare_trend.close() f.close() -def generate_gnuplot_math_script(title,gnuplot_output_filename,mode,average,gnuplot_output_dir): +def generate_gnuplot_math_script(title,gnuplot_output_filename,mode,average,gnuplot_output_dir,gpm_dir): filename=gnuplot_output_dir+'mymath'; + temporary_files.append(filename) f=open(filename,'a') - f.write("call \'math.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\' %s\n" % (title,gnuplot_output_filename,gnuplot_output_filename,mode,average)) + f.write("call \'%s/math.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\' %s\n" % (gpm_dir,title,gnuplot_output_filename,gnuplot_output_filename,mode,average)) f.close() def compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir): + if verbose: print "Processing data file 2/2" temp_files=[] pos=0 @@ -73,7 +134,8 @@ def compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_outp temp_files.append(open(tmp_filename,'r')) pos = pos +1 - f = open(gnuplot_output_filename, "w") + f = open(gnuplot_output_dir+gnuplot_output_filename, "w") + temporary_files.append(gnuplot_output_dir+gnuplot_output_filename) index=0 # Let's add some information for tempfile in temp_files: @@ -86,7 +148,11 @@ def compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_outp def average(s): return sum(s) * 1.0 / len(s) -def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir): +def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir, min_time, max_time): + end_time=max_time + if end_time == -1: + end_time="infinite" + if verbose: print "Processing data file 1/2 with %s 500) or (int(time)==-1)): - disk_perf[index].append(int(perf)) - perfs.append("%s %s"% (time, perf)) - index = index + 1 + if (min_time == 0): + min_time==0.5 + + # Then we estimate if the data we got is part of the time range we want to plot + if ((float(time)>(float(min_time)*1000)) and ((int(time) < (int(max_time)*1000)) or max_time==-1)): + disk_perf[index].append(int(perf)) + perfs.append("%d %s %s"% (index, time, perf)) # If we reach this point, it means that all the traces are coherent for p in enumerate(perfs): - perf_time,perf = p[1].split() - if (perf_time != "-1"): - temp_outfile[p[0]].write("%s %.2f %s\n" % (p[0], float(float(perf_time)/1000), perf)) + index, perf_time,perf = p[1].split() + temp_outfile[int(index)].write("%s %.2f %s\n" % (index, float(float(perf_time)/1000), perf)) for file in files: @@ -147,7 +224,8 @@ def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir): file.close() return blk_size -def compute_math(fio_data_file, title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf): +def compute_math(fio_data_file, title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir): + if verbose: print "Computing Maths" global_min=[] global_max=[] average_file=open(gnuplot_output_dir+gnuplot_output_filename+'.average', 'w') @@ -155,6 +233,11 @@ def compute_math(fio_data_file, title,gnuplot_output_filename,gnuplot_output_dir max_file=open(gnuplot_output_dir+gnuplot_output_filename+'.max', 'w') stddev_file=open(gnuplot_output_dir+gnuplot_output_filename+'.stddev', 'w') global_file=open(gnuplot_output_dir+gnuplot_output_filename+'.global','w') + temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.average') + temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.min') + temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.max') + temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.stddev') + temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.global') min_file.write('DiskName %s\n' % mode) max_file.write('DiskName %s\n'% mode) @@ -198,14 +281,14 @@ def compute_math(fio_data_file, title,gnuplot_output_filename,gnuplot_output_dir stddev_file.close() global_file.close() try: - os.remove('mymath') + os.remove(gnuplot_output_dir+'mymath') except: True - generate_gnuplot_math_script("Average values of "+title,gnuplot_output_filename+'.average',mode,int(avg),gnuplot_output_dir) - generate_gnuplot_math_script("Min values of "+title,gnuplot_output_filename+'.min',mode,average(global_min),gnuplot_output_dir) - generate_gnuplot_math_script("Max values of "+title,gnuplot_output_filename+'.max',mode,average(global_max),gnuplot_output_dir) - generate_gnuplot_math_script("Standard Deviation of "+title,gnuplot_output_filename+'.stddev',mode,int(standard_deviation),gnuplot_output_dir) + generate_gnuplot_math_script("Average values of "+title,gnuplot_output_filename+'.average',mode,int(avg),gnuplot_output_dir,gpm_dir) + generate_gnuplot_math_script("Min values of "+title,gnuplot_output_filename+'.min',mode,average(global_min),gnuplot_output_dir,gpm_dir) + generate_gnuplot_math_script("Max values of "+title,gnuplot_output_filename+'.max',mode,average(global_max),gnuplot_output_dir,gpm_dir) + generate_gnuplot_math_script("Standard Deviation of "+title,gnuplot_output_filename+'.stddev',mode,int(standard_deviation),gnuplot_output_dir,gpm_dir) def parse_global_files(fio_data_file, global_search): max_result=0 @@ -252,17 +335,30 @@ def parse_global_files(fio_data_file, global_search): else: print "Global search %s is not yet implemented\n" % global_search -def render_gnuplot(gnuplot_output_dir): - print "Running gnuplot Rendering\n" +def render_gnuplot(fio_data_file, gnuplot_output_dir): + print "Running gnuplot Rendering" try: + # Let's render all the compared files if some + if len(fio_data_file) > 1: + if verbose: print " |-> Rendering comparing traces" + os.system("cd %s; for i in *.gnuplot; do gnuplot $i; done" % gnuplot_output_dir) + if verbose: print " |-> Rendering math traces" os.system("cd %s; gnuplot mymath" % gnuplot_output_dir) + if verbose: print " |-> Rendering 2D & 3D traces" os.system("cd %s; gnuplot mygraph" % gnuplot_output_dir) + + name_of_directory="the current" + if gnuplot_output_dir != "./": + name_of_directory=gnuplot_output_dir + print "\nRendering traces are available in %s directory" % name_of_directory + global keep_temp_files + keep_temp_files=False except: print "Could not run gnuplot on mymath or mygraph !\n" sys.exit(1); def print_help(): - print 'fio2gnuplot.py -ghbio -t -o <outputfile> -p <pattern>' + print 'fio2gnuplot.py -ghbiodvk -t <title> -o <outputfile> -p <pattern> -G <type> -m <time> -M <time>' print print '-h --help : Print this help' print '-p <pattern> or --pattern <pattern> : A pattern in regexp to select fio input files' @@ -274,9 +370,13 @@ def print_help(): print '-d or --outputdir <dir> : The directory where gnuplot shall render files' print '-t or --title <title> : The title of the gnuplot traces' print ' - Title is set with the block size detected in fio traces' - print '-G or --Global <type> : Search for <type> in .global files match by a pattern' + print '-G or --Global <type> : Search for <type> in .global files match by a pattern' print ' - Available types are : min, max, avg, stddev' print ' - The .global extension is added automatically to the pattern' + print '-m or --min_time <time> : Only consider data starting from <time> seconds (default is 0)' + print '-M or --max_time <time> : Only consider data ending before <time> seconds (default is -1 aka nolimit)' + print '-v or --verbose : Increasing verbosity' + print '-k or --keep : Keep all temporary files from gnuplot\'s output dir' def main(argv): mode='unknown' @@ -285,15 +385,32 @@ def main(argv): title='No title' gnuplot_output_filename='result' gnuplot_output_dir='./' + gpm_dir="/usr/share/fio/" disk_perf=[] run_gnuplot=False parse_global=False global_search='' + min_time=0 + max_time=-1 + global verbose + verbose=False + global temporary_files + temporary_files=[] + global keep_temp_files + keep_temp_files=True + force_keep_temp_files=False + + if not os.path.isfile(gpm_dir+'math.gpm'): + gpm_dir="/usr/local/share/fio/" + if not os.path.isfile(gpm_dir+'math.gpm'): + print "Looks like fio didn't got installed properly as no gpm files found in '/usr/share/fio' or '/usr/local/share/fio'\n" + sys.exit(3) try: - opts, args = getopt.getopt(argv[1:],"ghbio:d:t:p:G:") + opts, args = getopt.getopt(argv[1:],"ghkbivo:d:t:p:G:m:M:",['bandwidth', 'iops', 'pattern', 'outputfile', 'outputdir', 'title', 'min_time', 'max_time', 'gnuplot', 'Global', 'help', 'verbose','keep']) except getopt.GetoptError: - print_help() + print "Error: One of the option passed to the cmdline was not supported" + print "Please fix your command line or read the help (-h option)" sys.exit(2) for opt, arg in opts: @@ -301,6 +418,11 @@ def main(argv): pattern='*_bw.log' elif opt in ("-i", "--iops"): pattern='*_iops.log' + elif opt in ("-v", "--verbose"): + verbose=True + elif opt in ("-k", "--keep"): + #User really wants to keep the temporary files + force_keep_temp_files=True elif opt in ("-p", "--pattern"): pattern_set_by_user=True pattern=arg @@ -315,6 +437,10 @@ def main(argv): os.makedirs(gnuplot_output_dir) elif opt in ("-t", "--title"): title=arg + elif opt in ("-m", "--min_time"): + min_time=arg + elif opt in ("-M", "--max_time"): + max_time=arg elif opt in ("-g", "--gnuplot"): run_gnuplot=True elif opt in ("-G", "--Global"): @@ -333,10 +459,12 @@ def main(argv): if len(fio_data_file) == 0: print "No log file found with pattern %s!" % pattern sys.exit(1) + else: + print "%d files Selected with pattern '%s'" % (len(fio_data_file), pattern) fio_data_file=sorted(fio_data_file, key=str.lower) for file in fio_data_file: - print 'Selected %s' % file + print ' |-> %s' % file if "_bw.log" in file : mode="Bandwidth (KB/sec)" if "_iops.log" in file : @@ -347,6 +475,7 @@ def main(argv): if "IO" in mode: title='IO benchmark with %d fio results' % len(fio_data_file) + print #We need to adjust the output filename regarding the pattern required by the user if (pattern_set_by_user == True): gnuplot_output_filename=pattern @@ -363,20 +492,25 @@ def main(argv): if parse_global==True: parse_global_files(fio_data_file, global_search) else: - blk_size=compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir) + blk_size=compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir,min_time,max_time) title="%s @ Blocksize = %dK" % (title,blk_size/1024) compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir) - compute_math(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf) - generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf) + compute_math(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir) + generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir) if (run_gnuplot==True): - render_gnuplot(gnuplot_output_dir) - - # Cleaning temporary files - try: - os.remove('gnuplot_temp_file.*') - except: - True + render_gnuplot(fio_data_file, gnuplot_output_dir) + + # Shall we clean the temporary files ? + if keep_temp_files==False and force_keep_temp_files==False: + # Cleaning temporary files + if verbose: print "Cleaning temporary files" + for f in enumerate(temporary_files): + if verbose: print " -> %s"%f[1] + try: + os.remove(f[1]) + except: + True #Main if __name__ == "__main__":