From 50d2a37543908e79c41b1d5a4c2cb2d65c5af21b Mon Sep 17 00:00:00 2001 From: Bill O'Donnell Date: Tue, 22 May 2018 12:49:09 -0500 Subject: [PATCH] make fio scripts python3-ready (part 2) NOTE: this patch (part 2) is in addition to commit 5eac3b00238b (this patch was missed on that submit/commit (part 1)). Many distributions are moving to python3 by default. This is another patch to make the python scripts in fio python3-ready. Conversion was facilitated with automated tools. The modified scripts pass rudimentary testing when run under python2.7 as well as python3. Signed-off-by: Bill O'Donnell Signed-off-by: Jens Axboe --- tools/fio_jsonplus_clat2csv | 13 +++-- tools/plot/fio2gnuplot | 97 +++++++++++++++++++------------------ 2 files changed, 60 insertions(+), 50 deletions(-) diff --git a/tools/fio_jsonplus_clat2csv b/tools/fio_jsonplus_clat2csv index e63d6d8b..78a007e5 100755 --- a/tools/fio_jsonplus_clat2csv +++ b/tools/fio_jsonplus_clat2csv @@ -1,4 +1,5 @@ #!/usr/bin/python2.7 +# Note: this script is python2 and python3 compatible. # # fio_jsonplus_clat2csv # @@ -60,9 +61,13 @@ # 10304ns is the 100th percentile for read latency # +from __future__ import absolute_import +from __future__ import print_function import os import json import argparse +import six +from six.moves import range def parse_args(): @@ -87,7 +92,7 @@ def percentile(idx, run_total): def more_lines(indices, bins): - for key, value in indices.iteritems(): + for key, value in six.iteritems(indices): if value < len(bins[key]): return True @@ -116,8 +121,8 @@ def main(): "Are you sure you are using json+ output?") bins[ddir] = [[int(key), value] for key, value in - jsondata['jobs'][jobnum][ddir][bins_loc] - ['bins'].iteritems()] + six.iteritems(jsondata['jobs'][jobnum][ddir][bins_loc] + ['bins'])] bins[ddir] = sorted(bins[ddir], key=lambda bin: bin[0]) run_total[ddir] = [0 for x in range(0, len(bins[ddir]))] @@ -165,7 +170,7 @@ def main(): output.write(", , , ") output.write("\n") - print "{0} generated".format(outfile) + print("{0} generated".format(outfile)) if __name__ == '__main__': diff --git a/tools/plot/fio2gnuplot b/tools/plot/fio2gnuplot index 5d31f13a..4d1815cf 100755 --- a/tools/plot/fio2gnuplot +++ b/tools/plot/fio2gnuplot @@ -1,4 +1,5 @@ #!/usr/bin/python2.7 +# Note: this script is python2 and python3 compatible. # # Copyright (C) 2013 eNovance SAS # Author: Erwan Velu @@ -19,6 +20,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +from __future__ import absolute_import +from __future__ import print_function import os import fnmatch import sys @@ -26,6 +29,8 @@ import getopt import re import math import shutil +from six.moves import map +from six.moves import range def find_file(path, pattern): fio_data_file=[] @@ -39,7 +44,7 @@ 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,gpm_dir): - if verbose: print "Generating rendering scripts" + if verbose: print("Generating rendering scripts") filename=gnuplot_output_dir+'mygraph' temporary_files.append(filename) f=open(filename,'w') @@ -124,7 +129,7 @@ def generate_gnuplot_math_script(title,gnuplot_output_filename,mode,average,gnup f.close() def compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir): - if verbose: print "Processing data file 2/2" + if verbose: print("Processing data file 2/2") temp_files=[] pos=0 @@ -152,7 +157,7 @@ def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir, min_time, max_ end_time=max_time if end_time == -1: end_time="infinite" - if verbose: print "Processing data file 1/2 with %s 1: - if verbose: print " |-> Rendering comparing traces" + 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" + if verbose: print(" |-> Rendering math traces") os.system("cd %s; gnuplot mymath" % gnuplot_output_dir) - if verbose: print " |-> Rendering 2D & 3D traces" + 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 + 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" + print("Could not run gnuplot on mymath or mygraph !\n") sys.exit(1); def print_help(): - print 'fio2gnuplot -ghbiodvk -t -o <outputfile> -p <pattern> -G <type> -m <time> -M <time>' - print - print '-h --help : Print this help' - print '-p <pattern> or --pattern <pattern> : A glob pattern to select fio input files' - print '-b or --bandwidth : A predefined pattern for selecting *_bw.log files' - print '-i or --iops : A predefined pattern for selecting *_iops.log files' - print '-g or --gnuplot : Render gnuplot traces before exiting' - print '-o or --outputfile <file> : The basename for gnuplot traces' - print ' - Basename is set with the pattern if defined' - 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 ' - 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' + print('fio2gnuplot -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 glob pattern to select fio input files') + print('-b or --bandwidth : A predefined pattern for selecting *_bw.log files') + print('-i or --iops : A predefined pattern for selecting *_iops.log files') + print('-g or --gnuplot : Render gnuplot traces before exiting') + print('-o or --outputfile <file> : The basename for gnuplot traces') + print(' - Basename is set with the pattern if defined') + 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(' - 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' @@ -403,14 +408,14 @@ def main(argv): 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 get installed properly as no gpm files found in '/usr/share/fio' or '/usr/local/share/fio'\n" + print("Looks like fio didn't get 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:],"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 "Error: One of the options passed to the cmdline was not supported" - print "Please fix your command line or read the help (-h option)" + print("Error: One of the options 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: @@ -457,7 +462,7 @@ def main(argv): fio_data_file=find_file('.',pattern) if len(fio_data_file) == 0: - print "No log file found with pattern %s!" % pattern + print("No log file found with pattern %s!" % pattern) # Try numjob log file format if per_numjob_logs=1 if (pattern == '*_bw.log'): fio_data_file=find_file('.','*_bw.*.log') @@ -466,13 +471,13 @@ def main(argv): if len(fio_data_file) == 0: sys.exit(1) else: - print "Using log file per job format instead" + print("Using log file per job format instead") else: - print "%d files Selected with pattern '%s'" % (len(fio_data_file), pattern) + 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 ' |-> %s' % file + print(' |-> %s' % file) if "_bw.log" in file : mode="Bandwidth (KB/sec)" if "_iops.log" in file : @@ -483,7 +488,7 @@ def main(argv): if "IO" in mode: title='IO benchmark with %d fio results' % len(fio_data_file) - print + 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 @@ -514,9 +519,9 @@ def main(argv): # 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" + if verbose: print("Cleaning temporary files") for f in enumerate(temporary_files): - if verbose: print " -> %s"%f[1] + if verbose: print(" -> %s"%f[1]) try: os.remove(f[1]) except: -- 2.25.1