CMS 3D CMS Logo

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

Functions

def manipulate_log
 

Variables

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

Function Documentation

def cmsSimplememchecker_parser.manipulate_log (   outdir,
  logfile_name,
  startevt 
)

Definition at line 4 of file cmsSimplememchecker_parser.py.

4 
5 def manipulate_log(outdir,logfile_name,startevt):
6 
7  import time
8  import sys
9  import ROOT
10 
11  os.system('pwd')
12 
13  # the fundamental structure: the key is the evt number the value is a list containing
14  # VSIZE deltaVSIZE RSS deltaRSS
15  data=[]
16  values_set=('vsize','delta_vsize','rss','delta_rss')
17  report=''
18 
19  # open file and read it and fill the structure!
20  logfile=open(logfile_name,'r')
21  logfile_lines=logfile.readlines()
22  logfile.close()
23 
24  # we get the info we need!
25  i=0
26  max_rss=(0,0)
27  parse_report=True
28  while i < len(logfile_lines):
29  line=logfile_lines[i]
30  if '%MSG-w MemoryCheck:' in line:
31  line=line[:-1] #no \n!
32  line_content_list=line.split(' ')
33  event_number=int(line_content_list[-1])
34  if event_number<startevt:
35  i+=1
36  continue
37  i+=1 # we inspect the following line
38  line=logfile_lines[i]
39  line=line[:-1] #no \n!
40  line_content_list=line.split(' ')
41  vsize=float(line_content_list[4])
42  delta_vsize=float(line_content_list[5])
43  rss=float(line_content_list[7])
44  delta_rss=float(line_content_list[8])
45 
46  data.append((event_number,{'vsize':vsize,
47  'delta_vsize':delta_vsize,
48  'rss':rss,
49  'delta_rss':delta_rss}))
50  # find maximum rss of the job
51  if rss > max_rss[1]:
52  max_rss=(event_number, rss)
53 
54  # include memory report
55  elif parse_report and 'MemoryReport' in line:
56  while 'TimeReport' not in line:
57  report += line.replace('MemoryReport', '')
58  i+=1
59  line = logfile_lines[i]
60  parse_report=False
61  i+=1
62 
63  # print maximum rss for this job
64  print 'Maximum rss =', max_rss[1]
65 
66  # skim the second entry when the event number is the same BUG!!!!!!!
67  # i take elements in couples!
68  new_data=[]
69  if len(data)>2:
70  if data[0][0]==data[1][0]:
71  print 'Two modules seem to have some output.\nCollapsing ...'
72  i=0
73  while True:
74  dataline1=data[i]
75  i+=1
76  dataline2=data[i]
77  new_eventnumber=dataline1[0]
78  new_vsize=dataline2[1]['vsize']
79  new_delta_vsize=dataline1[1]['delta_vsize']+dataline2[1]['delta_vsize']
80  new_rss=dataline2[1]['rss']
81  new_delta_rss=dataline1[1]['delta_rss']+dataline2[1]['delta_rss']
82 
83  new_data.append((new_eventnumber,{'vsize':new_vsize,
84  'delta_vsize':new_delta_vsize,
85  'rss':new_rss,
86  'delta_rss':new_delta_rss}))
87  i+=1
88  if i==len(data): break
89 
90  data=new_data
91  print 'Collapsing: Done!'
92 
93  npoints=len(data)
94 
95  print '%s values read and stored ...' %npoints
96 
97 
98  # The Graphs
99  __argv=sys.argv # trick for a strange behaviour of the TApp..
100  sys.argv=sys.argv[:1]
101  ROOT.gROOT.SetStyle("Plain") # style paranoia
102  sys.argv=__argv
103 
104  #Cannot use this option when the logfile includes
105  #a large number of events... PyRoot seg-faults.
106  #Set ROOT in batch mode to avoid canvases popping up!
107  ROOT.gROOT.SetBatch(1)
108 
109  # Save in file
110  rootfilename='%s/graphs.root' %outdir
111  myfile=ROOT.TFile(rootfilename,'RECREATE')
112 
113  # dictionary of graphs!
114  graph_dict={}
115  for value in values_set:
116  #graph_dict[value]
117  graph=ROOT.TGraph(npoints)
118  graph.SetMarkerStyle(8)
119  graph.SetMarkerSize(.7)
120  graph.SetMarkerColor(1)
121  graph.SetLineWidth(3)
122  graph.SetLineColor(2)
123  graph.SetTitle(value)
124  graph.SetName('%s_graph' %value)
125 
126 
127  #fill the graphs
128  point_counter=0
129  for event_number,vals_dict in data:
130  graph.SetPoint(point_counter,
131  event_number,
132  vals_dict[value])
133  point_counter+=1
134 
135  graph.GetXaxis().SetTitle("Event")
136  last_event=data[-1][0]
137  graph.GetXaxis().SetRangeUser(0,last_event+1)
138  graph.GetYaxis().SetTitleOffset(1.3)
139  graph.GetYaxis().SetTitle("MB")
140 
141 
142 
143  #print the graphs as files :)
144  mycanvas=ROOT.TCanvas('%s_canvas' %value)
145  mycanvas.cd()
146  graph.Draw("ALP")
147 
148  mycanvas.Print("%s/%s_graph.png"%(outdir,value),"png")
149 
150  # write it on file
151  graph.Write()
152  mycanvas.Write()
153 
154  myfile.Close()
155 
156  os.system('pwd')
157 
158  # The html page!------------------------------------------------------------------------------
159 
160  titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
161  %(os.environ['CMSSW_VERSION'],time.asctime())
162  #Introducing this if to catch the cmsRelvalreport.py use case of "reuse" of TimingReport
163  #profile when doing the SimpleMemReport... otherwise the filename for the html
164  #would be misleadingly TimingReport...
165  if len(logfile_name)>16 and 'TimingReport.log' in logfile_name[-16:]:
166  file_name=logfile_name[:-16]+"_SimpleMemReport"
167  else:
168  file_name=logfile_name[:-4]+"_SimpleMemReport"
169  html_file_name='%s/%s.html' %(outdir,file_name)
170  html_file=open(html_file_name,'w')
171  html_file.write('<html>\n<body>\n'+\
172  titlestring)
173  html_file.write('<table>\n'+\
174  '<tr>\n<td><img src=vsize_graph.png></img></td>\n'+\
175  '<td><img src=rss_graph.png></img></td>\n</tr>\n'+\
176  '<tr>\n<td><img src=delta_vsize_graph.png></img></td>\n'+\
177  '<td><img src=delta_rss_graph.png></img></td>\n</tr>\n' +\
178  '</table>\n')
179  html_file.write('<hr>\n<h1>Memory Checker Report</h1>\n<pre>\n' + report + '</pre>')
180  html_file.write('\n</body>\n</html>')
181  html_file.close()
182 

Variable Documentation

string cmsSimplememchecker_parser.default = ''

Definition at line 195 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.dest = 'profile'

Definition at line 196 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.help = 'The profile to manipulate'

Definition at line 194 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser.parser = optparse.OptionParser(usage)

Definition at line 192 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser.startevt = int(options.startevt)

Definition at line 220 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.usage = 'simplememchecker_parser.py <options>'

Definition at line 191 of file cmsSimplememchecker_parser.py.