14 """ Parses logfile_name and create an html report
15 with information and plots, at the outdir path.
16 Graphs' production is also done here.
21 logfile = open(logfile_name,
'r')
22 logfile_lines = iter(logfile.readlines())
26 for line
in logfile_lines:
28 if 'TimeEvent>' in line:
30 content = line.split(
' ')
31 event = int(content[1])
32 seconds = float(content[3])
35 elif 'TimeReport' in line:
37 report += line.replace(
'TimeReport',
'\n')
38 elif 'headings' in line:
40 elif 'complete' in line:
41 report += line.replace(
'TimeReport',
'\n')
42 for count
in range(12):
43 line =
next(logfile_lines)
47 report += line.replace(
'TimeReport',
'')
53 sys.argv = sys.argv[:1]
54 ROOT.gROOT.SetStyle(
"Plain")
59 ROOT.gROOT.SetBatch(1)
62 rootfilename =
'%s/graphs.root' %outdir
63 myfile = ROOT.TFile(rootfilename,
'RECREATE')
66 min_val = data[
min(data, key=data.get)]
67 max_val = data[
max(data, key=data.get)]
68 interval = max_val-min_val
69 min_val = min_val - (interval*0.2)
70 max_val = max_val + (interval*0.2)
71 interval = max_val - min_val
72 nbins = int(interval/secsperbin)
75 histo = ROOT.TH1F(
'Seconds per event',
'Seconds per event', nbins, min_val, max_val)
76 histo.GetXaxis().SetTitle(
"s")
79 graph = ROOT.TGraph(npoints)
80 graph.SetMarkerStyle(8)
81 graph.SetMarkerSize(.7)
82 graph.SetMarkerColor(1)
85 graph.SetTitle(
'Seconds per event')
86 graph.SetName(
'SecondsPerEvent')
87 graph.GetXaxis().SetTitle(
"Event")
88 last_event =
max(data)
89 graph.GetXaxis().SetLimits(0, last_event)
90 graph.GetYaxis().SetTitleOffset(1.3)
91 graph.GetYaxis().SetTitle(
"s")
92 graph.GetYaxis().SetRangeUser(0, max_val)
95 for event_num
in data.keys():
96 seconds = data[event_num]
97 graph.SetPoint(event_num-1, event_num, seconds)
101 avg = histo.GetMean()
102 avg_line = ROOT.TLine(1,avg,last_event, avg)
103 avg_line.SetLineColor(4)
104 avg_line.SetLineWidth(2)
106 graph_canvas = ROOT.TCanvas(
'graph_canvas')
109 avg_line.Draw(
"Same")
113 graph_canvas.Print(
"%s/graph.png" %outdir,
"png")
116 histo_canvas = ROOT.TCanvas(
'histo_canvas')
121 histo_canvas.Print(
"%s/histo.png" %outdir,
"png")
130 titlestring =
'<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
131 %(os.environ[
'CMSSW_VERSION'], time.asctime())
132 html_file_name =
'%s/%s_TimingReport.html' %(outdir, logfile_name[:-4])
133 html_file = open(html_file_name,
'w')
134 html_file.write(
'<html>\n<body>\n'+\
136 html_file.write(
'<table>\n'+\
137 '<tr>\n<td><img src=graph.png></img></td>\n'+\
138 '<td><img src=histo.png></img></td>\n</tr>\n'+\
140 html_file.write(
'<hr>\n<h2>Time Report</h2>\n<pre>\n' + report +
'</pre>\n')
141 html_file.write(
'</body>\n</html>')
147 total_events =
max(data)
148 average_time = total_time / total_events
151 sum += (data[i]-average_time)**2
152 denominator = total_events**2 - total_events
153 uncertainty =
sqrt(sum/denominator)
157 print(
'------ Statistics ------')
159 print(
'Minval = {} maxval = {} interval = {}'.
format(min_val, max_val, interval))
162 print(
'Uncertainty of Average Time = {} +/- {}'.
format(average_time, uncertainty))