-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloatfinder.py
150 lines (112 loc) · 3.73 KB
/
bloatfinder.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
#!/usr/bin/python
# 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/.
# This prints out the tests that open the most windows.
import sys
import re
import time
winPatt = re.compile('(\d\d:\d\d:\d\d)\W+INFO - (..)DOMWINDOW == (\d+).*\[pid = (\d+)\] \[serial = (\d+)\]')
def timeFromString(t):
[hr, mi, se] = t.split(':')
return ((60 * int(hr)) + int(mi)) * 60 + int(se)
def stringFromTime(t0):
se = t0 % 60
t = t0 / 60
mi = t % 60
h = t / 60
return '{:0>2}:{:0>2}:{:0>2}'.format(h, mi, se)
scaleFactor = 10
def writeStars(count):
count = count / scaleFactor
i = 0
while i < count:
sys.stdout.write('*')
i += 1
def windowsPerSecondChart(windowsPerSecond):
keys = sorted(windowsPerSecond.keys())
prevKey = keys[0] - 1
for k in keys:
while prevKey + 1 < k:
prevKey += 1
print stringFromTime(prevKey)
count = windowsPerSecond.get(k, 0)
sys.stdout.write(stringFromTime(k) + ' ')
writeStars(count)
print
prevKey = k
def peakWindowsPerSecondChart(peakWindowsPerSecond, lastLiveWindowsPerSecond):
keys = sorted(peakWindowsPerSecond.keys())
prevKey = keys[0] - 1
lastLive = lastLiveWindowsPerSecond.get(keys[0], 0)
for k in keys:
while prevKey + 1 < k:
prevKey += 1
# We're measuring the peak number of windows across a given
# second, not the final number of windows live in that second,
# so we can't just reuse the previous value.
sys.stdout.write(stringFromTime(prevKey) + ' ')
writeStars(lastLive)
print
count = peakWindowsPerSecond.get(k, 0)
sys.stdout.write(stringFromTime(k) + ' ')
writeStars(count)
lastLive = lastLiveWindowsPerSecond.get(k)
print
prevKey = k
def windowsPerTest(counts):
keys = sorted(counts.keys())
keys.reverse()
print 'Number of windows opened in each test.'
for k in keys[:10]:
print k, ', '.join(counts[k])
def peakWindowsPerTest(peaks):
keys = sorted(peaks.keys())
keys.reverse()
print 'Peak number of live windows in each test.'
for k in keys[:10]:
print k, ', '.join(peaks[k])
# Parse the input looking for when tests run and when windows are opened or closed.
test = None
numLive = 0
count = 0
peakNumLive = 0
counts = {}
peaks = {}
windowsPerSecond = {}
peakWindowsPerSecond = {}
lastLiveWindowsPerSecond = {}
for l in sys.stdin:
if l.find("TEST-START") > -1:
if test:
counts.setdefault(count, []).append(test)
peaks.setdefault(peakNumLive, []).append(test)
count = 0
peakNumLive = numLive
test = l.split('|')[1].strip()
m = winPatt.match(l)
if not m:
continue
if m.group(2) == '++':
count += 1
numLive += 1
t = timeFromString(m.group(1))
windowsPerSecond[t] = windowsPerSecond.setdefault(t, 1) + 1
if numLive > peakNumLive:
peakNumLive = numLive
if numLive > peakWindowsPerSecond.setdefault(t, 0):
peakWindowsPerSecond[t] = numLive
lastLiveWindowsPerSecond[t] = numLive
else:
assert m.group(2) == '--'
assert numLive > 0
numLive -= 1
if numLive > peakWindowsPerSecond.setdefault(t, 0):
peakWindowsPerSecond[t] = numLive
lastLiveWindowsPerSecond[t] = numLive
# Various output.
#windowsPerSecondChart(windowsPerSecond)
peakWindowsPerSecondChart(peakWindowsPerSecond, lastLiveWindowsPerSecond)
#windowsPerTest(counts)
#print
#peakWindowsPerTest(peaks)