CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
cmsTiming_parser Namespace Reference

Functions

def get_max
 
def get_min
 
def manipulate_log
 

Variables

string default = ''
 
string dest = 'profile'
 
string help = 'The profile to manipulate'
 
tuple parser = optparse.OptionParser(usage)
 
tuple startevt = float(options.startevt)
 
string usage = 'timing_parser.py <options>'
 

Function Documentation

def cmsTiming_parser.get_max (   data,
  index = 1 
)

Definition at line 4 of file cmsTiming_parser.py.

Referenced by manipulate_log().

4 
5 def get_max(data,index=1):
6  max_time=-1
7  for el in data:
8  sec=el[index]
9  if max_time<sec:
10  max_time=sec
11  return max_time
def cmsTiming_parser.get_min (   data,
  index = 1 
)

Definition at line 12 of file cmsTiming_parser.py.

Referenced by manipulate_log().

12 
13 def get_min(data,index=1):
14  min_time=1e20
15  for el in data:
16  sec=el[index]
17  if min_time>sec:
18  min_time=sec
19  return min_time
def cmsTiming_parser.manipulate_log (   outdir,
  logfile_name,
  secsperbin 
)

Definition at line 20 of file cmsTiming_parser.py.

References get_max(), get_min(), and mathSSE.sqrt().

20 
21 def manipulate_log(outdir,logfile_name,secsperbin):
22 
23  import time
24  import sys
25  import ROOT
26  from math import sqrt, log10, floor
27 
28  # the fundamental structure: the key is the evt number the value is a list containing
29  # VSIZE deltaVSIZE RSS deltaRSS
30  data=[]
31  report = ''
32  # open file and read it and fill the structure!
33  logfile=open(logfile_name,'r')
34  logfile_lines=logfile.readlines()
35  logfile.close()
36 
37  # we get the info we need!
38  i=0
39  parse_report=True
40  while i < len(logfile_lines):
41  line=logfile_lines[i]
42  if 'TimeEvent>' in line:
43  line=line[:-1] #no \n!
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:
49  # add an empty line before report's tables
50  if '[sec]' in line:
51  report+='\n'
52  report += line.replace('TimeReport', '')
53  # remove two non-informative lines
54  elif 'headings' in line:
55  i+=1
56  continue
57  # parsing last summaries
58  elif 'complete' in line:
59  report += '\n'
60  report += line.replace('TimeReport', '')
61  for k in range(12):
62  report += logfile_lines[i]
63  i+=1
64  parse_report=False
65  # add simple report line
66  else:
67  report += line.replace('TimeReport', '')
68  i+=1
69 
70  # init Graph and histo
71 
72  # The Graphs
73  __argv=sys.argv # trick for a strange behaviour of the TApp..
74  sys.argv=sys.argv[:1]
75  ROOT.gROOT.SetStyle("Plain") # style paranoia
76  sys.argv=__argv
77  #Cannot use this option when the logfile includes
78  #a large number of events... PyRoot seg-faults.
79  #Set ROOT in batch mode to avoid canvases popping up!
80  ROOT.gROOT.SetBatch(1)
81 
82  # Save in file
83  rootfilename='%s/graphs.root' %outdir
84  myfile=ROOT.TFile(rootfilename,'RECREATE')
85 
86 
87  # Set fancy limits
88  min_val=get_min(data,1)
89  max_val=get_max(data,1)
90  interval=max_val-min_val
91 
92  min_val=min_val-interval*0.2
93  max_val=max_val+interval*0.2
94  interval=max_val-min_val
95 
96  nbins=int(interval/secsperbin)
97 
98  print 'Minval =', min_val,' maxval =',max_val, ' interval =',interval
99 
100  histo=ROOT.TH1F('Seconds per event','Seconds per event',nbins,min_val,max_val)
101  histo.GetXaxis().SetTitle("s")
102 
103  npoints=len(data)
104 
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")
114 
115  last_event=data[-1][0]
116  print 'last event =',last_event
117  graph.GetXaxis().SetLimits(0,last_event)
118 
119  graph.GetYaxis().SetTitleOffset(1.3)
120  graph.GetYaxis().SetTitle("s")
121  graph.GetYaxis().SetRangeUser(0,max_val)
122 
123 
124 
125  # Fill them
126 
127  evt_counter=0
128  total=0
129  for evt_num,secs in data:
130  graph.SetPoint(evt_counter,evt_num,secs)
131  histo.Fill(secs)
132  total+=secs
133  evt_counter+=1
134 
135  average=total/evt_counter
136 
137  sum=0.
138  for i in range(evt_counter):
139  sum+=(data[i][1]-average)**2
140  uncertainty= sqrt(sum/(evt_counter*(evt_counter-1)))
141 
142  # round uncertainty to the most significant digit
143  #rounded_uncertainty=round(uncertainty, -int(floor(log10(uncertainty))))
144  #print 'Rounded uncertainty=' , rounded_uncertainty
145 
146  print 'Total Time =', total
147  print 'Average Time =', average
148  print 'Uncertainty of Average Time =', average, '+/-', uncertainty
149 
150  #A line which represents the average is drawn in the TGraph
151  avg=histo.GetMean()
152  avg_line=ROOT.TLine(1,avg,last_event,avg)
153  avg_line.SetLineColor(4)
154  avg_line.SetLineWidth(2)
155 
156  # draw and save!
157  graph_canvas=ROOT.TCanvas('graph_canvas')
158  graph_canvas.cd()
159  graph.Draw("ALP")
160  avg_line.Draw("Same")
161 
162  graph_canvas.Print("%s/graph.png" %outdir,"png")
163 
164  # write it on file
165  graph.Write()
166  graph_canvas.Write()
167 
168  histo_canvas=ROOT.TCanvas('histo_canvas')
169  histo_canvas.cd()
170  histo.Draw('')
171 
172  histo_canvas.Print("%s/histo.png" %outdir,"png")
173 
174  # write it on file
175  histo.Write()
176  histo_canvas.Write()
177 
178  myfile.Close()
179 
180  # The html page!------------------------------------------------------------------------------
181 
182  titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
183  %(os.environ['CMSSW_VERSION'],time.asctime())
184 
185  html_file_name='%s/%s_TimingReport.html' %(outdir,logfile_name[:-4])# a way to say the string until its last but 4th char
186  html_file=open(html_file_name,'w')
187  html_file.write('<html>\n<body>\n'+\
188  titlestring)
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'+\
192  '</table>\n')
193  html_file.write('<hr>\n<h2>Time Report</h2>\n<pre>\n' + report + '</pre>\n')
194  html_file.write('</body>\n</html>')
195  html_file.close()
196 
T sqrt(T t)
Definition: SSEVec.h:46

Variable Documentation

string cmsTiming_parser.default = ''

Definition at line 209 of file cmsTiming_parser.py.

string cmsTiming_parser.dest = 'profile'

Definition at line 210 of file cmsTiming_parser.py.

string cmsTiming_parser.help = 'The profile to manipulate'

Definition at line 208 of file cmsTiming_parser.py.

tuple cmsTiming_parser.parser = optparse.OptionParser(usage)

Definition at line 206 of file cmsTiming_parser.py.

tuple cmsTiming_parser.startevt = float(options.startevt)

Definition at line 234 of file cmsTiming_parser.py.

string cmsTiming_parser.usage = 'timing_parser.py <options>'

Definition at line 205 of file cmsTiming_parser.py.