CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 5 of file cmsSimplememchecker_parser.py.

References print().

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

Variable Documentation

string cmsSimplememchecker_parser.default = ''

Definition at line 196 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.dest = 'profile'

Definition at line 197 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.help = 'The profile to manipulate'

Definition at line 195 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser.parser = optparse.OptionParser(usage)

Definition at line 193 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser.startevt = int(options.startevt)

Definition at line 221 of file cmsSimplememchecker_parser.py.

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

Definition at line 192 of file cmsSimplememchecker_parser.py.