3 from __future__
import print_function
4 from builtins
import range
8 from math
import sqrt, log10, floor
13 """ Parses logfile_name and create an html report
14 with information and plots, at the outdir path.
15 Graphs' production is also done here.
20 logfile = open(logfile_name,
'r')
21 logfile_lines = iter(logfile.readlines())
25 for line
in logfile_lines:
27 if 'TimeEvent>' in line:
29 content = line.split(
' ')
30 event = int(content[1])
31 seconds = float(content[3])
34 elif 'TimeReport' in line:
36 report += line.replace(
'TimeReport',
'\n')
37 elif 'headings' in line:
39 elif 'complete' in line:
40 report += line.replace(
'TimeReport',
'\n')
41 for count
in range(12):
42 line =
next(logfile_lines)
46 report += line.replace(
'TimeReport',
'')
52 sys.argv = sys.argv[:1]
53 ROOT.gROOT.SetStyle(
"Plain")
58 ROOT.gROOT.SetBatch(1)
61 rootfilename =
'%s/graphs.root' %outdir
62 myfile = ROOT.TFile(rootfilename,
'RECREATE')
65 min_val = data[
min(data, key=data.get)]
66 max_val = data[
max(data, key=data.get)]
67 interval = max_val-min_val
68 min_val = min_val - (interval*0.2)
69 max_val = max_val + (interval*0.2)
70 interval = max_val - min_val
71 nbins = int(interval/secsperbin)
74 histo = ROOT.TH1F(
'Seconds per event',
'Seconds per event', nbins, min_val, max_val)
75 histo.GetXaxis().SetTitle(
"s")
78 graph = ROOT.TGraph(npoints)
79 graph.SetMarkerStyle(8)
80 graph.SetMarkerSize(.7)
81 graph.SetMarkerColor(1)
84 graph.SetTitle(
'Seconds per event')
85 graph.SetName(
'SecondsPerEvent')
86 graph.GetXaxis().SetTitle(
"Event")
87 last_event =
max(data)
88 graph.GetXaxis().SetLimits(0, last_event)
89 graph.GetYaxis().SetTitleOffset(1.3)
90 graph.GetYaxis().SetTitle(
"s")
91 graph.GetYaxis().SetRangeUser(0, max_val)
94 for event_num
in data.keys():
95 seconds = data[event_num]
96 graph.SetPoint(event_num-1, event_num, seconds)
100 avg = histo.GetMean()
101 avg_line = ROOT.TLine(1,avg,last_event, avg)
102 avg_line.SetLineColor(4)
103 avg_line.SetLineWidth(2)
105 graph_canvas = ROOT.TCanvas(
'graph_canvas')
108 avg_line.Draw(
"Same")
112 graph_canvas.Print(
"%s/graph.png" %outdir,
"png")
115 histo_canvas = ROOT.TCanvas(
'histo_canvas')
120 histo_canvas.Print(
"%s/histo.png" %outdir,
"png")
129 titlestring =
'<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
130 %(os.environ[
'CMSSW_VERSION'], time.asctime())
131 html_file_name =
'%s/%s_TimingReport.html' %(outdir, logfile_name[:-4])
132 html_file = open(html_file_name,
'w')
133 html_file.write(
'<html>\n<body>\n'+\
135 html_file.write(
'<table>\n'+\
136 '<tr>\n<td><img src=graph.png></img></td>\n'+\
137 '<td><img src=histo.png></img></td>\n</tr>\n'+\
139 html_file.write(
'<hr>\n<h2>Time Report</h2>\n<pre>\n' + report +
'</pre>\n')
140 html_file.write(
'</body>\n</html>')
146 total_events =
max(data)
147 average_time = total_time / total_events
150 sum += (data[i]-average_time)**2
151 denominator = total_events**2 - total_events
152 uncertainty =
sqrt(sum/denominator)
156 print(
'------ Statistics ------')
158 print(
'Minval = {} maxval = {} interval = {}'.
format(min_val, max_val, interval))
161 print(
'Uncertainty of Average Time = {} +/- {}'.
format(average_time, uncertainty))
165 if __name__ ==
'__main__':
168 usage =
'timing_parser.py <options>'
169 parser = optparse.OptionParser(usage)
170 parser.add_option(
'-i',
'--in_ profile',
171 help=
'The profile to manipulate' ,
175 parser.add_option(
'-o',
'--outdir',
176 help=
'The directory of the output' ,
180 parser.add_option(
'-n',
181 help=
'Number of secs per bin. Default is 1.' ,
184 (options,args) = parser.parse_args()
187 if options.profile ==
'' or\
188 options.outdir ==
'':
189 raise Exception(
'Please select a profile and an output dir!')
191 if not os.path.exists(options.profile)
or\
192 not os.path.exists(options.outdir):
193 raise Exception(
'Outdir or input profile not present!')
196 startevt = float(options.startevt)
198 print(
'Problems in convertng starting event value!')
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)