forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmsSimplememchecker_parser.py
executable file
·228 lines (181 loc) · 7.85 KB
/
cmsSimplememchecker_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#! /usr/bin/env python3
def manipulate_log(outdir,logfile_name,startevt):
import time
import sys
import ROOT
os.system('pwd')
# the fundamental structure: the key is the evt number the value is a list containing
# VSIZE deltaVSIZE RSS deltaRSS
data=[]
values_set=('vsize','delta_vsize','rss','delta_rss')
report=''
# open file and read it and fill the structure!
logfile=open(logfile_name,'r')
logfile_lines=logfile.readlines()
logfile.close()
# we get the info we need!
i=0
max_rss=(0,0)
parse_report=True
while i < len(logfile_lines):
line=logfile_lines[i]
if '%MSG-w MemoryCheck:' in line:
line=line[:-1] #no \n!
line_content_list=line.split(' ')
event_number=int(line_content_list[-1])
if event_number<startevt:
i+=1
continue
i+=1 # we inspect the following line
line=logfile_lines[i]
line=line[:-1] #no \n!
line_content_list=line.split(' ')
vsize=float(line_content_list[4])
delta_vsize=float(line_content_list[5])
rss=float(line_content_list[7])
delta_rss=float(line_content_list[8])
data.append((event_number,{'vsize':vsize,
'delta_vsize':delta_vsize,
'rss':rss,
'delta_rss':delta_rss}))
# find maximum rss of the job
if rss > max_rss[1]:
max_rss=(event_number, rss)
# include memory report
elif parse_report and 'MemoryReport' in line:
while 'TimeReport' not in line:
report += line.replace('MemoryReport', '')
i+=1
line = logfile_lines[i]
parse_report=False
i+=1
# print maximum rss for this job
print('Maximum rss =', max_rss[1])
# skim the second entry when the event number is the same BUG!!!!!!!
# i take elements in couples!
new_data=[]
if len(data)>2:
if data[0][0]==data[1][0]:
print('Two modules seem to have some output.\nCollapsing ...')
i=0
while True:
dataline1=data[i]
i+=1
dataline2=data[i]
new_eventnumber=dataline1[0]
new_vsize=dataline2[1]['vsize']
new_delta_vsize=dataline1[1]['delta_vsize']+dataline2[1]['delta_vsize']
new_rss=dataline2[1]['rss']
new_delta_rss=dataline1[1]['delta_rss']+dataline2[1]['delta_rss']
new_data.append((new_eventnumber,{'vsize':new_vsize,
'delta_vsize':new_delta_vsize,
'rss':new_rss,
'delta_rss':new_delta_rss}))
i+=1
if i==len(data): break
data=new_data
print('Collapsing: Done!')
npoints=len(data)
print('%s values read and stored ...' %npoints)
# The Graphs
__argv=sys.argv # trick for a strange behaviour of the TApp..
sys.argv=sys.argv[:1]
ROOT.gROOT.SetStyle("Plain") # style paranoia
sys.argv=__argv
#Cannot use this option when the logfile includes
#a large number of events... PyRoot seg-faults.
#Set ROOT in batch mode to avoid canvases popping up!
ROOT.gROOT.SetBatch(1)
# Save in file
rootfilename='%s/graphs.root' %outdir
myfile=ROOT.TFile(rootfilename,'RECREATE')
# dictionary of graphs!
graph_dict={}
for value in values_set:
#graph_dict[value]
graph=ROOT.TGraph(npoints)
graph.SetMarkerStyle(8)
graph.SetMarkerSize(.7)
graph.SetMarkerColor(1)
graph.SetLineWidth(3)
graph.SetLineColor(2)
graph.SetTitle(value)
graph.SetName('%s_graph' %value)
#fill the graphs
point_counter=0
for event_number,vals_dict in data:
graph.SetPoint(point_counter,
event_number,
vals_dict[value])
point_counter+=1
graph.GetXaxis().SetTitle("Event")
last_event=data[-1][0]
graph.GetXaxis().SetRangeUser(0,last_event+1)
graph.GetYaxis().SetTitleOffset(1.3)
graph.GetYaxis().SetTitle("MB")
#print the graphs as files :)
mycanvas=ROOT.TCanvas('%s_canvas' %value)
mycanvas.cd()
graph.Draw("ALP")
mycanvas.Print("%s/%s_graph.png"%(outdir,value),"png")
# write it on file
graph.Write()
mycanvas.Write()
myfile.Close()
os.system('pwd')
# The html page!------------------------------------------------------------------------------
titlestring='<b>Report executed with release %s on %s.</b>\n<br>\n<hr>\n'\
%(os.environ['CMSSW_VERSION'],time.asctime())
#Introducing this if to catch the cmsRelvalreport.py use case of "reuse" of TimingReport
#profile when doing the SimpleMemReport... otherwise the filename for the html
#would be misleadingly TimingReport...
if len(logfile_name)>16 and 'TimingReport.log' in logfile_name[-16:]:
file_name=logfile_name[:-16]+"_SimpleMemReport"
else:
file_name=logfile_name[:-4]+"_SimpleMemReport"
html_file_name='%s/%s.html' %(outdir,file_name)
html_file=open(html_file_name,'w')
html_file.write('<html>\n<body>\n'+\
titlestring)
html_file.write('<table>\n'+\
'<tr>\n<td><img src=vsize_graph.png></img></td>\n'+\
'<td><img src=rss_graph.png></img></td>\n</tr>\n'+\
'<tr>\n<td><img src=delta_vsize_graph.png></img></td>\n'+\
'<td><img src=delta_rss_graph.png></img></td>\n</tr>\n' +\
'</table>\n')
html_file.write('<hr>\n<h1>Memory Checker Report</h1>\n<pre>\n' + report + '</pre>')
html_file.write('\n</body>\n</html>')
html_file.close()
#################################################################################################
if __name__ == '__main__':
import optparse
import os
# Here we define an option parser to handle commandline options..
usage='simplememchecker_parser.py <options>'
parser = optparse.OptionParser(usage)
parser.add_option('-i', '--in_ profile',
help='The profile to manipulate' ,
default='',
dest='profile')
parser.add_option('-o', '--outdir',
help='The directory of the output' ,
default='',
dest='outdir')
parser.add_option('-n',
help='The event number from which we start. Default is 1.' ,
default='1',
dest='startevt')
(options,args) = parser.parse_args()
# Now some fault control..If an error is found we raise an exception
if options.profile=='' or\
options.outdir=='':
raise('Please select a profile and an output dir!')
if not os.path.exists(options.profile) or\
not os.path.exists(options.outdir):
raise ('Outdir or input profile not present!')
try:
startevt=int(options.startevt)
except ValueError:
print('Problems in convertng starting event value!')
#launch the function!
manipulate_log(options.outdir,options.profile,startevt)