6 from math
import sqrt, log10, floor
11 """ Parses logfile_name and create an html report 12 with information and plots, at the outdir path. 13 Graphs' production is also done here. 18 logfile = open(logfile_name,
'r') 19 logfile_lines = iter(logfile.readlines()) 23 for line
in logfile_lines:
25 if 'TimeEvent>' in line:
27 content = line.split(
' ')
28 event =
int(content[1])
29 seconds =
float(content[3])
32 elif 'TimeReport' in line:
34 report += line.replace(
'TimeReport',
'\n')
35 elif 'headings' in line:
37 elif 'complete' in line:
38 report += line.replace(
'TimeReport',
'\n')
39 for count
in range(12):
40 line =
next(logfile_lines)
44 report += line.replace(
'TimeReport',
'')
50 sys.argv = sys.argv[:1]
51 ROOT.gROOT.SetStyle(
"Plain")
56 ROOT.gROOT.SetBatch(1)
59 rootfilename =
'%s/graphs.root' %outdir
60 myfile = ROOT.TFile(rootfilename,
'RECREATE')
63 min_val = data[
min(data, key=data.get)]
64 max_val = data[
max(data, key=data.get)]
65 interval = max_val-min_val
66 min_val = min_val - (interval*0.2)
67 max_val = max_val + (interval*0.2)
68 interval = max_val - min_val
69 nbins =
int(interval/secsperbin)
72 histo = ROOT.TH1F(
'Seconds per event',
'Seconds per event', nbins, min_val, max_val)
73 histo.GetXaxis().SetTitle(
"s")
76 graph = ROOT.TGraph(npoints)
77 graph.SetMarkerStyle(8)
78 graph.SetMarkerSize(.7)
79 graph.SetMarkerColor(1)
82 graph.SetTitle(
'Seconds per event')
83 graph.SetName(
'SecondsPerEvent')
84 graph.GetXaxis().SetTitle(
"Event")
85 last_event =
max(data)
86 graph.GetXaxis().SetLimits(0, last_event)
87 graph.GetYaxis().SetTitleOffset(1.3)
88 graph.GetYaxis().SetTitle(
"s")
89 graph.GetYaxis().SetRangeUser(0, max_val)
92 for event_num
in data.keys():
93 seconds = data[event_num]
94 graph.SetPoint(event_num-1, event_num, seconds)
99 avg_line = ROOT.TLine(1,avg,last_event, avg)
100 avg_line.SetLineColor(4)
101 avg_line.SetLineWidth(2)
103 graph_canvas = ROOT.TCanvas(
'graph_canvas')
106 avg_line.Draw(
"Same")
110 graph_canvas.Print(
"%s/graph.png" %outdir,
"png")
113 histo_canvas = ROOT.TCanvas(
'histo_canvas')
118 histo_canvas.Print(
"%s/histo.png" %outdir,
"png")
127 titlestring =
'<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
128 %(os.environ[
'CMSSW_VERSION'], time.asctime())
129 html_file_name =
'%s/%s_TimingReport.html' %(outdir, logfile_name[:-4])
130 html_file = open(html_file_name,
'w')
131 html_file.write(
'<html>\n<body>\n'+\
133 html_file.write(
'<table>\n'+\
134 '<tr>\n<td><img src=graph.png></img></td>\n'+\
135 '<td><img src=histo.png></img></td>\n</tr>\n'+\
137 html_file.write(
'<hr>\n<h2>Time Report</h2>\n<pre>\n' + report +
'</pre>\n')
138 html_file.write(
'</body>\n</html>')
144 total_events =
max(data)
145 average_time = total_time / total_events
147 for i
in range(1,
max(data)+1):
148 sum += (data[i]-average_time)**2
149 denominator = total_events**2 - total_events
150 uncertainty =
sqrt(sum/denominator)
154 print '------ Statistics ------' 155 print 'last event = {}'.
format(last_event)
156 print 'Minval = {} maxval = {} interval = {}'.
format(min_val, max_val, interval)
157 print 'Total Time = {}'.
format(total_time)
158 print 'Average Time = {}'.
format(average_time)
159 print 'Uncertainty of Average Time = {} +/- {}'.
format(average_time, uncertainty)
163 if __name__ ==
'__main__':
166 usage =
'timing_parser.py <options>' 167 parser = optparse.OptionParser(usage)
168 parser.add_option(
'-i',
'--in_ profile',
169 help=
'The profile to manipulate' ,
173 parser.add_option(
'-o',
'--outdir',
174 help=
'The directory of the output' ,
178 parser.add_option(
'-n',
179 help=
'Number of secs per bin. Default is 1.' ,
182 (options,args) = parser.parse_args()
185 if options.profile ==
'' or\
186 options.outdir ==
'':
187 raise Exception(
'Please select a profile and an output dir!')
189 if not os.path.exists(options.profile)
or\
190 not os.path.exists(options.outdir):
191 raise Exception(
'Outdir or input profile not present!')
196 print 'Problems in convertng starting event value!'
def manipulate_log(outdir, logfile_name, secsperbin)