fio2gnuplot: Fixing typo in error message
[fio.git] / tools / plot / fio2gnuplot.py
index c05799173b7dfde35e908ead4b7d685b88dfb487..b2530e0a0dbdf5ad9ba5f2ede4de95dc4ef03453 100755 (executable)
@@ -56,8 +56,8 @@ set ytics axis out auto
 set key top left reverse
 set xlabel "Time (Seconds)"
 set ylabel '%s'
-set xrange [0:]
 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)
@@ -76,6 +76,13 @@ set yrange [0:]
                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:
@@ -84,14 +91,9 @@ set yrange [0:]
                # 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
-                       if pos ==0 :
-                               compare_raw.write("plot '%s' using 2:3 with linespoints title '%s'" % (tmp_filename,fio_data_file[pos]))
-                               compare_smooth.write("plot '%s' using 2:3 smooth csplines title '%s'" % (tmp_filename,fio_data_file[pos]))
-                               compare_trend.write("plot '%s' using 2:3 smooth bezier title '%s'" % (tmp_filename,fio_data_file[pos]))
-                       else:
-                               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]))
+                       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)
@@ -139,8 +141,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):
-       print "Processing data file 1/2"
+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"
+       print "Processing data file 1/2 with %s<time<%s" % (min_time,end_time)
        files=[]
        temp_outfile=[]
        blk_size=0
@@ -158,8 +163,8 @@ def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir):
                current_line=[]
                nb_empty_files=0
                nb_files=len(files)
-               for file in files:
-                       s=file.readline().replace(',',' ').split()
+               for myfile in files:
+                       s=myfile.readline().replace(',',' ').split()
                        if not s:
                                nb_empty_files+=1
                                s="-1, 0, 0, 0".replace(',',' ').split()
@@ -174,10 +179,13 @@ def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir):
                        break
 
                last_time = -1
-               index=0
+               index=-1
                perfs=[]
-               for line in current_line:
-                       time, perf, x, block_size = line
+               for line in enumerate(current_line):
+                       # Index will be used to remember what file was featuring what value
+                       index=index+1
+
+                       time, perf, x, block_size = line[1]
                        if (blk_size == 0):
                                try:
                                        blk_size=int(block_size)
@@ -188,16 +196,18 @@ def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir):
 
                        # We ignore the first 500msec as it doesn't seems to be part of the real benchmark
                        # Time < 500 usually reports BW=0 breaking the min computing
-                       if (((int(time)) > 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:
@@ -333,7 +343,7 @@ def render_gnuplot(fio_data_file, gnuplot_output_dir):
                sys.exit(1);
 
 def print_help():
-    print 'fio2gnuplot.py -ghbiod -t <title> -o <outputfile> -p <pattern> -G <type>'
+    print 'fio2gnuplot.py -ghbiod -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'
@@ -348,6 +358,8 @@ def print_help():
     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)'
 
 def main(argv):
     mode='unknown'
@@ -361,6 +373,8 @@ def main(argv):
     run_gnuplot=False
     parse_global=False
     global_search=''
+    min_time=0
+    max_time=-1
 
     if not os.path.isfile(gpm_dir+'math.gpm'):
            gpm_dir="/usr/local/share/fio/"
@@ -369,9 +383,10 @@ def main(argv):
                    sys.exit(3)
 
     try:
-           opts, args = getopt.getopt(argv[1:],"ghbio:d:t:p:G:")
+           opts, args = getopt.getopt(argv[1:],"ghbio:d:t:p:G:m:M:",['bandwidth', 'iops', 'pattern', 'outputfile', 'outputdir', 'title', 'min_time', 'max_time', 'gnuplot', 'Global', 'help'])
     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:
@@ -393,6 +408,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"):
@@ -444,7 +463,7 @@ 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,gpm_dir)