25 from math
import sqrt, log10, floor
32 logfile=open(logfile_name,
'r')
33 logfile_lines=logfile.readlines()
39 while i < len(logfile_lines):
41 if 'TimeEvent>' in line:
43 line_content_list=line.split(
' ')
44 event_number=int(line_content_list[1])
45 seconds=float(line_content_list[3])
46 data.append((event_number,seconds))
47 elif parse_report
and'TimeReport' in line:
51 report += line.replace(
'TimeReport',
'')
53 elif 'headings' in line:
57 elif 'complete' in line:
59 report += line.replace(
'TimeReport',
'')
61 report += logfile_lines[i]
66 report += line.replace(
'TimeReport',
'')
74 ROOT.gROOT.SetStyle(
"Plain")
79 ROOT.gROOT.SetBatch(1)
82 rootfilename=
'%s/graphs.root' %outdir
83 myfile=ROOT.TFile(rootfilename,
'RECREATE')
89 interval=max_val-min_val
91 min_val=min_val-interval*0.2
92 max_val=max_val+interval*0.2
93 interval=max_val-min_val
95 nbins=int(interval/secsperbin)
97 print 'Minval =', min_val,
' maxval =',max_val,
' interval =',interval
99 histo=ROOT.TH1F(
'Seconds per event',
'Seconds per event',nbins,min_val,max_val)
100 histo.GetXaxis().SetTitle(
"s")
104 graph=ROOT.TGraph(npoints)
105 graph.SetMarkerStyle(8)
106 graph.SetMarkerSize(.7)
107 graph.SetMarkerColor(1)
108 graph.SetLineWidth(3)
109 graph.SetLineColor(2)
110 graph.SetTitle(
'Seconds per event')
111 graph.SetName(
'SecondsPerEvent')
112 graph.GetXaxis().SetTitle(
"Event")
114 last_event=data[-1][0]
115 print 'last event =',last_event
116 graph.GetXaxis().SetLimits(0,last_event)
118 graph.GetYaxis().SetTitleOffset(1.3)
119 graph.GetYaxis().SetTitle(
"s")
120 graph.GetYaxis().SetRangeUser(0,max_val)
128 for evt_num,secs
in data:
129 graph.SetPoint(evt_counter,evt_num,secs)
134 average=total/evt_counter
137 for i
in range(evt_counter):
138 sum+=(data[i][1]-average)**2
139 uncertainty=
sqrt(sum/(evt_counter*(evt_counter-1)))
145 print 'Total Time =', total
146 print 'Average Time =', average
147 print 'Uncertainty of Average Time =', average,
'+/-', uncertainty
151 avg_line=ROOT.TLine(1,avg,last_event,avg)
152 avg_line.SetLineColor(4)
153 avg_line.SetLineWidth(2)
156 graph_canvas=ROOT.TCanvas(
'graph_canvas')
159 avg_line.Draw(
"Same")
161 graph_canvas.Print(
"%s/graph.png" %outdir,
"png")
167 histo_canvas=ROOT.TCanvas(
'histo_canvas')
171 histo_canvas.Print(
"%s/histo.png" %outdir,
"png")
181 titlestring=
'<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
182 %(os.environ[
'CMSSW_VERSION'],time.asctime())
184 html_file_name=
'%s/%s_TimingReport.html' %(outdir,logfile_name[:-4])
185 html_file=open(html_file_name,
'w')
186 html_file.write(
'<html>\n<body>\n'+\
188 html_file.write(
'<table>\n'+\
189 '<tr>\n<td><img src=graph.png></img></td>\n'+\
190 '<td><img src=histo.png></img></td>\n</tr>\n'+\
192 html_file.write(
'<hr>\n<h2>Time Report</h2>\n<pre>\n' + report +
'</pre>\n')
193 html_file.write(
'</body>\n</html>')
199 if __name__ ==
'__main__':
205 usage=
'timing_parser.py <options>'
206 parser = optparse.OptionParser(usage)
207 parser.add_option(
'-i',
'--in_ profile',
208 help=
'The profile to manipulate' ,
212 parser.add_option(
'-o',
'--outdir',
213 help=
'The directory of the output' ,
217 parser.add_option(
'-n',
218 help=
'Number of secs per bin. Default is 1.' ,
222 (options,args) = parser.parse_args()
225 if options.profile==
'' or\
227 raise(
'Please select a profile and an output dir!')
229 if not os.path.exists(options.profile)
or\
230 not os.path.exists(options.outdir):
231 raise (
'Outdir or input profile not present!')
234 startevt=float(options.startevt)
236 print 'Problems in convertng starting event value!'