File: gcstat.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (53 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download | duplicates (7)
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
try:
    import psyco
    psyco.full()
except ImportError:
    pass

class LifeTime(object):
    __slots__ = "typeid address size varsize birth death".split()
    def __init__(self, typeid, address, size, varsize, birth, death=-1):
        self.typeid = typeid
        self.address = address
        self.size = size
        self.birth = birth
        self.death = death
        self.varsize = varsize

def parse_file(f, callback):
    unknown_lifetime = {}
    current = 0
    for i, line in enumerate(f):
        if i % 100000 == 0:
            print i
        line = line.split()
        if line[0] == "free":
            _, typeid, address = line
            typeid = int(typeid)
            address = int(address, 16)
            unknown = unknown_lifetime.pop(address)
            unknown.death = current
            callback(unknown)
        else:
            if line[0] == "malloc_varsize":
                varsize = True
            else:
                varsize = False
            _, typeid, size, address = line
            size = int(size)
            typeid = int(typeid)
            address = int(address, 16)
            new = LifeTime(typeid, address, size, varsize, current)
            unknown_lifetime[address] = new
            current += size
    for unknown in unknown_lifetime.itervalues():
        unknown.death = current
        callback(unknown)

def collect_all(f):
    all = []
    def callback(obj):
        all.append(obj)
    parse_file(f, callback)
    return all