00001
00002
00003
00004
00005
00006
00007
00008 import os,sys
00009 import time
00010
00011 IgProfProfile={'PERF_TICKS':'IgProfPerf',
00012 'MEM_TOTAL':'IgProfMem',
00013 'MEM_LIVE':'IgProfMem',
00014 'MEM_MAX':'IgProfMem'
00015 }
00016
00017 def execute(command):
00018 print '[IgAnalysis] %s ...' %command
00019 sys.stdout.flush()
00020 exitstate=os.system(command)
00021 return exitstate
00022
00023 def simple_igprof_analysis(profile_name,AnalysisType,output_type):
00024
00025 """This function takes as arguments:
00026 -a compressed (.gz) igprof output profile
00027 -the output directory where to store the output
00028 -the type of output wanted
00029 Based on this information it automatically selects the igprof counter
00030 (PERF_TICKS, MEM_TOTAL or MEM_LIVE) to use with igprof-analyse and it
00031 performs the analysis.
00032 If ASCII output_type is given, it keeps only the first seven lines of
00033 the output file (the report) allowing quick access to the totals for
00034 the counters in order to put together summary tables.
00035 If SQLite3 output_type is given, it simply dumps the full reports in
00036 sqlite3 format, ready to be browsed by igprof-navigator GUI (standalone
00037 or cgi-bin).
00038 """
00039
00040
00041 outfile=profile_name.split(".")[0].replace(IgProfProfile[AnalysisType],AnalysisType)+".res"
00042
00043
00044
00045
00046
00047
00048 if output_type =="SQLite3":
00049
00050 outfile= outfile[:-3]+"sql3"
00051 command='igprof-analyse --sqlite -d -v -g -r %s %s |sqlite3 %s'%(AnalysisType,profile_name,outfile)
00052
00053 exit=execute(command)
00054 elif output_type =="ASCII":
00055
00056 command='igprof-analyse -d -v -g -r %s %s > %s'%(AnalysisType,profile_name,outfile)
00057
00058 exit=execute(command)
00059
00060
00061 print "Reading the res file"
00062 txt_file=open(outfile,'r')
00063 txt_file_content=txt_file.readlines()
00064 print "res file has %s lines!"%len(txt_file_content)
00065 txt_file.close()
00066
00067 print "Overwriting the res file, to reduce it to 7 lines"
00068 out_file=open(outfile,'w')
00069 line_num=0
00070 for line in txt_file_content:
00071 out_file.write(line)
00072 line_num+=1
00073 if line_num == 7:
00074 break
00075 out_file.close()
00076
00077 return exit
00078
00079 def diff_igprof_analysis(profile_name,regression_profile_name,AnalysisType):
00080
00081 """
00082 This function takes as arguments:
00083 -a compressed (.gz) igprof output profile
00084 -a second compressed (.gz) igprof output profile against which a regression analysis is intended to be done
00085 -the output directory where to store the output of the regression analysis
00086 Based on this information it automatically selects the igprof counter (PERF_TICKS, MEM_TOTAL or MEM_LIVE) to use
00087 with igprof-analyse and it performs the regression analysis with SQLite3 output.
00088 """
00089
00090 outfile=profile_name.split(".")[0].replace(IgProfProfile[AnalysisType],AnalysisType)+"_diff_"+regression_profile_name.split(".")[0].split("___")[-1]+".sql3"
00091 command='igprof-analyse --sqlite -d -v -g --diff-mode -b %s -r %s %s |sqlite3 %s'%(regression_profile_name, AnalysisType,profile_name,outfile)
00092 exit=execute(command)
00093
00094 return exit
00095 def library_igprof_analysis(profile_name,AnalysisType):
00096
00097 """
00098 This function takes as arguments:
00099 -a compressed (.gz) igprof output profile
00100 -the output directory where to store the output of the igprof-analysis merging the results by library
00101 Based on this information it automatically selects the igprof counter (PERF_TICKS, MEM_TOTAL or MEM_LIVE) to use
00102 with igprof-analyse and it performs the igprof-analyse analysis merging the results by library and saving the results
00103 in the usual igprof-navigator browseable SQLite3 format.
00104 """
00105
00106 outfile=profile_name.split(".")[0].replace(IgProfProfile[AnalysisType],AnalysisType)+"_merged"+".sql3"
00107
00108 command="igprof-analyse --sqlite -d -v -g -r %s -ml -mr 's|.*/(.*)$|\\1|' %s |sqlite3 %s"%(AnalysisType,profile_name,outfile)
00109 exit=execute(command)
00110
00111 return exit
00112
00113
00114
00115
00116 if __name__ == '__main__':
00117
00118 import optparse
00119
00120
00121 usage='IgProf_Analysis.py <options>'
00122 parser = optparse.OptionParser(usage)
00123 parser.add_option('-i', '--in_ profile',
00124 help='The profile to manipulate' ,
00125 default='',
00126 dest='profile')
00127
00128 parser.add_option('-c', '--counter',
00129 help='The IgProf counter for the analysis (PERF_TICKS,MEM_TOTAL,MEM_LIVE,MEM_MAX)' ,
00130 default='UNKNOWN_COUNTER',
00131 dest='counter')
00132 parser.add_option('-t', '--output_type',
00133 help='The type of the output file (ASCII or sqlite3)' ,
00134 default='',
00135 dest='output_type')
00136 parser.add_option('-r', '--regression',
00137 help='The IgProf output file to make a regression analysis against' ,
00138 default='',
00139 dest='regressionprofile')
00140 parser.add_option('-l','--library',
00141 help='Perform igprof-analyse merging the results by library',
00142 action='store_true',
00143 default=False,
00144 dest='library')
00145 (options,args) = parser.parse_args()
00146
00147
00148 if options.profile=='':
00149 raise('Please select a profile, an output dir AND a type of output (ASCII or SQLITE3)!')
00150
00151 if not os.path.exists(options.profile):
00152 raise ('Input profile not present!')
00153
00154 AnalysisType=options.counter
00155
00156 print "Input file is %s and AnalysisType is %s"%(options.profile,AnalysisType)
00157
00158
00159 if options.regressionprofile:
00160 diff_igprof_analysis(options.profile,options.regressionprofile,AnalysisType)
00161 elif options.library:
00162 library_igprof_analysis(options.profile,AnalysisType)
00163 else:
00164 simple_igprof_analysis(options.profile,AnalysisType,options.output_type)
00165