Go to the documentation of this file.00001
00002
00003
00004 def manipulate_log(outdir,logfile_name,startevt):
00005
00006 import time
00007 import sys
00008 import ROOT
00009
00010 os.system('pwd')
00011
00012
00013
00014 data=[]
00015 values_set=('vsize','delta_vsize','rss','delta_rss')
00016
00017
00018 logfile=open(logfile_name,'r')
00019 logfile_lines=logfile.readlines()
00020 logfile.close()
00021
00022
00023 i=0
00024 while i < len(logfile_lines):
00025 line=logfile_lines[i]
00026 if '%MSG-w MemoryCheck:' in line:
00027 line=line[:-1]
00028 line_content_list=line.split(' ')
00029 event_number=int(line_content_list[-1])
00030 if event_number<startevt:
00031 i+=1
00032 continue
00033 i+=1
00034 line=logfile_lines[i]
00035 line=line[:-1]
00036 line_content_list=line.split(' ')
00037 vsize=float(line_content_list[4])
00038 delta_vsize=float(line_content_list[5])
00039 rss=float(line_content_list[7])
00040 delta_rss=float(line_content_list[8])
00041
00042 data.append((event_number,{'vsize':vsize,
00043 'delta_vsize':delta_vsize,
00044 'rss':rss,
00045 'delta_rss':delta_rss}))
00046 i+=1
00047
00048
00049
00050 new_data=[]
00051 if len(data)>2:
00052 if data[0][0]==data[1][0]:
00053 print 'Two modules seem to have some output.\nCollapsing ...'
00054 i=0
00055 while True:
00056 dataline1=data[i]
00057 i+=1
00058 dataline2=data[i]
00059 new_eventnumber=dataline1[0]
00060 new_vsize=dataline2[1]['vsize']
00061 new_delta_vsize=dataline1[1]['delta_vsize']+dataline2[1]['delta_vsize']
00062 new_rss=dataline2[1]['rss']
00063 new_delta_rss=dataline1[1]['delta_rss']+dataline2[1]['delta_rss']
00064
00065 new_data.append((new_eventnumber,{'vsize':new_vsize,
00066 'delta_vsize':new_delta_vsize,
00067 'rss':new_rss,
00068 'delta_rss':new_delta_rss}))
00069 i+=1
00070 if i==len(data): break
00071
00072 data=new_data
00073 print 'Collapsing: Done!'
00074
00075 npoints=len(data)
00076
00077 print '%s values read and stored ...' %npoints
00078
00079
00080
00081 __argv=sys.argv
00082 sys.argv=sys.argv[:1]
00083 ROOT.gROOT.SetStyle("Plain")
00084 sys.argv=__argv
00085
00086
00087
00088
00089 ROOT.gROOT.SetBatch(1)
00090
00091
00092 rootfilename='%s/graphs.root' %outdir
00093 myfile=ROOT.TFile(rootfilename,'RECREATE')
00094
00095
00096 graph_dict={}
00097 for value in values_set:
00098
00099 graph=ROOT.TGraph(npoints)
00100 graph.SetMarkerStyle(8)
00101 graph.SetMarkerSize(.7)
00102 graph.SetMarkerColor(1)
00103 graph.SetLineWidth(3)
00104 graph.SetLineColor(2)
00105 graph.SetTitle(value)
00106 graph.SetName('%s_graph' %value)
00107
00108
00109
00110 point_counter=0
00111 for event_number,vals_dict in data:
00112 graph.SetPoint(point_counter,
00113 event_number,
00114 vals_dict[value])
00115 point_counter+=1
00116
00117 graph.GetXaxis().SetTitle("Event")
00118 last_event=data[-1][0]
00119 graph.GetXaxis().SetRangeUser(0,last_event+1)
00120 graph.GetYaxis().SetTitleOffset(1.3)
00121 graph.GetYaxis().SetTitle("MB")
00122
00123
00124
00125
00126 mycanvas=ROOT.TCanvas('%s_canvas' %value)
00127 mycanvas.cd()
00128 graph.Draw("ALP")
00129
00130 mycanvas.Print("%s/%s_graph.gif"%(outdir,value),"gif")
00131
00132
00133 graph.Write()
00134 mycanvas.Write()
00135
00136 myfile.Close()
00137
00138 os.system('pwd')
00139
00140
00141
00142 titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
00143 %(os.environ['CMSSW_VERSION'],time.asctime())
00144
00145
00146
00147 if len(logfile_name)>16 and 'TimingReport.log' in logfile_name[-16:]:
00148 file_name=logfile_name[:-16]+"_SimpleMemReport"
00149 else:
00150 file_name=logfile_name[:-4]+"_SimpleMemReport"
00151 html_file_name='%s/%s.html' %(outdir,file_name)
00152 html_file=open(html_file_name,'w')
00153 html_file.write('<html>\n<body>\n'+\
00154 titlestring)
00155 html_file.write('<table>\n'+\
00156 '<tr><td><img src=vsize_graph.gif></img></td>'+\
00157 '<td><img src=rss_graph.gif></img></td></tr>'+\
00158 '<tr><td><img src=delta_vsize_graph.gif></img></td>'+\
00159 '<td><img src=delta_rss_graph.gif></img></td></tr>' +\
00160 '</table>\n')
00161
00162 html_file.write('\n</body>\n</html>')
00163 html_file.close()
00164
00165
00166
00167
00168 if __name__ == '__main__':
00169
00170 import optparse
00171 import os
00172
00173
00174 usage='simplememchecker_parser.py <options>'
00175 parser = optparse.OptionParser(usage)
00176 parser.add_option('-i', '--in_ profile',
00177 help='The profile to manipulate' ,
00178 default='',
00179 dest='profile')
00180
00181 parser.add_option('-o', '--outdir',
00182 help='The directory of the output' ,
00183 default='',
00184 dest='outdir')
00185
00186 parser.add_option('-n',
00187 help='The event number from which we start. Default is 1.' ,
00188 default='1',
00189 dest='startevt')
00190
00191 (options,args) = parser.parse_args()
00192
00193
00194 if options.profile=='' or\
00195 options.outdir=='':
00196 raise('Please select a profile and an output dir!')
00197
00198 if not os.path.exists(options.profile) or\
00199 not os.path.exists(options.outdir):
00200 raise ('Outdir or input profile not present!')
00201
00202 try:
00203 startevt=int(options.startevt)
00204 except ValueError:
00205 print 'Problems in convertng starting event value!'
00206
00207
00208
00209 manipulate_log(options.outdir,options.profile,startevt)
00210
00211