#!/usr/software/bin/python # # File: mod_3x_plot.py # Version: 1 # Date: 18 Nov 2011 # Description: Plots charts from NetApp input file # Usage: mod_3x_plot.py # Input File : _python.txt # Example: /usr/software/bin/python mod_3x_plot.py filer-iso.txt # Author : arunak@netapp.com # Change : from author: # Description of the change: < Description > # ############### # EXTERNAL LIB ############### import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import sys, string, re, os, getopt from collections import deque from pylab import * from matplotlib.ticker import MultipleLocator, FormatStrFormatter ############### #GLOBAL VARIABLES ############### count =0 xvalue = [] yvalue = [] y1value = [] xname = "" yname = "" total_count = "" app_name = "" infh = None chart_list ="" file = "" header_name = "" output_fmt = "png" test_name = "" outputdir = "." kernel_name = "" prd_id = "" legend_name ="" t_name ="" driv_id = "" ############## #COMMAND LINE FUNCTIONS ############# def help_content(): print "COMMON PLOT HELP FILE" print "========================================================" print "This script will plot the chart for the given input-file" print "========================================================" print "" print "Usage:" print " mod_3x_plot.py " print "" print "Help Option:" print "-h displays help an usage of program" print "" print "Advance Option:" print "-o directory where output files are created" print " defaults to '.'" print " directory must exist before using this option" print "" print "Advance Option Usage:" print " mod_3x_plot.py -o " print "" print "Note : Input file should be in specified format, to plot chart successfully" ############### #COMMAND LINE ARGUMENTS ############### app_name = os.path.basename(sys.argv[0]) try: opts, args = getopt.getopt(sys.argv[1:],"ho:",["help","outdir"]) except getopt.GetoptError, err: print str(err) sys.exit(0) for opt, optval in opts: if opt in ("-h", "--help"): # help with usage help_content() sys.exit(0) elif opt in ("-o", "--outdir"): # output directory outputdir = optval else: assert False, "unhandled command line option" #cmdl_arg = len(sys.argv) if len(args) > 1: print "%s: too many input files specified" % app_name sys.exit(0) if len(args) == 0: print "%s: missing " % app_name sys.exit(0) else: file = args[0] ############### #FUNCTIONS TO PLOT GRAPH AND TO RESET VALUES ############### def a3axis_sub(total_count,test_name): count = 0 while (count < total_count): print "Total count",total_count print "Count -",count list_item = chart_list[count] infh = open(file, "r") for line in infh: if re.match(list_item,line): header = re.match(r"(\w+)\s(.*):(.*)", line) if header != None: header_name = header.group(3) t_name = header.group(2) # print "tname-",t_name else: print "Please Provide header name" break line = infh.next() line=line.replace('=',',') line=line.strip() xaxis_list = line.split(',') xname = xaxis_list.pop(0) # print "Name-",xname xvalue = [] xvalue = xaxis_list # print xname,xvalue line = infh.next() line=line.replace('=',',') line=line.strip() yaxis_list = line.split(',') yname = yaxis_list.pop(0) yvalue = yaxis_list # print yname,yvalue line = infh.next() line=line.replace('=',',') line=line.strip() y1axis_list = line.split(',') y1name = y1axis_list.pop(0) y1value = [] y1value = y1axis_list # print y1name,y1value line = infh.next() line=line.replace('=',',') line=line.strip() y2axis_list = line.split(',') y2name = y2axis_list.pop(0) y2value = [] y2value = y2axis_list # print y2name,y2value line = infh.next() line=line.replace('=',',') line=line.strip() y3axis_list = line.split(',') y3name = y3axis_list.pop(0) y3value = [] y3value = y3axis_list # print y3name,y3value line = infh.next() line=line.replace('=',',') line=line.strip() y4axis_list = line.split(',') y4name = y4axis_list.pop(0) y4value = [] y4value = y4axis_list # print y4name,y4value line = infh.next() line=line.replace('=',',') line=line.strip() y5axis_list = line.split(',') y5name = y5axis_list.pop(0) y5value = [] y5value = y5axis_list # print y5name,y5value line = infh.next() xsv= re.match(r"^(\w+)\s+=(\w+)",line) if xsv != None: line=line.replace('=',',') line=line.strip() y6axis_list = line.split(',') y6name = y6axis_list.pop(0) y6value = [] y6value = y6axis_list # print y6name,y6value line = infh.next() tst=re.match(r"^(\w+)\s+=(\w+)",line) if tst!= None: line=line.replace('=',',') line=line.strip() y7axis_list = line.split(',') y7name = y7axis_list.pop(0) y7value = [] y7value = y7axis_list # print y7name,y7value header_name_t = "" header_name_t += "Test_Name : %s\n " %(test_name) header_name_t += "Kernel_Name : %s " %(kernel_name) # header_name_t += "Product_ID : %s \n" %(prd_id) header_name_t += "Drive_ID : %s \n" %(driv_id) header_name_t += "Title : %s - %s \n" %(t_name,header_name) if t_name == "1tf" or t_name == "1tg": plot_3axisgraph_fg(header_name_t,xvalue,yvalue,y1value,y2value,y3value,test_name,t_name,driv_id) plot_3axisgraph_fg2(header_name_t,xvalue,y4value,y5value,y6value,y7value,test_name,t_name,driv_id) elif t_name == "1ta" or t_name == "1tb" or t_name == "1tc": plot_2axis_graph(header_name_t,xvalue,yvalue,y1value,y2value,y3value,y4value,y5value,test_name,t_name,driv_id) elif t_name == "1td" or t_name == "1te": plot_2axis_3ele(header_name_t,xvalue,y3value,y4value,y5value,test_name,t_name,driv_id) else: plot_3axisgraph(header_name_t,xvalue,yvalue,y1value,y2value,y3value,y4value,y5value,test_name,t_name,driv_id) count = count + 1 #function to Plot 3 axis graph def plot_3axisgraph(title,x,ODrate,MDrate,IDrate,ODIOPS,MDIOPS,IDIOPS,test_name,t_name,driv_id): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) plt.grid(True) plt.suptitle(title, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) #ax1.set_ylim(0,180) ax1.set_xlim(8,512) #Plot data ax1.plot(x,ODrate, 'r-^',label="ODRATE") ax1.plot(x,MDrate,'g-s',label="MDRATE") ax1.plot(x,IDrate, 'b-*',label="IDRATE") plt.ylabel('MB/s') plt.xlabel('Block') box = ax1.get_position() ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax1.legend(loc='center left', bbox_to_anchor=(1.11, 0.90),fancybox=True, shadow=True, ncol=1) # plt.legend(loc='upper center', bbox_to_anchor=(-0.5, 0.19),fancybox=True, shadow=True, ncol=5) #plot data2 ax2= ax1.twinx() ax2.plot(x, ODIOPS, 'k-o',label="ODIOPS") ax2.plot(x, MDIOPS, 'm-d',label="MDIOPS") ax2.plot(x, IDIOPS, 'y-p',label="IDIOPS") box = ax2.get_position() ax2.set_position([box.x0, box.y0 + box.height * 0.1,box.width, box.height * 0.9]) ax2.legend(loc='center left', bbox_to_anchor=(1.12, -0.01),fancybox=True, shadow=True, ncol=1) # ax2.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15),fancybox=True, shadow=True, ncol=5) plt.xlabel('BLOCK') plt.ylabel('IOPS') chart_name = "%s%s%s_%s_%s.%s" % (outputdir,os.sep,t_name,test_name,driv_id,output_fmt) plt.savefig(chart_name) plt.clf() reset_values() #function to Plot 1tf and 1tg axis graph def plot_3axisgraph_fg(title,x,MS_Q1,MS_Q2,IOPS_Q1,IOPS_Q2,test_name,t_name,driv_id): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) plt.grid(True) plt.suptitle(title, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) #Plot data ax1.plot(x,MS_Q1, 'r-^',label="MS_Q1") ax1.plot(x,MS_Q2,'g-s',label="MS_Q2") plt.ylabel('MB/s') plt.xlabel('Block') box = ax1.get_position() ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax1.legend(loc='center left', bbox_to_anchor=(1.11, 0.90),fancybox=True, shadow=True, ncol=1) # plt.legend(loc='upper center', bbox_to_anchor=(-0.5, 0.19),fancybox=True, shadow=True, ncol=5) #plot data2 ax2= ax1.twinx() ax2.plot(x, IOPS_Q1, 'k-o',label="IOPS_Q1") ax2.plot(x, IOPS_Q2, 'm-d',label="IOPS_Q2") box = ax2.get_position() ax2.set_position([box.x0, box.y0 + box.height * 0.1,box.width, box.height * 0.9]) ax2.legend(loc='center left', bbox_to_anchor=(1.11, -0.01),fancybox=True, shadow=True, ncol=1) # ax2.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15),fancybox=True, shadow=True, ncol=5) plt.xlabel('BLOCK') plt.ylabel('IOPS') chart_name = "%s%s%s_%s_%s.%s" % (outputdir,os.sep,t_name,test_name,driv_id,output_fmt) plt.savefig(chart_name) plt.clf() reset_values() def plot_3axisgraph_fg2(title,x,MS_Q3,MS_Q4,IOPS_Q3,IOPS_Q4,test_name,t_name,driv_id): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) plt.grid(True) plt.suptitle(title, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) sub_name = "Subplot" #Plot data ax1.plot(x,MS_Q3, 'r-^',label="MS_Q3") ax1.plot(x,MS_Q4,'g-s',label="MS_Q4") plt.ylabel('MB/s') plt.xlabel('Block') box = ax1.get_position() ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax1.legend(loc='center left', bbox_to_anchor=(1.11, 0.90),fancybox=True, shadow=True, ncol=1) #plot data2 ax2= ax1.twinx() ax2.plot(x, IOPS_Q3, 'k-o',label="IOPS_Q3") ax2.plot(x, IOPS_Q4, 'm-d',label="IOPS_Q4") box = ax2.get_position() ax2.set_position([box.x0, box.y0 + box.height * 0.1,box.width, box.height * 0.9]) ax2.legend(loc='center left', bbox_to_anchor=(1.11, -0.01),fancybox=True, shadow=True, ncol=1) plt.xlabel('BLOCK') plt.ylabel('IOPS') chart_name = "%s%s%s_%s_%s_%s.%s" % (outputdir,os.sep,t_name,test_name,sub_name,driv_id,output_fmt) plt.savefig(chart_name) plt.clf() reset_values() def plot_2axis_graph(title,x,BS1,BS2,BS3,BS4,BS5,BS6,test_name,t_name,driv_id): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) plt.grid(True) plt.suptitle(title, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) #Plot data ax1.plot(x,BS1, 'r-^',label="B=24 - D=32") ax1.plot(x,BS2, 'g-s',label="B=24 - D=48") ax1.plot(x,BS3, 'b-*',label="B=24 - D=72") ax1.plot(x,BS4, 'm-d',label="B=80 - D=88") ax1.plot(x,BS5, 'r-^',label="B=80 - D=104") ax1.plot(x,BS6, 'k-o',label="B=80 - D=128") plt.ylabel('Follow IO response time(usecs)') plt.xlabel('Queue') box = ax1.get_position() ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax1.legend(loc='center left', bbox_to_anchor=(1.00, 0.82),fancybox=True, shadow=True, ncol=1) ax1.text(4.48,2700, "B- Block | D-Distance", size=10,ha="center", va="center",bbox = dict(boxstyle="round",ec=(1., 0.5, 0.5),fc=(1., 0.8, 0.8))) chart_name = "%s%s%s_%s_%s.%s" % (outputdir,os.sep,t_name,test_name,driv_id,output_fmt) plt.savefig(chart_name) plt.clf() reset_values() def plot_2axis_3ele(title,x,D1,D2,D3,test_name,t_name,driv_id): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) plt.grid(True) plt.suptitle(title, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) #Plot data ax1.plot(x,D1, 'r-^',label="Dist-16") ax1.plot(x,D2, 'm-d',label="Dist-32") ax1.plot(x,D3, 'r-o',label="Dist-56") plt.ylabel('Follow IO response time(usecs)') plt.xlabel('Queue') box = ax1.get_position() ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax1.legend(loc='center left', bbox_to_anchor=(1.11, 0.90),fancybox=True, shadow=True, ncol=1) chart_name = "%s%s%s_%s_%s.%s" % (outputdir,os.sep,t_name,test_name,driv_id,output_fmt) plt.savefig(chart_name) plt.clf() reset_values() def reset_values(): title = "" x = "" y = "" xlab = "" ylab = "" tstname = "" xvalue = [] yvalue = [] ############### #MAIN PROGRAM STARTS HERE, GET INPUT FILE TO READ VALUES ############### try: infh = open(file, "r") except IOError: print "%s: unable to open '%s'" % (app_name, file) exit # Open the file for reading if infh: data = infh.read() chart_list = re.findall(r"CHART\s.*t",data) print len(chart_list) total_count = len(chart_list) print chart_list infh = open(file, "r") for line in infh: if line.isspace(): line = infh.next() test= re.match(r"^(\w+)\s+=\s+(\w+)",line) if test != None: test_name = test.group(2) print "TEST NAME :",test_name #break line = infh.next() kern = re.match(r"^(\w+)\s+=\s+(.*)",line) if kern != None: kernel_name = kern.group(2) print "Kernel :",kernel_name #break line = infh.next() driv = re.match(r"^(\w+)\s+=\s+(.*)",line) if driv != None: driv_id = driv.group(2) print "Drive ID :", driv_id #break line = infh.next() pid = re.match(r"^(\w+)\s+=\s+(.*)",line) if pid != None: prd_id = pid.group(2) print "Product ID:",prd_id break else: print "Test Name Not found in input file" sys.exit(0) infh = open(file, "r") print "File opened" for line in infh: list_item = "CHART 1t" # print "List",list_item if re.match(list_item,line): print "Line is",line header = re.match(r"(\w+)\s(.*):(\w+)", line) if header != None: header_name = header.group(3) t_name = header.group(2) # print "tname-",t_name print "Head-",header_name else: print "Please Provide header name" break print "" a3axis_sub(total_count,test_name)