#!/usr/software/bin/python # # File: 31ab_2fan_plot.py # Version: 1 # Date: 12 Jan 2012 # Description: Plots charts from NetApp input file # Usage: mod_3x_plot.py # Input File : _python.txt # Example: /usr/software/bin/python 31ab_2fan_plot.py *31_a_b_plot_python.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 import time from threading import Thread from pylab import * from matplotlib.ticker import MultipleLocator, FormatStrFormatter ############### #GLOBAL VARIABLES ############### count =0 xvalue = [] yvalue = [] y1value = [] fan_list = [] yt_list = [] rd_w_list = [] 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 ="" ############## #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 plot_r_graph(xaxis,yaxlist1,yaxlist2,testname,kernel,productid,fan_list,countno,rd_w_list_valu): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) print "Rd list --->",rd_w_list_valu plt.grid(True) title1 = " " title1 +="Test_name :%s\n"%(testname) title1 +="IO :%s\n"%(rd_w_list_valu) title1 +="Kernel :%s -- "%(kernel) # title1 +="Product_ID :%s\n"%(productid) plt.suptitle(title1, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) #Plot data ax1.plot(xaxis,yaxlist1, 'r-^',label=fan_list[0]) ax1.plot(xaxis,yaxlist2, 'b-*',label=fan_list[1]) 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.07, 0.60),fancybox=True, shadow=True, ncol=1) rd_w_valuee = 0 chart_name = "%s%s%s_%s_%s_%s.%s" % (outputdir,os.sep,test_name,fan_speed,countno,rd_w_list_valu,output_fmt) plt.savefig(chart_name) plt.clf() def plot_r_graph_single(xaxis,yaxlist1,testname,kernel,productid,fan_list,countno,rd_w_list_valu): outputdir minorLocator = LinearLocator() fig = plt.figure(figsize=(9,6)) print "Rd list --->",rd_w_list_valu plt.grid(True) title1 = " " title1 +="Test_name :%s\n"%(testname) title1 +="IO :%s\n"%(rd_w_list_valu) title1 +="Kernel :%s -- "%(kernel) # title1 +="Product_ID :%s\n"%(productid) plt.suptitle(title1, fontsize="small") #, y=0.99) ax1 = fig.add_subplot(111) #plot data ax1.plot(xaxis,yaxlist1, 'r-o',label=fan_list[0]) 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.07, 0.60),fancybox=True, shadow=True, ncol=1) rd_w_valuee = 0 chart_name = "%s%s%s_%s_%s_%s.%s" % (outputdir,os.sep,test_name,fan_speed,countno,rd_w_list_valu,output_fmt) plt.savefig(chart_name) plt.clf() def plot_r_graph_test(xaxis,yaxlist,fan_list,testname,kernel,productid,imgcount): print "TEST NAME -->",testname print "Kernel -->",kernel # print "ProductID -->",productid print "Fanlist -->",fan_list # print "Xaxis is -->",xaxis # print "Yaxis list is -->",yaxlist # print "####################################################################" # print "1st and 2nd list value -->",yaxlist[0],yaxlist[1] # print "Lengthof yaxis",len(yaxlist) # print "Length of fanlist",len(fan_list) fignum = (len(yaxlist)/len(fan_list)) print "fignum is",fignum if fignum == 2: print "plotting for all drives" rd_w_list = ['4KRW','64KRW'] else: print "Plotting for single drives" rd_w_list = ['4KRW','64KRW','256KRW','256KSW','4KRR'] count = 0 if len(fan_list) == 1: for j in range(fignum): plot_r_graph_single(xaxis,yaxlist[count],testname,kernel,productid,fan_list,j,rd_w_list[j]) count+=1 time.sleep(10) else: for j in range(fignum): plot_r_graph(xaxis,yaxlist[count],yaxlist[count+1],testname,kernel,productid,fan_list,j,rd_w_list[j]) count+=2 time.sleep(10) ############### #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"FANSPEED:\.*",data) # print len(chart_list) total_count = len(chart_list) # print chart_list tot_y = re.findall(r"Y-.*",data) y_prst= len(tot_y) # print "No of y present",y_prst chr_cnt = re.findall(r"CHART",data) img_count = len(chr_cnt) # print "Total Graph to plot ", img_count 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() 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") for line in infh: f_speed= re.match(r"FANSPEED:(.*)",line) if f_speed != None: fan_speed = f_speed.group(1) fan_list.append(fan_speed) # print fan_list infh = open(file, "r") for line in infh: if line.isspace(): line = infh.next() cht = re.match(r"CHART",line) if cht != None: line = infh.next() 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 total_yax = (y_prst/img_count) # print "Total y is-->",total_yax for i in range(total_yax): line = infh.next() line = line.replace('=',',') line=line.strip() y_list = line.split(',') yname = y_list.pop(0) y = [] y = y_list # print "I ->", i # print yname,y yt_list.append(y) # time.sleep(5) # print "Appended list :",yt_list # time.sleep(10) # print " Leng of combined list",len(yt_list) plot_r_graph_test(xvalue,yt_list,fan_list,test_name,kernel_name,prd_id,img_count)