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

Variable Documentation

string cmsSimplememchecker_parser.default = ''

Definition at line 178 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.dest = 'profile'

Definition at line 179 of file cmsSimplememchecker_parser.py.

string cmsSimplememchecker_parser.help = 'The profile to manipulate'

Definition at line 177 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser.parser = optparse.OptionParser(usage)

Definition at line 175 of file cmsSimplememchecker_parser.py.

tuple cmsSimplememchecker_parser.startevt = int(options.startevt)

Definition at line 203 of file cmsSimplememchecker_parser.py.

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

Definition at line 174 of file cmsSimplememchecker_parser.py.