26 from math
import sqrt, log10, floor
33 logfile=open(logfile_name,
'r')
34 logfile_lines=logfile.readlines()
40 while i < len(logfile_lines):
42 if 'TimeEvent>' in line:
44 line_content_list=line.split(
' ')
45 event_number=int(line_content_list[1])
46 seconds=float(line_content_list[3])
47 data.append((event_number,seconds))
48 elif parse_report
and'TimeReport' in line:
52 report += line.replace(
'TimeReport',
'')
54 elif 'headings' in line:
58 elif 'complete' in line:
60 report += line.replace(
'TimeReport',
'')
62 report += logfile_lines[i]
67 report += line.replace(
'TimeReport',
'')
75 ROOT.gROOT.SetStyle(
"Plain")
80 ROOT.gROOT.SetBatch(1)
83 rootfilename=
'%s/graphs.root' %outdir
84 myfile=ROOT.TFile(rootfilename,
'RECREATE')
90 interval=max_val-min_val
92 min_val=min_val-interval*0.2
93 max_val=max_val+interval*0.2
94 interval=max_val-min_val
96 nbins=int(interval/secsperbin)
98 print 'Minval =', min_val,
' maxval =',max_val,
' interval =',interval
100 histo=ROOT.TH1F(
'Seconds per event',
'Seconds per event',nbins,min_val,max_val)
101 histo.GetXaxis().SetTitle(
"s")
105 graph=ROOT.TGraph(npoints)
106 graph.SetMarkerStyle(8)
107 graph.SetMarkerSize(.7)
108 graph.SetMarkerColor(1)
109 graph.SetLineWidth(3)
110 graph.SetLineColor(2)
111 graph.SetTitle(
'Seconds per event')
112 graph.SetName(
'SecondsPerEvent')
113 graph.GetXaxis().SetTitle(
"Event")
115 last_event=data[-1][0]
116 print 'last event =',last_event
117 graph.GetXaxis().SetLimits(0,last_event)
119 graph.GetYaxis().SetTitleOffset(1.3)
120 graph.GetYaxis().SetTitle(
"s")
121 graph.GetYaxis().SetRangeUser(0,max_val)
129 for evt_num,secs
in data:
130 graph.SetPoint(evt_counter,evt_num,secs)
135 average=total/evt_counter
138 for i
in range(evt_counter):
139 sum+=(data[i][1]-average)**2
140 uncertainty=
sqrt(sum/(evt_counter*(evt_counter-1)))
146 print 'Total Time =', total
147 print 'Average Time =', average
148 print 'Uncertainty of Average Time =', average,
'+/-', uncertainty
152 avg_line=ROOT.TLine(1,avg,last_event,avg)
153 avg_line.SetLineColor(4)
154 avg_line.SetLineWidth(2)
157 graph_canvas=ROOT.TCanvas(
'graph_canvas')
160 avg_line.Draw(
"Same")
162 graph_canvas.Print(
"%s/graph.png" %outdir,
"png")
168 histo_canvas=ROOT.TCanvas(
'histo_canvas')
172 histo_canvas.Print(
"%s/histo.png" %outdir,
"png")
182 titlestring=
'<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
183 %(os.environ[
'CMSSW_VERSION'],time.asctime())
185 html_file_name=
'%s/%s_TimingReport.html' %(outdir,logfile_name[:-4])
186 html_file=open(html_file_name,
'w')
187 html_file.write(
'<html>\n<body>\n'+\
189 html_file.write(
'<table>\n'+\
190 '<tr>\n<td><img src=graph.png></img></td>\n'+\
191 '<td><img src=histo.png></img></td>\n</tr>\n'+\
193 html_file.write(
'<hr>\n<h2>Time Report</h2>\n<pre>\n' + report +
'</pre>\n')
194 html_file.write(
'</body>\n</html>')