CMS 3D CMS Logo

Functions | Variables

cmsSimplememchecker_parser Namespace Reference

Functions

def manipulate_log

Variables

string default = ''
string dest = 'profile'
string help = 'The profile to manipulate'
tuple parser = optparse.OptionParser(usage)
tuple startevt = int(options.startevt)
string usage = 'simplememchecker_parser.py <options>'

Function Documentation

def cmsSimplememchecker_parser::manipulate_log (   outdir,
  logfile_name,
  startevt 
)

Definition at line 4 of file cmsSimplememchecker_parser.py.

00005                                                 :
00006 
00007     import time
00008     import sys
00009     import ROOT       
00010     
00011     os.system('pwd')
00012     
00013     # the fundamental structure: the key is the evt number the value is a list containing
00014     # VSIZE deltaVSIZE RSS deltaRSS
00015     data=[]
00016     values_set=('vsize','delta_vsize','rss','delta_rss')
00017     
00018     # open file and read it and fill the structure!
00019     logfile=open(logfile_name,'r')
00020     logfile_lines=logfile.readlines()
00021     logfile.close()
00022 
00023     # we get the info we need!
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] #no \n!
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 # we inspect the following line
00035             line=logfile_lines[i]
00036             line=line[:-1] #no \n!
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     # skim the second entry when the event number is the same BUG!!!!!!!
00050     # i take elements in couples!
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     # The Graphs 
00082     __argv=sys.argv # trick for a strange behaviour of the TApp..
00083     sys.argv=sys.argv[:1]
00084     ROOT.gROOT.SetStyle("Plain") # style paranoia
00085     sys.argv=__argv
00086 
00087     #Cannot use this option when the logfile includes
00088     #a large number of events... PyRoot seg-faults.
00089     #Set ROOT in batch mode to avoid canvases popping up!
00090     ROOT.gROOT.SetBatch(1)
00091 
00092     # Save in file
00093     rootfilename='%s/graphs.root' %outdir
00094     myfile=ROOT.TFile(rootfilename,'RECREATE')    
00095        
00096     # dictionary of graphs!
00097     graph_dict={}
00098     for value in values_set:
00099         #graph_dict[value]
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         #fill the graphs
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         #print the graphs as files :)
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         # write it on file
00134         graph.Write()
00135         mycanvas.Write()
00136         
00137     myfile.Close() 
00138         
00139     os.system('pwd') 
00140                 
00141     # The html page!------------------------------------------------------------------------------
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     #Introducing this if to catch the cmsRelvalreport.py use case of "reuse" of TimingReport
00146     #profile when doing the SimpleMemReport... otherwise the filename for the html
00147     #would be misleadingly TimingReport...
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     
    

Variable Documentation

Definition at line 178 of file cmsSimplememchecker_parser.py.

Definition at line 179 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser::help = 'The profile to manipulate'

Definition at line 177 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser::parser = optparse.OptionParser(usage)

Definition at line 175 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser::startevt = int(options.startevt)

Definition at line 203 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser::usage = 'simplememchecker_parser.py <options>'

Definition at line 174 of file cmsSimplememchecker_parser.py.