-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprofilehist.py
36 lines (30 loc) · 938 Bytes
/
profilehist.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
import sys
import numpy as np
from collections import defaultdict
def DumpHistogram(h):
f = open("hist.txt", 'w')
for addr in sorted(h.keys()):
print >>f, hex(addr), h[addr]
f.close()
def CollectSamples(infile):
histogram = defaultdict(int)
checkpointctr = 0
while True:
buf = infile.read(32)
if len(buf) < 32:
break
addrs = np.frombuffer(buf, np.uint16)
# stackframe = []
for addr in addrs:
# for now, ignore stack frames and just add a single sample for each
# if addr & 0x8000:
# stackframe.append((addr & 0x7fff) * 2)
# else:
histogram[(addr & 0x7fff) * 2] += 1
checkpointctr += 1
if checkpointctr > 100:
DumpHistogram(histogram)
checkpointctr = 0
return histogram
if __name__ == '__main__':
CollectSamples(open(sys.argv[1], 'rb'))