00001
00002
00003
00004
00005
00006
00007
00008 import os
00009 import time
00010
00011 def execute(command):
00012 print '[IgAnalysis] %s ...' %command
00013 exitstate=os.system(command)
00014 return exitstate
00015
00016 def analyse_prof_sim(profile_name,outdir):
00017
00018
00019 outfile1='%s/mem_live_peak.res' %outdir
00020 outfile2='%s/doEvent_output.txt' %outdir
00021 outfile3='%s/doBeginJob_output.txt' %outdir
00022 outfile4='%s/mem_live.res' %outdir
00023 outfile5='%s/mem_total.res' %outdir
00024
00025
00026 command='igprof-analyse -d -v -g --value peak -r MEM_LIVE %s > %s'\
00027 %(profile_name,outfile1)
00028 execute(command)
00029
00030
00031 commands_list=(\
00032 'igprof-segment edm::EDProducer::doEvent < %s |tee -a %s' %(outfile1,outfile2),
00033
00034 'igprof-segment edm::EDProducer::doBeginJob < %s |tee -a %s' %(outfile1,outfile3),
00035
00036 'igprof-analyse -d -v -g -r MEM_LIVE %s |tee -a \%s'\
00037 %(profile_name,outfile4),
00038
00039 'igprof-analyse -d -v -g -r MEM_TOTAL %s |tee -a \%s'\
00040 %(profile_name,outfile5)
00041 )
00042
00043 for command in commands_list:
00044
00045 execute(command)
00046
00047
00048 titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
00049 %(os.environ['CMSSW_VERSION'],time.asctime())
00050
00051 for command,filename in map(None,commands_list,[outfile2,outfile3,outfile4,outfile5]):
00052 command_info='Command executed: <em>%s</em><br><br>\n' %command
00053
00054
00055 txt_file=open(filename,'r')
00056 txt_file_content=txt_file.readlines()
00057 txt_file.close()
00058
00059 html_file_name='%s.html' %filename[:-4]
00060 html_file=open(html_file_name,'w')
00061 html_file.write('<html>\n<body>\n'+\
00062 titlestring+\
00063 command_info)
00064 for line in txt_file_content:
00065 html_file.write(line+'<br>\n')
00066 html_file.write('\n</body>\n</html>')
00067 html_file.close()
00068
00069
00070 execute('pushd %s;gzip *txt;popd' %outdir)
00071
00072
00073
00074
00075
00076 if __name__ == '__main__':
00077
00078 import optparse
00079
00080
00081 usage='IgProf_Analysis.py <options>'
00082 parser = optparse.OptionParser(usage)
00083 parser.add_option('-i', '--in_ profile',
00084 help='The profile to manipulate' ,
00085 default='',
00086 dest='profile')
00087
00088 parser.add_option('-o', '--outdir',
00089 help='The directory of the output' ,
00090 default='',
00091 dest='outdir')
00092
00093 (options,args) = parser.parse_args()
00094
00095
00096 if options.profile=='' or\
00097 options.outdir=='':
00098 raise('Please select a profile and an output dir!')
00099
00100 if not os.path.exists(options.profile) or\
00101 not os.path.exists(options.outdir):
00102 raise ('Outdir or input profile not present!')
00103
00104
00105 analyse_prof_sim(options.profile,options.outdir)
00106