Blame tools/plot/fio2gnuplot

Packit Service 844fb0
#! /usr/libexec/platform-python
Packit 8930e1
# Note: this script is python2 and python3 compatible.
Packit 8930e1
#
Packit 8930e1
#  Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
Packit 8930e1
#  Author: Erwan Velu  <erwan@enovance.com>
Packit 8930e1
#
Packit 8930e1
#  The license below covers all files distributed with fio unless otherwise
Packit 8930e1
#  noted in the file itself.
Packit 8930e1
#
Packit 8930e1
#  This program is free software; you can redistribute it and/or modify
Packit 8930e1
#  it under the terms of the GNU General Public License version 2 as
Packit 8930e1
#  published by the Free Software Foundation.
Packit 8930e1
#
Packit 8930e1
#  This program is distributed in the hope that it will be useful,
Packit 8930e1
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8930e1
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8930e1
#  GNU General Public License for more details.
Packit 8930e1
#
Packit 8930e1
#  You should have received a copy of the GNU General Public License
Packit 8930e1
#  along with this program; if not, write to the Free Software
Packit 8930e1
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 8930e1
Packit 8930e1
from __future__ import absolute_import
Packit 8930e1
from __future__ import print_function
Packit 8930e1
import os
Packit 8930e1
import fnmatch
Packit 8930e1
import sys
Packit 8930e1
import getopt
Packit 8930e1
import re
Packit 8930e1
import math
Packit 8930e1
import shutil
Packit 8930e1
from six.moves import map
Packit 8930e1
from six.moves import range
Packit 8930e1
Packit 8930e1
def find_file(path, pattern):
Packit 8930e1
	fio_data_file=[]
Packit 8930e1
	# For all the local files
Packit 8930e1
	for file in os.listdir(path):
Packit 8930e1
		# If the file matches the glob
Packit 8930e1
		if fnmatch.fnmatch(file, pattern):
Packit 8930e1
			# Let's consider this file
Packit 8930e1
			fio_data_file.append(file)
Packit 8930e1
Packit 8930e1
	return fio_data_file
Packit 8930e1
Packit 8930e1
def generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir):
Packit 8930e1
	if verbose: print("Generating rendering scripts")
Packit 8930e1
	filename=gnuplot_output_dir+'mygraph'
Packit 8930e1
	temporary_files.append(filename)
Packit 8930e1
	f=open(filename,'w')
Packit 8930e1
Packit 8930e1
	# Plotting 3D or comparing graphs doesn't have a meaning unless if there is at least 2 traces
Packit 8930e1
	if len(fio_data_file) > 1:
Packit 8930e1
		f.write("call \'%s/graph3D.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\'\n" % (gpm_dir,title,gnuplot_output_filename,gnuplot_output_filename,mode))
Packit 8930e1
Packit 8930e1
		# Setting up the compare files that will be plot later
Packit 8930e1
		compare=open(gnuplot_output_dir + 'compare.gnuplot','w')
Packit 8930e1
		compare.write('''
Packit 8930e1
set title '%s'
Packit 8930e1
set terminal png size 1280,1024
Packit 8930e1
set ytics axis out auto
Packit 8930e1
set key top left reverse
Packit 8930e1
set xlabel "Time (Seconds)"
Packit 8930e1
set ylabel '%s'
Packit 8930e1
set yrange [0:]
Packit 8930e1
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "green"
Packit 8930e1
'''% (title,mode))
Packit 8930e1
		compare.close()
Packit 8930e1
		#Copying the common file for all kind of graph (raw/smooth/trend)
Packit 8930e1
		compare_raw_filename="compare-%s-2Draw" % (gnuplot_output_filename)
Packit 8930e1
		compare_smooth_filename="compare-%s-2Dsmooth" % (gnuplot_output_filename)
Packit 8930e1
		compare_trend_filename="compare-%s-2Dtrend" % (gnuplot_output_filename)
Packit 8930e1
Packit 8930e1
		shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_raw_filename+".gnuplot")
Packit 8930e1
		shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_smooth_filename+".gnuplot")
Packit 8930e1
		shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_trend_filename+".gnuplot")
Packit 8930e1
		temporary_files.append(gnuplot_output_dir+compare_raw_filename+".gnuplot")
Packit 8930e1
		temporary_files.append(gnuplot_output_dir+compare_smooth_filename+".gnuplot")
Packit 8930e1
		temporary_files.append(gnuplot_output_dir+compare_trend_filename+".gnuplot")
Packit 8930e1
Packit 8930e1
		#Setting up a different output filename for each kind of graph
Packit 8930e1
		compare_raw=open(gnuplot_output_dir+compare_raw_filename + ".gnuplot",'a')
Packit 8930e1
		compare_raw.write("set output '%s.png'\n" % compare_raw_filename)
Packit 8930e1
		compare_smooth=open(gnuplot_output_dir+compare_smooth_filename+".gnuplot",'a')
Packit 8930e1
		compare_smooth.write("set output '%s.png'\n" % compare_smooth_filename)
Packit 8930e1
		compare_trend=open(gnuplot_output_dir+compare_trend_filename+".gnuplot",'a')
Packit 8930e1
		compare_trend.write("set output '%s.png'\n" % compare_trend_filename)
Packit 8930e1
Packit 8930e1
		# Let's plot the average value for all the traces
Packit 8930e1
		global_disk_perf = sum(disk_perf, [])
Packit 8930e1
		global_avg  = average(global_disk_perf)
Packit 8930e1
		compare_raw.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg));
Packit 8930e1
		compare_smooth.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg));
Packit 8930e1
		compare_trend.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg));
Packit 8930e1
Packit 8930e1
		pos=0
Packit 8930e1
		# Let's create a temporary file for each selected fio file
Packit 8930e1
		for file in fio_data_file:
Packit 8930e1
			tmp_filename = "gnuplot_temp_file.%d" % pos
Packit 8930e1
Packit 8930e1
		# Plotting comparing graphs doesn't have a meaning unless if there is at least 2 traces
Packit 8930e1
		if len(fio_data_file) > 1:
Packit 8930e1
			# Adding the plot instruction for each kind of comparing graphs
Packit 8930e1
			compare_raw.write(",\\\n'%s' using 2:3 with linespoints title '%s'" % (tmp_filename,fio_data_file[pos]))
Packit 8930e1
			compare_smooth.write(",\\\n'%s' using 2:3 smooth csplines title '%s'" % (tmp_filename,fio_data_file[pos]))
Packit 8930e1
			compare_trend.write(",\\\n'%s' using 2:3 smooth bezier title '%s'" % (tmp_filename,fio_data_file[pos]))
Packit 8930e1
Packit 8930e1
		png_file=file.replace('.log','')
Packit 8930e1
		raw_filename = "%s-2Draw" % (png_file)
Packit 8930e1
		smooth_filename = "%s-2Dsmooth" % (png_file)
Packit 8930e1
		trend_filename = "%s-2Dtrend" % (png_file)
Packit 8930e1
		avg  = average(disk_perf[pos])
Packit 8930e1
		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))
Packit 8930e1
		pos = pos +1
Packit 8930e1
Packit 8930e1
	# Plotting comparing graphs doesn't have a meaning unless if there is at least 2 traces
Packit 8930e1
	if len(fio_data_file) > 1:
Packit 8930e1
		os.remove(gnuplot_output_dir+"compare.gnuplot")
Packit 8930e1
		compare_raw.close()
Packit 8930e1
		compare_smooth.close()
Packit 8930e1
		compare_trend.close()
Packit 8930e1
	f.close()
Packit 8930e1
Packit 8930e1
def generate_gnuplot_math_script(title,gnuplot_output_filename,mode,average,gnuplot_output_dir,gpm_dir):
Packit 8930e1
	filename=gnuplot_output_dir+'mymath';
Packit 8930e1
	temporary_files.append(filename)
Packit 8930e1
	f=open(filename,'a')
Packit 8930e1
	f.write("call \'%s/math.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\' %s\n" % (gpm_dir,title,gnuplot_output_filename,gnuplot_output_filename,mode,average))
Packit 8930e1
	f.close()
Packit 8930e1
Packit 8930e1
def compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir):
Packit 8930e1
	if verbose: print("Processing data file 2/2")
Packit 8930e1
	temp_files=[]
Packit 8930e1
	pos=0
Packit 8930e1
Packit 8930e1
	# Let's create a temporary file for each selected fio file
Packit 8930e1
	for file in fio_data_file:
Packit 8930e1
		tmp_filename = "%sgnuplot_temp_file.%d" % (gnuplot_output_dir, pos)
Packit 8930e1
		temp_files.append(open(tmp_filename,'r'))
Packit 8930e1
		pos = pos +1
Packit 8930e1
Packit 8930e1
	f = open(gnuplot_output_dir+gnuplot_output_filename, "w")
Packit 8930e1
	temporary_files.append(gnuplot_output_dir+gnuplot_output_filename)
Packit 8930e1
	index=0
Packit 8930e1
	# Let's add some information
Packit 8930e1
	for tempfile in temp_files:
Packit 8930e1
		    f.write("# Disk%d was coming from %s\n" % (index,fio_data_file[index]))
Packit 8930e1
		    f.write(tempfile.read())
Packit 8930e1
		    f.write("\n")
Packit 8930e1
		    tempfile.close()
Packit 8930e1
		    index = index + 1
Packit 8930e1
	f.close()
Packit 8930e1
Packit 8930e1
def average(s): return sum(s) * 1.0 / len(s)
Packit 8930e1
Packit 8930e1
def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir, min_time, max_time):
Packit 8930e1
	end_time=max_time
Packit 8930e1
	if end_time == -1:
Packit 8930e1
		end_time="infinite"
Packit 8930e1
	if verbose: print("Processing data file 1/2 with %s
Packit 8930e1
	files=[]
Packit 8930e1
	temp_outfile=[]
Packit 8930e1
	blk_size=0
Packit 8930e1
	for file in fio_data_file:
Packit 8930e1
		files.append(open(file))
Packit 8930e1
		pos = len(files) - 1
Packit 8930e1
		tmp_filename = "%sgnuplot_temp_file.%d" % (gnuplot_output_dir,pos)
Packit 8930e1
		temporary_files.append(tmp_filename)
Packit 8930e1
		gnuplot_file=open(tmp_filename,'w')
Packit 8930e1
		temp_outfile.append(gnuplot_file)
Packit 8930e1
		gnuplot_file.write("#Temporary file based on file %s\n" % file)
Packit 8930e1
		disk_perf.append([])
Packit 8930e1
Packit 8930e1
	shall_break = False
Packit 8930e1
	while True:
Packit 8930e1
		current_line=[]
Packit 8930e1
		nb_empty_files=0
Packit 8930e1
		nb_files=len(files)
Packit 8930e1
		for myfile in files:
Packit 8930e1
			s=myfile.readline().replace(',',' ').split()
Packit 8930e1
			if not s:
Packit 8930e1
				nb_empty_files+=1
Packit 8930e1
				s="-1, 0, 0, 0".replace(',',' ').split()
Packit 8930e1
Packit 8930e1
			if (nb_empty_files == nb_files):
Packit 8930e1
				shall_break=True
Packit 8930e1
				break;
Packit 8930e1
Packit 8930e1
			current_line.append(s);
Packit 8930e1
Packit 8930e1
		if shall_break == True:
Packit 8930e1
			break
Packit 8930e1
Packit 8930e1
		last_time = -1
Packit 8930e1
		index=-1
Packit 8930e1
		perfs=[]
Packit 8930e1
		for line in enumerate(current_line):
Packit 8930e1
			# Index will be used to remember what file was featuring what value
Packit 8930e1
			index=index+1
Packit 8930e1
Packit 8930e1
			time, perf, x, block_size = line[1]
Packit 8930e1
			if (blk_size == 0):
Packit 8930e1
				try:
Packit 8930e1
					blk_size=int(block_size)
Packit 8930e1
				except:
Packit 8930e1
					print("Error while reading the following line :")
Packit 8930e1
					print(line)
Packit 8930e1
					sys.exit(1);
Packit 8930e1
Packit 8930e1
			# We ignore the first 500msec as it doesn't seems to be part of the real benchmark
Packit 8930e1
			# Time < 500 usually reports BW=0 breaking the min computing
Packit 8930e1
			if (min_time == 0):
Packit 8930e1
				min_time==0.5
Packit 8930e1
Packit 8930e1
			# Then we estimate if the data we got is part of the time range we want to plot
Packit 8930e1
			if ((float(time)>(float(min_time)*1000)) and ((int(time) < (int(max_time)*1000)) or max_time==-1)):
Packit 8930e1
					disk_perf[index].append(int(perf))
Packit 8930e1
					perfs.append("%d %s %s"% (index, time, perf))
Packit 8930e1
Packit 8930e1
		# If we reach this point, it means that all the traces are coherent
Packit 8930e1
		for p in enumerate(perfs):
Packit 8930e1
			index, perf_time,perf = p[1].split()
Packit 8930e1
			temp_outfile[int(index)].write("%s %.2f %s\n" % (index, float(float(perf_time)/1000), perf))
Packit 8930e1
Packit 8930e1
Packit 8930e1
	for file in files:
Packit 8930e1
		file.close()
Packit 8930e1
	for file in temp_outfile:
Packit 8930e1
                file.close()
Packit 8930e1
	return blk_size
Packit 8930e1
Packit 8930e1
def compute_math(fio_data_file, title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir):
Packit 8930e1
	if verbose: print("Computing Maths")
Packit 8930e1
	global_min=[]
Packit 8930e1
	global_max=[]
Packit 8930e1
	average_file=open(gnuplot_output_dir+gnuplot_output_filename+'.average', 'w')
Packit 8930e1
	min_file=open(gnuplot_output_dir+gnuplot_output_filename+'.min', 'w')
Packit 8930e1
	max_file=open(gnuplot_output_dir+gnuplot_output_filename+'.max', 'w')
Packit 8930e1
	stddev_file=open(gnuplot_output_dir+gnuplot_output_filename+'.stddev', 'w')
Packit 8930e1
	global_file=open(gnuplot_output_dir+gnuplot_output_filename+'.global','w')
Packit 8930e1
	temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.average')
Packit 8930e1
	temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.min')
Packit 8930e1
	temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.max')
Packit 8930e1
	temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.stddev')
Packit 8930e1
	temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.global')
Packit 8930e1
Packit 8930e1
	min_file.write('DiskName %s\n' % mode)
Packit 8930e1
	max_file.write('DiskName %s\n'% mode)
Packit 8930e1
	average_file.write('DiskName %s\n'% mode)
Packit 8930e1
	stddev_file.write('DiskName %s\n'% mode )
Packit 8930e1
	for disk in range(len(fio_data_file)):
Packit 8930e1
#		print disk_perf[disk]
Packit 8930e1
		min_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk]))
Packit 8930e1
		max_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk]))
Packit 8930e1
		average_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk]))
Packit 8930e1
		stddev_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk]))
Packit 8930e1
		avg  = average(disk_perf[disk])
Packit 8930e1
		variance = [(x - avg)**2 for x in disk_perf[disk]]
Packit 8930e1
		standard_deviation = math.sqrt(average(variance))
Packit 8930e1
#		print "Disk%d [ min=%.2f max=%.2f avg=%.2f stddev=%.2f \n" % (disk,min(disk_perf[disk]),max(disk_perf[disk]),avg, standard_deviation)
Packit 8930e1
		average_file.write('%d %d\n' % (disk, avg))
Packit 8930e1
		stddev_file.write('%d %d\n' % (disk, standard_deviation))
Packit 8930e1
		local_min=min(disk_perf[disk])
Packit 8930e1
		local_max=max(disk_perf[disk])
Packit 8930e1
		min_file.write('%d %d\n' % (disk, local_min))
Packit 8930e1
		max_file.write('%d %d\n' % (disk, local_max))
Packit 8930e1
		global_min.append(int(local_min))
Packit 8930e1
		global_max.append(int(local_max))
Packit 8930e1
Packit 8930e1
	global_disk_perf = sum(disk_perf, [])
Packit 8930e1
	avg  = average(global_disk_perf)
Packit 8930e1
	variance = [(x - avg)**2 for x in global_disk_perf]
Packit 8930e1
	standard_deviation = math.sqrt(average(variance))
Packit 8930e1
Packit 8930e1
	global_file.write('min=%.2f\n' % min(global_disk_perf))
Packit 8930e1
	global_file.write('max=%.2f\n' % max(global_disk_perf))
Packit 8930e1
	global_file.write('avg=%.2f\n' % avg)
Packit 8930e1
	global_file.write('stddev=%.2f\n' % standard_deviation)
Packit 8930e1
	global_file.write('values_count=%d\n' % len(global_disk_perf))
Packit 8930e1
	global_file.write('disks_count=%d\n' % len(fio_data_file))
Packit 8930e1
	#print "Global [ min=%.2f max=%.2f avg=%.2f stddev=%.2f \n" % (min(global_disk_perf),max(global_disk_perf),avg, standard_deviation)
Packit 8930e1
Packit 8930e1
	average_file.close()
Packit 8930e1
	min_file.close()
Packit 8930e1
	max_file.close()
Packit 8930e1
	stddev_file.close()
Packit 8930e1
	global_file.close()
Packit 8930e1
	try:
Packit 8930e1
		os.remove(gnuplot_output_dir+'mymath')
Packit 8930e1
	except:
Packit 8930e1
		True
Packit 8930e1
Packit 8930e1
	generate_gnuplot_math_script("Average values of "+title,gnuplot_output_filename+'.average',mode,int(avg),gnuplot_output_dir,gpm_dir)
Packit 8930e1
	generate_gnuplot_math_script("Min values of "+title,gnuplot_output_filename+'.min',mode,average(global_min),gnuplot_output_dir,gpm_dir)
Packit 8930e1
	generate_gnuplot_math_script("Max values of "+title,gnuplot_output_filename+'.max',mode,average(global_max),gnuplot_output_dir,gpm_dir)
Packit 8930e1
	generate_gnuplot_math_script("Standard Deviation of "+title,gnuplot_output_filename+'.stddev',mode,int(standard_deviation),gnuplot_output_dir,gpm_dir)
Packit 8930e1
Packit 8930e1
def parse_global_files(fio_data_file, global_search):
Packit 8930e1
	max_result=0
Packit 8930e1
	max_file=''
Packit 8930e1
	for file in fio_data_file:
Packit 8930e1
		f=open(file)
Packit 8930e1
		disk_count=0
Packit 8930e1
		search_value=-1
Packit 8930e1
Packit 8930e1
		# Let's read the complete file
Packit 8930e1
		while True:
Packit 8930e1
			try:
Packit 8930e1
				# We do split the name from the value
Packit 8930e1
				name,value=f.readline().split("=")
Packit 8930e1
			except:
Packit 8930e1
				f.close()
Packit 8930e1
				break
Packit 8930e1
			# If we ended the file
Packit 8930e1
			if not name:
Packit 8930e1
				# Let's process what we have
Packit 8930e1
				f.close()
Packit 8930e1
				break
Packit 8930e1
			else:
Packit 8930e1
				# disks_count is not global_search item
Packit 8930e1
				# As we need it for some computation, let's save it
Packit 8930e1
				if name=="disks_count":
Packit 8930e1
					disks_count=int(value)
Packit 8930e1
Packit 8930e1
				# Let's catch the searched item
Packit 8930e1
				if global_search in name:
Packit 8930e1
					search_value=float(value)
Packit 8930e1
Packit 8930e1
		# Let's process the avg value by estimated the global bandwidth per file
Packit 8930e1
		# We keep the biggest in memory for reporting
Packit 8930e1
		if global_search == "avg":
Packit 8930e1
			if (disks_count > 0) and (search_value != -1):
Packit 8930e1
				result=disks_count*search_value
Packit 8930e1
				if (result > max_result):
Packit 8930e1
					max_result=result
Packit 8930e1
					max_file=file
Packit 8930e1
	# Let's print the avg output
Packit 8930e1
	if global_search == "avg":
Packit 8930e1
		print("Biggest aggregated value of %s was %2.f in file %s\n" % (global_search, max_result, max_file))
Packit 8930e1
	else:
Packit 8930e1
		print("Global search %s is not yet implemented\n" % global_search)
Packit 8930e1
Packit 8930e1
def render_gnuplot(fio_data_file, gnuplot_output_dir):
Packit 8930e1
	print("Running gnuplot Rendering")
Packit 8930e1
	try:
Packit 8930e1
		# Let's render all the compared files if some
Packit 8930e1
		if len(fio_data_file) > 1:
Packit 8930e1
			if verbose: print(" |-> Rendering comparing traces")
Packit 8930e1
			os.system("cd %s; for i in *.gnuplot; do gnuplot $i; done" % gnuplot_output_dir)
Packit 8930e1
		if verbose: print(" |-> Rendering math traces")
Packit 8930e1
		os.system("cd %s; gnuplot mymath" % gnuplot_output_dir)
Packit 8930e1
		if verbose: print(" |-> Rendering 2D & 3D traces")
Packit 8930e1
		os.system("cd %s; gnuplot mygraph" % gnuplot_output_dir)
Packit 8930e1
Packit 8930e1
		name_of_directory="the current"
Packit 8930e1
		if gnuplot_output_dir != "./":
Packit 8930e1
			name_of_directory=gnuplot_output_dir
Packit 8930e1
		print("\nRendering traces are available in %s directory" % name_of_directory)
Packit 8930e1
		global keep_temp_files
Packit 8930e1
		keep_temp_files=False
Packit 8930e1
	except:
Packit 8930e1
		print("Could not run gnuplot on mymath or mygraph !\n")
Packit 8930e1
		sys.exit(1);
Packit 8930e1
Packit 8930e1
def print_help():
Packit 8930e1
    print('fio2gnuplot -ghbiodvk -t <title> -o <outputfile> -p <pattern> -G <type> -m <time> -M <time>')
Packit 8930e1
    print()
Packit 8930e1
    print('-h --help                           : Print this help')
Packit 8930e1
    print('-p <pattern> or --pattern <pattern> : A glob pattern to select fio input files')
Packit 8930e1
    print('-b           or --bandwidth         : A predefined pattern for selecting *_bw.log files')
Packit 8930e1
    print('-i           or --iops              : A predefined pattern for selecting *_iops.log files')
Packit 8930e1
    print('-g           or --gnuplot           : Render gnuplot traces before exiting')
Packit 8930e1
    print('-o           or --outputfile <file> : The basename for gnuplot traces')
Packit 8930e1
    print('                                       - Basename is set with the pattern if defined')
Packit 8930e1
    print('-d           or --outputdir <dir>   : The directory where gnuplot shall render files')
Packit 8930e1
    print('-t           or --title <title>     : The title of the gnuplot traces')
Packit 8930e1
    print('                                       - Title is set with the block size detected in fio traces')
Packit 8930e1
    print('-G           or --Global <type>     : Search for <type> in .global files match by a pattern')
Packit 8930e1
    print('                                       - Available types are : min, max, avg, stddev')
Packit 8930e1
    print('                                       - The .global extension is added automatically to the pattern')
Packit 8930e1
    print('-m           or --min_time <time>   : Only consider data starting from <time> seconds (default is 0)')
Packit 8930e1
    print('-M           or --max_time <time>   : Only consider data ending before <time> seconds (default is -1 aka nolimit)')
Packit 8930e1
    print('-v           or --verbose           : Increasing verbosity')
Packit 8930e1
    print('-k           or --keep              : Keep all temporary files from gnuplot\'s output dir')
Packit 8930e1
Packit 8930e1
def main(argv):
Packit 8930e1
    mode='unknown'
Packit 8930e1
    pattern=''
Packit 8930e1
    pattern_set_by_user=False
Packit 8930e1
    title='No title'
Packit 8930e1
    gnuplot_output_filename='result'
Packit 8930e1
    gnuplot_output_dir='./'
Packit 8930e1
    gpm_dir="/usr/share/fio/"
Packit 8930e1
    disk_perf=[]
Packit 8930e1
    run_gnuplot=False
Packit 8930e1
    parse_global=False
Packit 8930e1
    global_search=''
Packit 8930e1
    min_time=0
Packit 8930e1
    max_time=-1
Packit 8930e1
    global verbose
Packit 8930e1
    verbose=False
Packit 8930e1
    global temporary_files
Packit 8930e1
    temporary_files=[]
Packit 8930e1
    global keep_temp_files
Packit 8930e1
    keep_temp_files=True
Packit 8930e1
    force_keep_temp_files=False
Packit 8930e1
Packit 8930e1
    if not os.path.isfile(gpm_dir+'math.gpm'):
Packit 8930e1
        gpm_dir="/usr/local/share/fio/"
Packit 8930e1
        if not os.path.isfile(gpm_dir+'math.gpm'):
Packit 8930e1
            print("Looks like fio didn't get installed properly as no gpm files found in '/usr/share/fio' or '/usr/local/share/fio'\n")
Packit 8930e1
            sys.exit(3)
Packit 8930e1
Packit 8930e1
    try:
Packit 8930e1
        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'])
Packit 8930e1
    except getopt.GetoptError:
Packit 8930e1
        print("Error: One of the options passed to the cmdline was not supported")
Packit 8930e1
        print("Please fix your command line or read the help (-h option)")
Packit 8930e1
        sys.exit(2)
Packit 8930e1
Packit 8930e1
    for opt, arg in opts:
Packit 8930e1
        if opt in ("-b", "--bandwidth"):
Packit 8930e1
            pattern='*_bw.log'
Packit 8930e1
        elif opt in ("-i", "--iops"):
Packit 8930e1
            pattern='*_iops.log'
Packit 8930e1
        elif opt in ("-v", "--verbose"):
Packit 8930e1
            verbose=True
Packit 8930e1
        elif opt in ("-k", "--keep"):
Packit 8930e1
            #User really wants to keep the temporary files
Packit 8930e1
            force_keep_temp_files=True
Packit 8930e1
        elif opt in ("-p", "--pattern"):
Packit 8930e1
            pattern_set_by_user=True
Packit 8930e1
            pattern=arg
Packit 8930e1
            pattern=pattern.replace('\\','')
Packit 8930e1
        elif opt in ("-o", "--outputfile"):
Packit 8930e1
            gnuplot_output_filename=arg
Packit 8930e1
        elif opt in ("-d", "--outputdir"):
Packit 8930e1
            gnuplot_output_dir=arg
Packit 8930e1
            if not gnuplot_output_dir.endswith('/'):
Packit 8930e1
                gnuplot_output_dir=gnuplot_output_dir+'/'
Packit 8930e1
            if not os.path.exists(gnuplot_output_dir):
Packit 8930e1
                os.makedirs(gnuplot_output_dir)
Packit 8930e1
        elif opt in ("-t", "--title"):
Packit 8930e1
            title=arg
Packit 8930e1
        elif opt in ("-m", "--min_time"):
Packit 8930e1
            min_time=arg
Packit 8930e1
        elif opt in ("-M", "--max_time"):
Packit 8930e1
            max_time=arg
Packit 8930e1
        elif opt in ("-g", "--gnuplot"):
Packit 8930e1
            run_gnuplot=True
Packit 8930e1
        elif opt in ("-G", "--Global"):
Packit 8930e1
            parse_global=True
Packit 8930e1
            global_search=arg
Packit 8930e1
        elif opt in ("-h", "--help"):
Packit 8930e1
            print_help()
Packit 8930e1
            sys.exit(1)
Packit 8930e1
Packit 8930e1
    # Adding .global extension to the file
Packit 8930e1
    if parse_global==True:
Packit 8930e1
        if not gnuplot_output_filename.endswith('.global'):
Packit 8930e1
            pattern = pattern+'.global'
Packit 8930e1
Packit 8930e1
    fio_data_file=find_file('.',pattern)
Packit 8930e1
    if len(fio_data_file) == 0:
Packit 8930e1
        print("No log file found with pattern %s!" % pattern)
Packit 8930e1
        # Try numjob log file format if per_numjob_logs=1
Packit 8930e1
        if (pattern == '*_bw.log'):
Packit 8930e1
            fio_data_file=find_file('.','*_bw.*.log')
Packit 8930e1
        if (pattern == '*_iops.log'):
Packit 8930e1
            fio_data_file=find_file('.','*_iops.*.log')
Packit 8930e1
        if len(fio_data_file) == 0:
Packit 8930e1
            sys.exit(1)
Packit 8930e1
        else:
Packit 8930e1
            print("Using log file per job format instead")
Packit 8930e1
    else:
Packit 8930e1
        print("%d files Selected with pattern '%s'" % (len(fio_data_file), pattern))
Packit 8930e1
Packit 8930e1
    fio_data_file=sorted(fio_data_file, key=str.lower)
Packit 8930e1
    for file in fio_data_file:
Packit 8930e1
        print(' |-> %s' % file)
Packit 8930e1
        if "_bw.log" in file :
Packit 8930e1
            mode="Bandwidth (KB/sec)"
Packit 8930e1
        if "_iops.log" in file :
Packit 8930e1
            mode="IO per Seconds (IO/sec)"
Packit 8930e1
    if (title == 'No title') and (mode != 'unknown'):
Packit 8930e1
        if "Bandwidth" in mode:
Packit 8930e1
            title='Bandwidth benchmark with %d fio results' % len(fio_data_file)
Packit 8930e1
        if "IO" in mode:
Packit 8930e1
            title='IO benchmark with %d fio results' % len(fio_data_file)
Packit 8930e1
Packit 8930e1
    print()
Packit 8930e1
    #We need to adjust the output filename regarding the pattern required by the user
Packit 8930e1
    if (pattern_set_by_user == True):
Packit 8930e1
        gnuplot_output_filename=pattern
Packit 8930e1
        # As we do have some glob in the pattern, let's make this simpliest
Packit 8930e1
        # We do remove the simpliest parts of the expression to get a clear file name
Packit 8930e1
        gnuplot_output_filename=gnuplot_output_filename.replace('-*-','-')
Packit 8930e1
        gnuplot_output_filename=gnuplot_output_filename.replace('*','-')
Packit 8930e1
        gnuplot_output_filename=gnuplot_output_filename.replace('--','-')
Packit 8930e1
        gnuplot_output_filename=gnuplot_output_filename.replace('.log','')
Packit 8930e1
        # Insure that we don't have any starting or trailing dash to the filename
Packit 8930e1
        gnuplot_output_filename = gnuplot_output_filename[:-1] if gnuplot_output_filename.endswith('-') else gnuplot_output_filename
Packit 8930e1
        gnuplot_output_filename = gnuplot_output_filename[1:] if gnuplot_output_filename.startswith('-') else gnuplot_output_filename
Packit 8930e1
        if (gnuplot_output_filename == ''):
Packit 8930e1
            gnuplot_output_filename='default'
Packit 8930e1
Packit 8930e1
    if parse_global==True:
Packit 8930e1
        parse_global_files(fio_data_file, global_search)
Packit 8930e1
    else:
Packit 8930e1
        blk_size=compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir,min_time,max_time)
Packit 8930e1
        title="%s @ Blocksize = %dK" % (title,blk_size/1024)
Packit 8930e1
        compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir)
Packit 8930e1
        compute_math(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir)
Packit 8930e1
        generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir)
Packit 8930e1
Packit 8930e1
        if (run_gnuplot==True):
Packit 8930e1
            render_gnuplot(fio_data_file, gnuplot_output_dir)
Packit 8930e1
Packit 8930e1
        # Shall we clean the temporary files ?
Packit 8930e1
        if keep_temp_files==False and force_keep_temp_files==False:
Packit 8930e1
            # Cleaning temporary files
Packit 8930e1
            if verbose: print("Cleaning temporary files")
Packit 8930e1
            for f in enumerate(temporary_files):
Packit 8930e1
                if verbose: print(" -> %s"%f[1])
Packit 8930e1
                try:
Packit 8930e1
                    os.remove(f[1])
Packit 8930e1
                except:
Packit 8930e1
                    True
Packit 8930e1
Packit 8930e1
#Main
Packit 8930e1
if __name__ == "__main__":
Packit 8930e1
    sys.exit(main(sys.argv))