footprint.py revision e2512892
1e2512892SShuo Chen#!/usr/bin/python
2e2512892SShuo Chen
3e2512892SShuo Chenfrom collections import OrderedDict
4e2512892SShuo Chenimport re, sys
5e2512892SShuo Chen
6e2512892SShuo Chenslabs = {}
7e2512892SShuo Chen
8e2512892SShuo Chensections = []
9e2512892SShuo Chen
10e2512892SShuo Chensection = None
11e2512892SShuo Chen
12e2512892SShuo Chenfor line in sys.stdin:
13e2512892SShuo Chen    m = re.match('===== (.*) =====', line)
14e2512892SShuo Chen    if m:
15e2512892SShuo Chen        section_name = m.group(1)
16e2512892SShuo Chen        # print section_name
17e2512892SShuo Chen        if (section):
18e2512892SShuo Chen            sections.append(section)
19e2512892SShuo Chen        section = (section_name, OrderedDict(), OrderedDict())
20e2512892SShuo Chen        meminfo = True
21e2512892SShuo Chen        continue
22e2512892SShuo Chen    if re.match('slabinfo -', line):
23e2512892SShuo Chen        meminfo = False
24e2512892SShuo Chen        continue
25e2512892SShuo Chen    if meminfo:
26e2512892SShuo Chen        m = re.match('(.*): *(\\d+) kB', line)
27e2512892SShuo Chen        if m:
28e2512892SShuo Chen            section[1][m.group(1)] = int(m.group(2))
29e2512892SShuo Chen    else:
30e2512892SShuo Chen        if line[0] == '#':
31e2512892SShuo Chen            continue
32e2512892SShuo Chen        (slab, active, total, objsize) = line.split()[:4]
33e2512892SShuo Chen        slabs[slab] = int(objsize)
34e2512892SShuo Chen        section[2][slab] = int(active)
35e2512892SShuo Chen
36e2512892SShuo Chen
37e2512892SShuo Chensections.append(section)
38e2512892SShuo Chen
39e2512892SShuo Chenfor i in range(1, len(sections)):
40e2512892SShuo Chen    print '=====', sections[i][0]
41e2512892SShuo Chen    meminfo = sections[i][1]
42e2512892SShuo Chen    old = sections[i-1][1]
43e2512892SShuo Chen    for key in meminfo:
44e2512892SShuo Chen        diff = meminfo[key]-old[key]
45e2512892SShuo Chen        if diff:
46e2512892SShuo Chen            print key, diff
47e2512892SShuo Chen
48e2512892SShuo Chen    print '-----'
49e2512892SShuo Chen    slab = sections[i][2]
50e2512892SShuo Chen    old = sections[i-1][2]
51e2512892SShuo Chen    for key in slab:
52e2512892SShuo Chen        diff = slab[key]-old[key]
53e2512892SShuo Chen        if diff:
54e2512892SShuo Chen            print key, slabs[key], diff
55e2512892SShuo Chen
56