CMS 3D CMS Logo

Functions | Variables

cmsTiming_parser Namespace Reference

Functions

def get_max
def get_min
def manipulate_log

Variables

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

Function Documentation

def cmsTiming_parser::get_max (   data,
  index = 1 
)

Definition at line 4 of file cmsTiming_parser.py.

00005                          :
00006     max_time=-1
00007     for el in data:
00008         sec=el[index]
00009         if max_time<sec:
00010             max_time=sec
00011     return max_time

def cmsTiming_parser::get_min (   data,
  index = 1 
)

Definition at line 12 of file cmsTiming_parser.py.

00013                          :
00014     min_time=1e20
00015     for el in data:
00016         sec=el[index]
00017         if min_time>sec:
00018             min_time=sec
00019     return min_time    
    
def cmsTiming_parser::manipulate_log (   outdir,
  logfile_name,
  secsperbin 
)

Definition at line 20 of file cmsTiming_parser.py.

00021                                                   :
00022 
00023     import time
00024     import sys
00025     import ROOT       
00026     
00027     # the fundamental structure: the key is the evt number the value is a list containing
00028     # VSIZE deltaVSIZE RSS deltaRSS
00029     data=[]
00030     
00031     # open file and read it and fill the structure!
00032     logfile=open(logfile_name,'r')
00033     logfile_lines=logfile.readlines()
00034     logfile.close()
00035 
00036     # we get the info we need!
00037     i=0
00038     while i < len(logfile_lines):
00039         line=logfile_lines[i]
00040         if 'TimeEvent>' in line:
00041             line=line[:-1] #no \n!
00042             line_content_list=line.split(' ')
00043             event_number=int(line_content_list[1])
00044             seconds=float(line_content_list[3])
00045             data.append((event_number,seconds))
00046         i+=1
00047                                               
00048     # init Graph and histo
00049     
00050     # The Graphs 
00051     __argv=sys.argv # trick for a strange behaviour of the TApp..
00052     sys.argv=sys.argv[:1]
00053     ROOT.gROOT.SetStyle("Plain") # style paranoia
00054     sys.argv=__argv
00055     #Cannot use this option when the logfile includes
00056     #a large number of events... PyRoot seg-faults.
00057     #Set ROOT in batch mode to avoid canvases popping up!
00058     ROOT.gROOT.SetBatch(1)
00059 
00060     # Save in file
00061     rootfilename='%s/graphs.root' %outdir
00062     myfile=ROOT.TFile(rootfilename,'RECREATE')   
00063     
00064     
00065     # Set fancy limits
00066     min_val=get_min(data,1)
00067     max_val=get_max(data,1)
00068     interval=max_val-min_val
00069     
00070     min_val=min_val-interval*0.2
00071     max_val=max_val+interval*0.2
00072     interval=max_val-min_val
00073     
00074     nbins=int(interval/secsperbin)
00075     
00076     print 'Minval=',min_val,' maxval=',max_val, ' interval=',interval
00077     
00078     histo=ROOT.TH1F('Seconds per event','Seconds per event',nbins,min_val,max_val)
00079     histo.GetXaxis().SetTitle("s")    
00080     
00081     npoints=len(data)   
00082     
00083     graph=ROOT.TGraph(npoints)
00084     graph.SetMarkerStyle(8)
00085     graph.SetMarkerSize(.7)
00086     graph.SetMarkerColor(1)
00087     graph.SetLineWidth(3)
00088     graph.SetLineColor(2)        
00089     graph.SetTitle('Seconds per event')
00090     graph.SetName('SecondsPerEvent')    
00091     graph.GetXaxis().SetTitle("Event")
00092     
00093     last_event=data[-1][0]
00094     print 'last event =',last_event
00095     graph.GetXaxis().SetLimits(0,last_event)
00096         
00097     graph.GetYaxis().SetTitleOffset(1.3)
00098     graph.GetYaxis().SetTitle("s")
00099     graph.GetYaxis().SetRangeUser(0,max_val)
00100 
00101     
00102     
00103     # Fill them
00104     
00105     evt_counter=0
00106     total=0
00107     for evt_num,secs in data:
00108         graph.SetPoint(evt_counter,evt_num,secs)
00109         histo.Fill(secs)
00110         total+=secs
00111         evt_counter+=1
00112         
00113     print 'Total Time=', total
00114         
00115     #A line which represents the average is drawn in the TGraph
00116     avg=histo.GetMean()
00117     avg_line=ROOT.TLine(1,avg,last_event,avg)
00118     avg_line.SetLineColor(4)
00119     avg_line.SetLineWidth(2)
00120         
00121     # draw and save!
00122     graph_canvas=ROOT.TCanvas('graph_canvas')
00123     graph_canvas.cd()
00124     graph.Draw("ALP")
00125     avg_line.Draw("Same")
00126     
00127     graph_canvas.Print("%s/graph.gif" %outdir,"gif")
00128     
00129     # write it on file
00130     graph.Write()
00131     graph_canvas.Write()    
00132 
00133     histo_canvas=ROOT.TCanvas('histo_canvas')
00134     histo_canvas.cd()
00135     histo.Draw('')
00136 
00137     histo_canvas.Print("%s/histo.gif" %outdir,"gif")
00138     
00139     # write it on file
00140     histo.Write()
00141     histo_canvas.Write() 
00142     
00143     myfile.Close()   
00144                     
00145     # The html page!------------------------------------------------------------------------------
00146     
00147     titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
00148                                    %(os.environ['CMSSW_VERSION'],time.asctime())
00149         
00150     html_file_name='%s/%s.html' %(outdir,logfile_name[:-4])# a way to say the string until its last but 4th char
00151     html_file=open(html_file_name,'w')
00152     html_file.write('<html>\n<body>\n'+\
00153                     titlestring)
00154     html_file.write('<table>\n'+\
00155                     '<tr><td><img  src=graph.gif></img></td></tr>'+\
00156                     '<tr><td><img  src=histo.gif></img></td></tr>'+\
00157                     '</table>\n')
00158     html_file.write('\n</body>\n</html>')
00159     html_file.close()    
00160     
    

Variable Documentation

Definition at line 173 of file cmsTiming_parser.py.

string cmsTiming_parser::dest = 'profile'

Definition at line 174 of file cmsTiming_parser.py.

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

Definition at line 172 of file cmsTiming_parser.py.

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

Definition at line 170 of file cmsTiming_parser.py.

tuple cmsTiming_parser::startevt = float(options.startevt)

Definition at line 198 of file cmsTiming_parser.py.

string cmsTiming_parser::usage = 'timing_parser.py <options>'

Definition at line 169 of file cmsTiming_parser.py.