-
Notifications
You must be signed in to change notification settings - Fork 0
/
plusplus.py
executable file
·174 lines (140 loc) · 5.1 KB
/
plusplus.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
#!/usr/bin/python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Analyze the ++/-- DOMWINDOW in a TBPL log.
import re
import sys
winPatt = re.compile('I/DocShellAndDOMWindowLeak (..)DOMWINDOW == (\d+).*\[pid = (\d+)\] \[serial = (\d+)\] \[[^\]]+\].?(\[url = [^\]]+)?')
urlLen = len('[url = ')
leakLogCreatePatt = re.compile('### XPCOM_MEM_BLOAT_LOG defined -- logging bloat/leaks to (.+)$')
leakLogReadPatt = re.compile('INFO \- leakcheck \| Processing leak log file (.+)$')
bloatViewPatt = re.compile('BloatView: ALL \(cumulative\) LEAK AND BLOAT STATISTICS\, ([a-zA-Z]+) process (\d+)')
failPatt = re.compile('TEST-UNEXPECTED-FAIL \| leakcheck large nsGlobalWindowInner \| (.+)$')
testPatt = re.compile('INFO \- TEST-(START|SKIP|OK) \| (\S+)')
windowCountPatt = re.compile('INFO \- TEST-INFO \| leakcheck \| [a-zA-Z]+ leaked ([0-9]+) (nsGlobalWindowInner|nsGlobalWindowOuter)')
def findLeakers():
live = {}
hiddenLive = {}
foundAny = False
lastLeakLog = None
currTest = None
inSkip = False
currBloatPid = 0
pidLeaks = {}
testsForLogs = {}
leakingLogs = {}
sys.stdin.reconfigure(encoding='latin1')
for l in sys.stdin:
tp = testPatt.search(l)
if tp:
state = tp.group(1)
t = tp.group(2)
if state == "START":
if t == "Shutdown":
continue
assert (currTest is None) or inSkip
currTest = t
inSkip = False
elif state == "SKIP":
assert currTest == t
inSkip = True
elif state == "OK":
assert currTest == t
currTest = None
inSkip = False
continue
m = winPatt.search(l)
if m:
isNew = m.group(1) == '++'
assert isNew or m.group(1) == '--'
# XXX m.group(1) is the window pointer.
# Could use that to disambiguate.
numLive = int(m.group(2))
pid = int(m.group(3))
serial = int(m.group(4))
url = m.group(5)
if url:
url = url[urlLen:]
winId = (pid, serial)
if isNew:
assert url is None
if winId in live:
assert not winId in hiddenLive
hiddenLive[winId] = live[winId]
live[winId] = currTest
foundAny = True
else:
assert winId in live
del live[winId]
continue
f = failPatt.search(l)
if f:
leakLog = f.group(1)
assert not leakLog in leakingLogs
leakingLogs[lastLeakLog] = f.group(1)
continue
llc = leakLogCreatePatt.search(l)
if llc:
leakLog = llc.group(1)
t = currTest if currTest else "NONE"
testsForLogs.setdefault(leakLog, []).append(t)
continue
llr = leakLogReadPatt.search(l)
if llr:
lastLeakLog = llr.group(1)
continue
bv = bloatViewPatt.search(l)
if bv:
# bv.group(1) is the log file.
currBloatPid = int(bv.group(2))
# XXX Hopefully if a PID is reused, both won't leak.
assert not currBloatPid in pidLeaks
pidLeaks[currBloatPid] = {}
continue
wc = windowCountPatt.search(l)
if wc:
count = int(wc.group(1))
which = wc.group(2)
m = pidLeaks[currBloatPid]
assert not which in m
m[which] = count
continue
if not foundAny:
print("Didn't find any windows in the log.")
pidToWindows = {}
for x, currTest in hiddenLive.items():
pid = x[0]
pidToWindows.setdefault(pid, []).append([x[0], x[1], currTest])
for x, currTest in live.items():
pid = x[0]
pidToWindows.setdefault(pid, []).append([x[0], x[1], currTest])
for pid, m in pidLeaks.items():
print(f'pid:{pid}')
print(' leaked: ', end='')
x = []
for which, count in m.items():
x.append(f'{count} {which}')
print(', '.join(x))
for [x, y, z] in pidToWindows.get(pid, []):
print(f' [pid = {x}] [serial = {y}] during {z}')
print()
for log, reported in leakingLogs.items():
print(f'log: {log}')
print(f' reported test directory: {reported}')
print(f' actual test: {", ".join(testsForLogs.get(log, ["NONE"]))}')
print()
dupeCount = 0
nonDupeCount = 0
for log, tests in testsForLogs.items():
nonDupeCount += 1
if len(tests) <= 1:
continue
dupeCount += len(tests) - 1
if False:
tstring = "\n ".join(tests)
print(f'Duplicate logs {log}:\n {tstring}')
print(f'Number of non-overridden logs: {nonDupeCount}')
print(f'Number of overridden logs: {dupeCount}')
print()
findLeakers()