| 1 |
#!/usr/bin/env python3 |
| 2 |
# Note: this script is python2 and python3 compatible. |
| 3 |
# |
| 4 |
# Copyright (C) 2013 eNovance SAS <[email protected]> |
| 5 |
# Author: Erwan Velu <[email protected]> |
| 6 |
# |
| 7 |
# The license below covers all files distributed with fio unless otherwise |
| 8 |
# noted in the file itself. |
| 9 |
# |
| 10 |
# This program is free software; you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU General Public License version 2 as |
| 12 |
# published by the Free Software Foundation. |
| 13 |
# |
| 14 |
# This program is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with this program; if not, write to the Free Software |
| 21 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 |
|
| 23 |
from __future__ import absolute_import |
| 24 |
from __future__ import print_function |
| 25 |
import os |
| 26 |
import fnmatch |
| 27 |
import sys |
| 28 |
import getopt |
| 29 |
import re |
| 30 |
import math |
| 31 |
import shutil |
| 32 |
from six.moves import map |
| 33 |
from six.moves import range |
| 34 |
|
| 35 |
def find_file(path, pattern): |
| 36 |
fio_data_file=[] |
| 37 |
# For all the local files |
| 38 |
for file in os.listdir(path): |
| 39 |
# If the file matches the glob |
| 40 |
if fnmatch.fnmatch(file, pattern): |
| 41 |
# Let's consider this file |
| 42 |
fio_data_file.append(file) |
| 43 |
|
| 44 |
return fio_data_file |
| 45 |
|
| 46 |
def generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir): |
| 47 |
if verbose: print("Generating rendering scripts") |
| 48 |
filename=gnuplot_output_dir+'mygraph' |
| 49 |
temporary_files.append(filename) |
| 50 |
f=open(filename,'w') |
| 51 |
|
| 52 |
# Plotting 3D or comparing graphs doesn't have a meaning unless if there is at least 2 traces |
| 53 |
if len(fio_data_file) > 1: |
| 54 |
f.write("call \'%s/graph3D.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\'\n" % (gpm_dir,title,gnuplot_output_filename,gnuplot_output_filename,mode)) |
| 55 |
|
| 56 |
# Setting up the compare files that will be plot later |
| 57 |
compare=open(gnuplot_output_dir + 'compare.gnuplot','w') |
| 58 |
compare.write(''' |
| 59 |
set title '%s' |
| 60 |
set terminal png size 1280,1024 |
| 61 |
set ytics axis out auto |
| 62 |
set key top left reverse |
| 63 |
set xlabel "Time (Seconds)" |
| 64 |
set ylabel '%s' |
| 65 |
set yrange [0:] |
| 66 |
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "green" |
| 67 |
'''% (title,mode)) |
| 68 |
compare.close() |
| 69 |
#Copying the common file for all kind of graph (raw/smooth/trend) |
| 70 |
compare_raw_filename="compare-%s-2Draw" % (gnuplot_output_filename) |
| 71 |
compare_smooth_filename="compare-%s-2Dsmooth" % (gnuplot_output_filename) |
| 72 |
compare_trend_filename="compare-%s-2Dtrend" % (gnuplot_output_filename) |
| 73 |
|
| 74 |
shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_raw_filename+".gnuplot") |
| 75 |
shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_smooth_filename+".gnuplot") |
| 76 |
shutil.copy(gnuplot_output_dir+'compare.gnuplot',gnuplot_output_dir+compare_trend_filename+".gnuplot") |
| 77 |
temporary_files.append(gnuplot_output_dir+compare_raw_filename+".gnuplot") |
| 78 |
temporary_files.append(gnuplot_output_dir+compare_smooth_filename+".gnuplot") |
| 79 |
temporary_files.append(gnuplot_output_dir+compare_trend_filename+".gnuplot") |
| 80 |
|
| 81 |
#Setting up a different output filename for each kind of graph |
| 82 |
compare_raw=open(gnuplot_output_dir+compare_raw_filename + ".gnuplot",'a') |
| 83 |
compare_raw.write("set output '%s.png'\n" % compare_raw_filename) |
| 84 |
compare_smooth=open(gnuplot_output_dir+compare_smooth_filename+".gnuplot",'a') |
| 85 |
compare_smooth.write("set output '%s.png'\n" % compare_smooth_filename) |
| 86 |
compare_trend=open(gnuplot_output_dir+compare_trend_filename+".gnuplot",'a') |
| 87 |
compare_trend.write("set output '%s.png'\n" % compare_trend_filename) |
| 88 |
|
| 89 |
# Let's plot the average value for all the traces |
| 90 |
global_disk_perf = sum(disk_perf, []) |
| 91 |
global_avg = average(global_disk_perf) |
| 92 |
compare_raw.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg)); |
| 93 |
compare_smooth.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg)); |
| 94 |
compare_trend.write("plot %s w l ls 1 ti 'Global average value (%.2f)'" % (global_avg,global_avg)); |
| 95 |
|
| 96 |
pos=0 |
| 97 |
# Let's create a temporary file for each selected fio file |
| 98 |
for file in fio_data_file: |
| 99 |
tmp_filename = "gnuplot_temp_file.%d" % pos |
| 100 |
|
| 101 |
# Plotting comparing graphs doesn't have a meaning unless if there is at least 2 traces |
| 102 |
if len(fio_data_file) > 1: |
| 103 |
# Adding the plot instruction for each kind of comparing graphs |
| 104 |
compare_raw.write(",\\\n'%s' using 2:3 with linespoints title '%s'" % (tmp_filename,fio_data_file[pos])) |
| 105 |
compare_smooth.write(",\\\n'%s' using 2:3 smooth csplines title '%s'" % (tmp_filename,fio_data_file[pos])) |
| 106 |
compare_trend.write(",\\\n'%s' using 2:3 smooth bezier title '%s'" % (tmp_filename,fio_data_file[pos])) |
| 107 |
|
| 108 |
png_file=file.replace('.log','') |
| 109 |
raw_filename = "%s-2Draw" % (png_file) |
| 110 |
smooth_filename = "%s-2Dsmooth" % (png_file) |
| 111 |
trend_filename = "%s-2Dtrend" % (png_file) |
| 112 |
avg = average(disk_perf[pos]) |
| 113 |
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)) |
| 114 |
pos = pos +1 |
| 115 |
|
| 116 |
# Plotting comparing graphs doesn't have a meaning unless if there is at least 2 traces |
| 117 |
if len(fio_data_file) > 1: |
| 118 |
os.remove(gnuplot_output_dir+"compare.gnuplot") |
| 119 |
compare_raw.close() |
| 120 |
compare_smooth.close() |
| 121 |
compare_trend.close() |
| 122 |
f.close() |
| 123 |
|
| 124 |
def generate_gnuplot_math_script(title,gnuplot_output_filename,mode,average,gnuplot_output_dir,gpm_dir): |
| 125 |
filename=gnuplot_output_dir+'mymath'; |
| 126 |
temporary_files.append(filename) |
| 127 |
f=open(filename,'a') |
| 128 |
f.write("call \'%s/math.gpm\' \'%s' \'%s\' \'\' \'%s\' \'%s\' %s\n" % (gpm_dir,title,gnuplot_output_filename,gnuplot_output_filename,mode,average)) |
| 129 |
f.close() |
| 130 |
|
| 131 |
def compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir): |
| 132 |
if verbose: print("Processing data file 2/2") |
| 133 |
temp_files=[] |
| 134 |
pos=0 |
| 135 |
|
| 136 |
# Let's create a temporary file for each selected fio file |
| 137 |
for file in fio_data_file: |
| 138 |
tmp_filename = "%sgnuplot_temp_file.%d" % (gnuplot_output_dir, pos) |
| 139 |
temp_files.append(open(tmp_filename,'r')) |
| 140 |
pos = pos +1 |
| 141 |
|
| 142 |
f = open(gnuplot_output_dir+gnuplot_output_filename, "w") |
| 143 |
temporary_files.append(gnuplot_output_dir+gnuplot_output_filename) |
| 144 |
index=0 |
| 145 |
# Let's add some information |
| 146 |
for tempfile in temp_files: |
| 147 |
f.write("# Disk%d was coming from %s\n" % (index,fio_data_file[index])) |
| 148 |
f.write(tempfile.read()) |
| 149 |
f.write("\n") |
| 150 |
tempfile.close() |
| 151 |
index = index + 1 |
| 152 |
f.close() |
| 153 |
|
| 154 |
def average(s): return sum(s) * 1.0 / len(s) |
| 155 |
|
| 156 |
def compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir, min_time, max_time): |
| 157 |
end_time=max_time |
| 158 |
if end_time == -1: |
| 159 |
end_time="infinite" |
| 160 |
if verbose: print("Processing data file 1/2 with %s<time<%s" % (min_time,end_time)) |
| 161 |
files=[] |
| 162 |
temp_outfile=[] |
| 163 |
blk_size=0 |
| 164 |
for file in fio_data_file: |
| 165 |
files.append(open(file)) |
| 166 |
pos = len(files) - 1 |
| 167 |
tmp_filename = "%sgnuplot_temp_file.%d" % (gnuplot_output_dir,pos) |
| 168 |
temporary_files.append(tmp_filename) |
| 169 |
gnuplot_file=open(tmp_filename,'w') |
| 170 |
temp_outfile.append(gnuplot_file) |
| 171 |
gnuplot_file.write("#Temporary file based on file %s\n" % file) |
| 172 |
disk_perf.append([]) |
| 173 |
|
| 174 |
shall_break = False |
| 175 |
while True: |
| 176 |
current_line=[] |
| 177 |
nb_empty_files=0 |
| 178 |
nb_files=len(files) |
| 179 |
for myfile in files: |
| 180 |
s=myfile.readline().replace(',',' ').split() |
| 181 |
if not s: |
| 182 |
nb_empty_files+=1 |
| 183 |
s="-1, 0, 0, 0".replace(',',' ').split() |
| 184 |
|
| 185 |
if (nb_empty_files == nb_files): |
| 186 |
shall_break=True |
| 187 |
break; |
| 188 |
|
| 189 |
current_line.append(s); |
| 190 |
|
| 191 |
if shall_break == True: |
| 192 |
break |
| 193 |
|
| 194 |
last_time = -1 |
| 195 |
index=-1 |
| 196 |
perfs=[] |
| 197 |
for line in enumerate(current_line): |
| 198 |
# Index will be used to remember what file was featuring what value |
| 199 |
index=index+1 |
| 200 |
|
| 201 |
time, perf, x, block_size = line[1][:4] |
| 202 |
if (blk_size == 0): |
| 203 |
try: |
| 204 |
blk_size=int(block_size) |
| 205 |
except: |
| 206 |
print("Error while reading the following line :") |
| 207 |
print(line) |
| 208 |
sys.exit(1); |
| 209 |
|
| 210 |
# We ignore the first 500msec as it doesn't seems to be part of the real benchmark |
| 211 |
# Time < 500 usually reports BW=0 breaking the min computing |
| 212 |
if (min_time == 0): |
| 213 |
min_time==0.5 |
| 214 |
|
| 215 |
# Then we estimate if the data we got is part of the time range we want to plot |
| 216 |
if ((float(time)>(float(min_time)*1000)) and ((int(time) < (int(max_time)*1000)) or max_time==-1)): |
| 217 |
disk_perf[index].append(int(perf)) |
| 218 |
perfs.append("%d %s %s"% (index, time, perf)) |
| 219 |
|
| 220 |
# If we reach this point, it means that all the traces are coherent |
| 221 |
for p in enumerate(perfs): |
| 222 |
index, perf_time,perf = p[1].split() |
| 223 |
temp_outfile[int(index)].write("%s %.2f %s\n" % (index, float(float(perf_time)/1000), perf)) |
| 224 |
|
| 225 |
|
| 226 |
for file in files: |
| 227 |
file.close() |
| 228 |
for file in temp_outfile: |
| 229 |
file.close() |
| 230 |
return blk_size |
| 231 |
|
| 232 |
def compute_math(fio_data_file, title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir): |
| 233 |
if verbose: print("Computing Maths") |
| 234 |
global_min=[] |
| 235 |
global_max=[] |
| 236 |
average_file=open(gnuplot_output_dir+gnuplot_output_filename+'.average', 'w') |
| 237 |
min_file=open(gnuplot_output_dir+gnuplot_output_filename+'.min', 'w') |
| 238 |
max_file=open(gnuplot_output_dir+gnuplot_output_filename+'.max', 'w') |
| 239 |
stddev_file=open(gnuplot_output_dir+gnuplot_output_filename+'.stddev', 'w') |
| 240 |
global_file=open(gnuplot_output_dir+gnuplot_output_filename+'.global','w') |
| 241 |
temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.average') |
| 242 |
temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.min') |
| 243 |
temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.max') |
| 244 |
temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.stddev') |
| 245 |
temporary_files.append(gnuplot_output_dir+gnuplot_output_filename+'.global') |
| 246 |
|
| 247 |
min_file.write('DiskName %s\n' % mode) |
| 248 |
max_file.write('DiskName %s\n'% mode) |
| 249 |
average_file.write('DiskName %s\n'% mode) |
| 250 |
stddev_file.write('DiskName %s\n'% mode ) |
| 251 |
for disk in range(len(fio_data_file)): |
| 252 |
# print disk_perf[disk] |
| 253 |
min_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk])) |
| 254 |
max_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk])) |
| 255 |
average_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk])) |
| 256 |
stddev_file.write("# Disk%d was coming from %s\n" % (disk,fio_data_file[disk])) |
| 257 |
avg = average(disk_perf[disk]) |
| 258 |
variance = [(x - avg)**2 for x in disk_perf[disk]] |
| 259 |
standard_deviation = math.sqrt(average(variance)) |
| 260 |
# print "Disk%d [ min=%.2f max=%.2f avg=%.2f stddev=%.2f \n" % (disk,min(disk_perf[disk]),max(disk_perf[disk]),avg, standard_deviation) |
| 261 |
average_file.write('%d %d\n' % (disk, avg)) |
| 262 |
stddev_file.write('%d %d\n' % (disk, standard_deviation)) |
| 263 |
local_min=min(disk_perf[disk]) |
| 264 |
local_max=max(disk_perf[disk]) |
| 265 |
min_file.write('%d %d\n' % (disk, local_min)) |
| 266 |
max_file.write('%d %d\n' % (disk, local_max)) |
| 267 |
global_min.append(int(local_min)) |
| 268 |
global_max.append(int(local_max)) |
| 269 |
|
| 270 |
global_disk_perf = sum(disk_perf, []) |
| 271 |
avg = average(global_disk_perf) |
| 272 |
variance = [(x - avg)**2 for x in global_disk_perf] |
| 273 |
standard_deviation = math.sqrt(average(variance)) |
| 274 |
|
| 275 |
global_file.write('min=%.2f\n' % min(global_disk_perf)) |
| 276 |
global_file.write('max=%.2f\n' % max(global_disk_perf)) |
| 277 |
global_file.write('avg=%.2f\n' % avg) |
| 278 |
global_file.write('stddev=%.2f\n' % standard_deviation) |
| 279 |
global_file.write('values_count=%d\n' % len(global_disk_perf)) |
| 280 |
global_file.write('disks_count=%d\n' % len(fio_data_file)) |
| 281 |
#print "Global [ min=%.2f max=%.2f avg=%.2f stddev=%.2f \n" % (min(global_disk_perf),max(global_disk_perf),avg, standard_deviation) |
| 282 |
|
| 283 |
average_file.close() |
| 284 |
min_file.close() |
| 285 |
max_file.close() |
| 286 |
stddev_file.close() |
| 287 |
global_file.close() |
| 288 |
try: |
| 289 |
os.remove(gnuplot_output_dir+'mymath') |
| 290 |
except: |
| 291 |
True |
| 292 |
|
| 293 |
generate_gnuplot_math_script("Average values of "+title,gnuplot_output_filename+'.average',mode,int(avg),gnuplot_output_dir,gpm_dir) |
| 294 |
generate_gnuplot_math_script("Min values of "+title,gnuplot_output_filename+'.min',mode,average(global_min),gnuplot_output_dir,gpm_dir) |
| 295 |
generate_gnuplot_math_script("Max values of "+title,gnuplot_output_filename+'.max',mode,average(global_max),gnuplot_output_dir,gpm_dir) |
| 296 |
generate_gnuplot_math_script("Standard Deviation of "+title,gnuplot_output_filename+'.stddev',mode,int(standard_deviation),gnuplot_output_dir,gpm_dir) |
| 297 |
|
| 298 |
def parse_global_files(fio_data_file, global_search): |
| 299 |
max_result=0 |
| 300 |
max_file='' |
| 301 |
for file in fio_data_file: |
| 302 |
f=open(file) |
| 303 |
disk_count=0 |
| 304 |
search_value=-1 |
| 305 |
|
| 306 |
# Let's read the complete file |
| 307 |
while True: |
| 308 |
try: |
| 309 |
# We do split the name from the value |
| 310 |
name,value=f.readline().split("=") |
| 311 |
except: |
| 312 |
f.close() |
| 313 |
break |
| 314 |
# If we ended the file |
| 315 |
if not name: |
| 316 |
# Let's process what we have |
| 317 |
f.close() |
| 318 |
break |
| 319 |
else: |
| 320 |
# disks_count is not global_search item |
| 321 |
# As we need it for some computation, let's save it |
| 322 |
if name=="disks_count": |
| 323 |
disks_count=int(value) |
| 324 |
|
| 325 |
# Let's catch the searched item |
| 326 |
if global_search in name: |
| 327 |
search_value=float(value) |
| 328 |
|
| 329 |
# Let's process the avg value by estimated the global bandwidth per file |
| 330 |
# We keep the biggest in memory for reporting |
| 331 |
if global_search == "avg": |
| 332 |
if (disks_count > 0) and (search_value != -1): |
| 333 |
result=disks_count*search_value |
| 334 |
if (result > max_result): |
| 335 |
max_result=result |
| 336 |
max_file=file |
| 337 |
# Let's print the avg output |
| 338 |
if global_search == "avg": |
| 339 |
print("Biggest aggregated value of %s was %2.f in file %s\n" % (global_search, max_result, max_file)) |
| 340 |
else: |
| 341 |
print("Global search %s is not yet implemented\n" % global_search) |
| 342 |
|
| 343 |
def render_gnuplot(fio_data_file, gnuplot_output_dir): |
| 344 |
print("Running gnuplot Rendering") |
| 345 |
try: |
| 346 |
# Let's render all the compared files if some |
| 347 |
if len(fio_data_file) > 1: |
| 348 |
if verbose: print(" |-> Rendering comparing traces") |
| 349 |
os.system("cd %s; for i in *.gnuplot; do gnuplot $i; done" % gnuplot_output_dir) |
| 350 |
if verbose: print(" |-> Rendering math traces") |
| 351 |
os.system("cd %s; gnuplot mymath" % gnuplot_output_dir) |
| 352 |
if verbose: print(" |-> Rendering 2D & 3D traces") |
| 353 |
os.system("cd %s; gnuplot mygraph" % gnuplot_output_dir) |
| 354 |
|
| 355 |
name_of_directory="the current" |
| 356 |
if gnuplot_output_dir != "./": |
| 357 |
name_of_directory=gnuplot_output_dir |
| 358 |
print("\nRendering traces are available in %s directory" % name_of_directory) |
| 359 |
global keep_temp_files |
| 360 |
keep_temp_files=False |
| 361 |
except: |
| 362 |
print("Could not run gnuplot on mymath or mygraph !\n") |
| 363 |
sys.exit(1); |
| 364 |
|
| 365 |
def print_help(): |
| 366 |
print('fio2gnuplot -ghbiodvk -t <title> -o <outputfile> -p <pattern> -G <type> -m <time> -M <time>') |
| 367 |
print() |
| 368 |
print('-h --help : Print this help') |
| 369 |
print('-p <pattern> or --pattern <pattern> : A glob pattern to select fio input files') |
| 370 |
print('-b or --bandwidth : A predefined pattern for selecting *_bw.log files') |
| 371 |
print('-i or --iops : A predefined pattern for selecting *_iops.log files') |
| 372 |
print('-g or --gnuplot : Render gnuplot traces before exiting') |
| 373 |
print('-o or --outputfile <file> : The basename for gnuplot traces') |
| 374 |
print(' - Basename is set with the pattern if defined') |
| 375 |
print('-d or --outputdir <dir> : The directory where gnuplot shall render files') |
| 376 |
print('-t or --title <title> : The title of the gnuplot traces') |
| 377 |
print(' - Title is set with the block size detected in fio traces') |
| 378 |
print('-G or --Global <type> : Search for <type> in .global files match by a pattern') |
| 379 |
print(' - Available types are : min, max, avg, stddev') |
| 380 |
print(' - The .global extension is added automatically to the pattern') |
| 381 |
print('-m or --min_time <time> : Only consider data starting from <time> seconds (default is 0)') |
| 382 |
print('-M or --max_time <time> : Only consider data ending before <time> seconds (default is -1 aka nolimit)') |
| 383 |
print('-v or --verbose : Increasing verbosity') |
| 384 |
print('-k or --keep : Keep all temporary files from gnuplot\'s output dir') |
| 385 |
|
| 386 |
def main(argv): |
| 387 |
mode='unknown' |
| 388 |
pattern='' |
| 389 |
pattern_set_by_user=False |
| 390 |
title='No title' |
| 391 |
gnuplot_output_filename='result' |
| 392 |
gnuplot_output_dir='./' |
| 393 |
gpm_dir="/usr/share/fio/" |
| 394 |
disk_perf=[] |
| 395 |
run_gnuplot=False |
| 396 |
parse_global=False |
| 397 |
global_search='' |
| 398 |
min_time=0 |
| 399 |
max_time=-1 |
| 400 |
global verbose |
| 401 |
verbose=False |
| 402 |
global temporary_files |
| 403 |
temporary_files=[] |
| 404 |
global keep_temp_files |
| 405 |
keep_temp_files=True |
| 406 |
force_keep_temp_files=False |
| 407 |
|
| 408 |
if not os.path.isfile(gpm_dir+'math.gpm'): |
| 409 |
gpm_dir="/usr/local/share/fio/" |
| 410 |
if not os.path.isfile(gpm_dir+'math.gpm'): |
| 411 |
print("Looks like fio didn't get installed properly as no gpm files found in '/usr/share/fio' or '/usr/local/share/fio'\n") |
| 412 |
sys.exit(3) |
| 413 |
|
| 414 |
try: |
| 415 |
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']) |
| 416 |
except getopt.GetoptError: |
| 417 |
print("Error: One of the options passed to the cmdline was not supported") |
| 418 |
print("Please fix your command line or read the help (-h option)") |
| 419 |
sys.exit(2) |
| 420 |
|
| 421 |
for opt, arg in opts: |
| 422 |
if opt in ("-b", "--bandwidth"): |
| 423 |
pattern='*_bw.log' |
| 424 |
elif opt in ("-i", "--iops"): |
| 425 |
pattern='*_iops.log' |
| 426 |
elif opt in ("-v", "--verbose"): |
| 427 |
verbose=True |
| 428 |
elif opt in ("-k", "--keep"): |
| 429 |
#User really wants to keep the temporary files |
| 430 |
force_keep_temp_files=True |
| 431 |
elif opt in ("-p", "--pattern"): |
| 432 |
pattern_set_by_user=True |
| 433 |
pattern=arg |
| 434 |
pattern=pattern.replace('\\','') |
| 435 |
elif opt in ("-o", "--outputfile"): |
| 436 |
gnuplot_output_filename=arg |
| 437 |
elif opt in ("-d", "--outputdir"): |
| 438 |
gnuplot_output_dir=arg |
| 439 |
if not gnuplot_output_dir.endswith('/'): |
| 440 |
gnuplot_output_dir=gnuplot_output_dir+'/' |
| 441 |
if not os.path.exists(gnuplot_output_dir): |
| 442 |
os.makedirs(gnuplot_output_dir) |
| 443 |
elif opt in ("-t", "--title"): |
| 444 |
title=arg |
| 445 |
elif opt in ("-m", "--min_time"): |
| 446 |
min_time=arg |
| 447 |
elif opt in ("-M", "--max_time"): |
| 448 |
max_time=arg |
| 449 |
elif opt in ("-g", "--gnuplot"): |
| 450 |
run_gnuplot=True |
| 451 |
elif opt in ("-G", "--Global"): |
| 452 |
parse_global=True |
| 453 |
global_search=arg |
| 454 |
elif opt in ("-h", "--help"): |
| 455 |
print_help() |
| 456 |
sys.exit(1) |
| 457 |
|
| 458 |
# Adding .global extension to the file |
| 459 |
if parse_global==True: |
| 460 |
if not gnuplot_output_filename.endswith('.global'): |
| 461 |
pattern = pattern+'.global' |
| 462 |
|
| 463 |
fio_data_file=find_file('.',pattern) |
| 464 |
if len(fio_data_file) == 0: |
| 465 |
print("No log file found with pattern %s!" % pattern) |
| 466 |
# Try numjob log file format if per_numjob_logs=1 |
| 467 |
if (pattern == '*_bw.log'): |
| 468 |
fio_data_file=find_file('.','*_bw.*.log') |
| 469 |
if (pattern == '*_iops.log'): |
| 470 |
fio_data_file=find_file('.','*_iops.*.log') |
| 471 |
if len(fio_data_file) == 0: |
| 472 |
sys.exit(1) |
| 473 |
else: |
| 474 |
print("Using log file per job format instead") |
| 475 |
else: |
| 476 |
print("%d files Selected with pattern '%s'" % (len(fio_data_file), pattern)) |
| 477 |
|
| 478 |
fio_data_file=sorted(fio_data_file, key=str.lower) |
| 479 |
for file in fio_data_file: |
| 480 |
print(' |-> %s' % file) |
| 481 |
if "_bw.log" in file : |
| 482 |
mode="Bandwidth (KB/sec)" |
| 483 |
if "_iops.log" in file : |
| 484 |
mode="IO per Seconds (IO/sec)" |
| 485 |
if (title == 'No title') and (mode != 'unknown'): |
| 486 |
if "Bandwidth" in mode: |
| 487 |
title='Bandwidth benchmark with %d fio results' % len(fio_data_file) |
| 488 |
if "IO" in mode: |
| 489 |
title='IO benchmark with %d fio results' % len(fio_data_file) |
| 490 |
|
| 491 |
print() |
| 492 |
#We need to adjust the output filename regarding the pattern required by the user |
| 493 |
if (pattern_set_by_user == True): |
| 494 |
gnuplot_output_filename=pattern |
| 495 |
# As we do have some glob in the pattern, let's make this simplest |
| 496 |
# We do remove the simplest parts of the expression to get a clear file name |
| 497 |
gnuplot_output_filename=gnuplot_output_filename.replace('-*-','-') |
| 498 |
gnuplot_output_filename=gnuplot_output_filename.replace('*','-') |
| 499 |
gnuplot_output_filename=gnuplot_output_filename.replace('--','-') |
| 500 |
gnuplot_output_filename=gnuplot_output_filename.replace('.log','') |
| 501 |
# Insure that we don't have any starting or trailing dash to the filename |
| 502 |
gnuplot_output_filename = gnuplot_output_filename[:-1] if gnuplot_output_filename.endswith('-') else gnuplot_output_filename |
| 503 |
gnuplot_output_filename = gnuplot_output_filename[1:] if gnuplot_output_filename.startswith('-') else gnuplot_output_filename |
| 504 |
if (gnuplot_output_filename == ''): |
| 505 |
gnuplot_output_filename='default' |
| 506 |
|
| 507 |
if parse_global==True: |
| 508 |
parse_global_files(fio_data_file, global_search) |
| 509 |
else: |
| 510 |
blk_size=compute_temp_file(fio_data_file,disk_perf,gnuplot_output_dir,min_time,max_time) |
| 511 |
title="%s @ Blocksize = %dK" % (title,blk_size/1024) |
| 512 |
compute_aggregated_file(fio_data_file, gnuplot_output_filename, gnuplot_output_dir) |
| 513 |
compute_math(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir) |
| 514 |
generate_gnuplot_script(fio_data_file,title,gnuplot_output_filename,gnuplot_output_dir,mode,disk_perf,gpm_dir) |
| 515 |
|
| 516 |
if (run_gnuplot==True): |
| 517 |
render_gnuplot(fio_data_file, gnuplot_output_dir) |
| 518 |
|
| 519 |
# Shall we clean the temporary files ? |
| 520 |
if keep_temp_files==False and force_keep_temp_files==False: |
| 521 |
# Cleaning temporary files |
| 522 |
if verbose: print("Cleaning temporary files") |
| 523 |
for f in enumerate(temporary_files): |
| 524 |
if verbose: print(" -> %s"%f[1]) |
| 525 |
try: |
| 526 |
os.remove(f[1]) |
| 527 |
except: |
| 528 |
True |
| 529 |
|
| 530 |
#Main |
| 531 |
if __name__ == "__main__": |
| 532 |
sys.exit(main(sys.argv)) |