00005 :
00006
00007 import time
00008 import sys
00009 import ROOT
00010
00011 os.system('pwd')
00012
00013
00014
00015 data=[]
00016 values_set=('vsize','delta_vsize','rss','delta_rss')
00017
00018
00019 logfile=open(logfile_name,'r')
00020 logfile_lines=logfile.readlines()
00021 logfile.close()
00022
00023
00024 i=0
00025 while i < len(logfile_lines):
00026 line=logfile_lines[i]
00027 if '%MSG-w MemoryCheck:' in line:
00028 line=line[:-1]
00029 line_content_list=line.split(' ')
00030 event_number=int(line_content_list[-1])
00031 if event_number<startevt:
00032 i+=1
00033 continue
00034 i+=1
00035 line=logfile_lines[i]
00036 line=line[:-1]
00037 line_content_list=line.split(' ')
00038 vsize=float(line_content_list[4])
00039 delta_vsize=float(line_content_list[5])
00040 rss=float(line_content_list[7])
00041 delta_rss=float(line_content_list[8])
00042
00043 data.append((event_number,{'vsize':vsize,
00044 'delta_vsize':delta_vsize,
00045 'rss':rss,
00046 'delta_rss':delta_rss}))
00047 i+=1
00048
00049
00050
00051 new_data=[]
00052 if len(data)>2:
00053 if data[0][0]==data[1][0]:
00054 print 'Two modules seem to have some output.\nCollapsing ...'
00055 i=0
00056 while True:
00057 dataline1=data[i]
00058 i+=1
00059 dataline2=data[i]
00060 new_eventnumber=dataline1[0]
00061 new_vsize=dataline2[1]['vsize']
00062 new_delta_vsize=dataline1[1]['delta_vsize']+dataline2[1]['delta_vsize']
00063 new_rss=dataline2[1]['rss']
00064 new_delta_rss=dataline1[1]['delta_rss']+dataline2[1]['delta_rss']
00065
00066 new_data.append((new_eventnumber,{'vsize':new_vsize,
00067 'delta_vsize':new_delta_vsize,
00068 'rss':new_rss,
00069 'delta_rss':new_delta_rss}))
00070 i+=1
00071 if i==len(data): break
00072
00073 data=new_data
00074 print 'Collapsing: Done!'
00075
00076 npoints=len(data)
00077
00078 print '%s values read and stored ...' %npoints
00079
00080
00081
00082 __argv=sys.argv
00083 sys.argv=sys.argv[:1]
00084 ROOT.gROOT.SetStyle("Plain")
00085 sys.argv=__argv
00086
00087
00088
00089
00090 ROOT.gROOT.SetBatch(1)
00091
00092
00093 rootfilename='%s/graphs.root' %outdir
00094 myfile=ROOT.TFile(rootfilename,'RECREATE')
00095
00096
00097 graph_dict={}
00098 for value in values_set:
00099
00100 graph=ROOT.TGraph(npoints)
00101 graph.SetMarkerStyle(8)
00102 graph.SetMarkerSize(.7)
00103 graph.SetMarkerColor(1)
00104 graph.SetLineWidth(3)
00105 graph.SetLineColor(2)
00106 graph.SetTitle(value)
00107 graph.SetName('%s_graph' %value)
00108
00109
00110
00111 point_counter=0
00112 for event_number,vals_dict in data:
00113 graph.SetPoint(point_counter,
00114 event_number,
00115 vals_dict[value])
00116 point_counter+=1
00117
00118 graph.GetXaxis().SetTitle("Event")
00119 last_event=data[-1][0]
00120 graph.GetXaxis().SetRangeUser(0,last_event+1)
00121 graph.GetYaxis().SetTitleOffset(1.3)
00122 graph.GetYaxis().SetTitle("MB")
00123
00124
00125
00126
00127 mycanvas=ROOT.TCanvas('%s_canvas' %value)
00128 mycanvas.cd()
00129 graph.Draw("ALP")
00130
00131 mycanvas.Print("%s/%s_graph.gif"%(outdir,value),"gif")
00132
00133
00134 graph.Write()
00135 mycanvas.Write()
00136
00137 myfile.Close()
00138
00139 os.system('pwd')
00140
00141
00142
00143 titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
00144 %(os.environ['CMSSW_VERSION'],time.asctime())
00145
00146
00147
00148 if len(logfile_name)>16 and 'TimingReport.log' in logfile_name[-16:]:
00149 file_name=logfile_name[:-16]+"_SimpleMemReport"
00150 else:
00151 file_name=logfile_name[:-4]+"_SimpleMemReport"
00152 html_file_name='%s/%s.html' %(outdir,file_name)
00153 html_file=open(html_file_name,'w')
00154 html_file.write('<html>\n<body>\n'+\
00155 titlestring)
00156 html_file.write('<table>\n'+\
00157 '<tr><td><img src=vsize_graph.gif></img></td>'+\
00158 '<td><img src=rss_graph.gif></img></td></tr>'+\
00159 '<tr><td><img src=delta_vsize_graph.gif></img></td>'+\
00160 '<td><img src=delta_rss_graph.gif></img></td></tr>' +\
00161 '</table>\n')
00162
00163 html_file.write('\n</body>\n</html>')
00164 html_file.close()
00165