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(), and get_min().

20 
21 def manipulate_log(outdir,logfile_name,secsperbin):
22 
23  import time
24  import sys
25  import ROOT
26 
27  # the fundamental structure: the key is the evt number the value is a list containing
28  # VSIZE deltaVSIZE RSS deltaRSS
29  data=[]
30 
31  # open file and read it and fill the structure!
32  logfile=open(logfile_name,'r')
33  logfile_lines=logfile.readlines()
34  logfile.close()
35 
36  # we get the info we need!
37  i=0
38  while i < len(logfile_lines):
39  line=logfile_lines[i]
40  if 'TimeEvent>' in line:
41  line=line[:-1] #no \n!
42  line_content_list=line.split(' ')
43  event_number=int(line_content_list[1])
44  seconds=float(line_content_list[3])
45  data.append((event_number,seconds))
46  i+=1
47 
48  # init Graph and histo
49 
50  # The Graphs
51  __argv=sys.argv # trick for a strange behaviour of the TApp..
52  sys.argv=sys.argv[:1]
53  ROOT.gROOT.SetStyle("Plain") # style paranoia
54  sys.argv=__argv
55  #Cannot use this option when the logfile includes
56  #a large number of events... PyRoot seg-faults.
57  #Set ROOT in batch mode to avoid canvases popping up!
58  ROOT.gROOT.SetBatch(1)
59 
60  # Save in file
61  rootfilename='%s/graphs.root' %outdir
62  myfile=ROOT.TFile(rootfilename,'RECREATE')
63 
64 
65  # Set fancy limits
66  min_val=get_min(data,1)
67  max_val=get_max(data,1)
68  interval=max_val-min_val
69 
70  min_val=min_val-interval*0.2
71  max_val=max_val+interval*0.2
72  interval=max_val-min_val
73 
74  nbins=int(interval/secsperbin)
75 
76  print 'Minval=',min_val,' maxval=',max_val, ' interval=',interval
77 
78  histo=ROOT.TH1F('Seconds per event','Seconds per event',nbins,min_val,max_val)
79  histo.GetXaxis().SetTitle("s")
80 
81  npoints=len(data)
82 
83  graph=ROOT.TGraph(npoints)
84  graph.SetMarkerStyle(8)
85  graph.SetMarkerSize(.7)
86  graph.SetMarkerColor(1)
87  graph.SetLineWidth(3)
88  graph.SetLineColor(2)
89  graph.SetTitle('Seconds per event')
90  graph.SetName('SecondsPerEvent')
91  graph.GetXaxis().SetTitle("Event")
92 
93  last_event=data[-1][0]
94  print 'last event =',last_event
95  graph.GetXaxis().SetLimits(0,last_event)
96 
97  graph.GetYaxis().SetTitleOffset(1.3)
98  graph.GetYaxis().SetTitle("s")
99  graph.GetYaxis().SetRangeUser(0,max_val)
100 
101 
102 
103  # Fill them
104 
105  evt_counter=0
106  total=0
107  for evt_num,secs in data:
108  graph.SetPoint(evt_counter,evt_num,secs)
109  histo.Fill(secs)
110  total+=secs
111  evt_counter+=1
112 
113  print 'Total Time=', total
114 
115  #A line which represents the average is drawn in the TGraph
116  avg=histo.GetMean()
117  avg_line=ROOT.TLine(1,avg,last_event,avg)
118  avg_line.SetLineColor(4)
119  avg_line.SetLineWidth(2)
120 
121  # draw and save!
122  graph_canvas=ROOT.TCanvas('graph_canvas')
123  graph_canvas.cd()
124  graph.Draw("ALP")
125  avg_line.Draw("Same")
126 
127  graph_canvas.Print("%s/graph.gif" %outdir,"gif")
128 
129  # write it on file
130  graph.Write()
131  graph_canvas.Write()
132 
133  histo_canvas=ROOT.TCanvas('histo_canvas')
134  histo_canvas.cd()
135  histo.Draw('')
136 
137  histo_canvas.Print("%s/histo.gif" %outdir,"gif")
138 
139  # write it on file
140  histo.Write()
141  histo_canvas.Write()
142 
143  myfile.Close()
144 
145  # The html page!------------------------------------------------------------------------------
146 
147  titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
148  %(os.environ['CMSSW_VERSION'],time.asctime())
149 
150  html_file_name='%s/%s.html' %(outdir,logfile_name[:-4])# a way to say the string until its last but 4th char
151  html_file=open(html_file_name,'w')
152  html_file.write('<html>\n<body>\n'+\
153  titlestring)
154  html_file.write('<table>\n'+\
155  '<tr><td><img src=graph.gif></img></td></tr>'+\
156  '<tr><td><img src=histo.gif></img></td></tr>'+\
157  '</table>\n')
158  html_file.write('\n</body>\n</html>')
159  html_file.close()
160 

Variable Documentation

string cmsTiming_parser.default = ''

Definition at line 173 of file cmsTiming_parser.py.

string cmsTiming_parser.dest = 'profile'

Definition at line 174 of file cmsTiming_parser.py.

string cmsTiming_parser.help = 'The profile to manipulate'

Definition at line 172 of file cmsTiming_parser.py.

tuple cmsTiming_parser.parser = optparse.OptionParser(usage)

Definition at line 170 of file cmsTiming_parser.py.

tuple cmsTiming_parser.startevt = float(options.startevt)

Definition at line 198 of file cmsTiming_parser.py.

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

Definition at line 169 of file cmsTiming_parser.py.