-
Notifications
You must be signed in to change notification settings - Fork 0
/
HOLogParser.py
86 lines (79 loc) · 3.45 KB
/
HOLogParser.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
import re
import os
import shutil
# Return unique humongous objects from jfr log 'humongousObject.log' from JFRParser.java
def getUniqueHOObjects(jfrlogfile, needHTMLFile):
f = open(jfrlogfile, 'rU')
HOlist = []
HOdict = {}
i = -1
for line in f:
match = re.search(r'([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]*)\s\sSizeInMB=([0-9.]*)\sSizeInB=([0-9.]*)\sClass=(.*)\sThread=(.*)\sEndTime=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]*)\sJfrfile=([\w\.\-_\d]*)\sHost=([\w]*)\sStacktrace=(.*\n)', line)
if match:
i = i + 1
HO = {}
HO['AllocationEndTime'] = match.group(1)
HO['SizeInB'] = match.group(3)
HO['jfrfilename'] = match.group(7)
HO['Host'] = match.group(8)
HO['Stacktrace'] = []
HO['Stacktrace'].append(match.group(9))
HOlist.append(HO)
else:
HOlist[i]['Stacktrace'].append(line)
f.close()
for HO in HOlist:
key = ''.join(HO['Stacktrace'])
if key in HOdict:
HOdict[key]['Number'] = HOdict[key]['Number'] + 1
tmp = {}
tmp['AllocationEndTime'] = HO['AllocationEndTime']
tmp['SizeInB'] = HO['SizeInB']
tmp['jfrfilename'] = HO['jfrfilename']
tmp['Host'] = HO['Host']
HOdict[key]['HOs'].append(tmp)
else:
HOdict[key] = {}
HOdict[key]['Number'] = 1
HOdict[key]['HOs'] = []
tmp = {}
tmp['AllocationEndTime'] = HO['AllocationEndTime']
tmp['SizeInB'] = HO['SizeInB']
tmp['jfrfilename'] = HO['jfrfilename']
tmp['Host'] = HO['Host']
HOdict[key]['HOs'].append(tmp)
if needHTMLFile:
path = os.path.dirname(os.path.abspath(jfrlogfile)) + os.sep + 'html'
if os.path.exists(path):
shutil.rmtree(path)
os.mkdir(path)
f = open(path + os.sep + 'index.html', 'w')
f.write('<html><body>\n')
f.write('<h1>There are totally ' + str(len(HOlist)) + ' humongous objects. And have ' + str(len(HOdict)) + ' sources with different stacktrace. </h1><br>')
i = 1
for key in HOdict:
tmp = path + os.sep + 'Source' + str(i)
f1 = open(tmp + '.html', 'w')
tmpList = key.split('\n')
list2 = []
for tmpitem in tmpList:
temp = tmpitem.replace('<', '<').replace('>', '>')
if temp.find('successfactors') != -1:
temp = '<font color="blue">' + temp + '</font>'
list2.append(temp)
f1.write("<h1>Humongous Objects:</h1>")
for HO in HOdict[key]['HOs']:
f1.write('<font color="green">AllocationEndTime</font>=' + HO['AllocationEndTime'])
f1.write(' <font color="green">SizeInB</font>=' + HO['SizeInB'])
f1.write(' <font color="green">Host</font>=' + HO['Host'])
f1.write(' <font color="green">jfrfilename</font>=' + HO['jfrfilename'] + '<br>')
f1.write("<h1>StackTrace:</h1>")
for lt in list2:
f1.write(lt)
f1.write('<br>')
f1.close()
f.write('<a href="' + tmp + '.html">' + os.path.basename(tmp) + '</a>: ' + str(HOdict[key]['Number']) + ' # of humongous objects<br>')
i = i + 1
f.write('\n</body></html>\n')
f.close()
return HOdict