footprint.py revision 246b2f80
1246b2f80SShuo Chen#!/usr/bin/python3 2246b2f80SShuo Chen 3246b2f80SShuo Chen# Read and analyse stdout of footprint.cc 4246b2f80SShuo Chen# $ sudo ./footprint 100000 | ./footprint.py 5e2512892SShuo Chen 6e2512892SShuo Chenfrom collections import OrderedDict 7e2512892SShuo Chenimport re, sys 8e2512892SShuo Chen 9e2512892SShuo Chenslabs = {} 10e2512892SShuo Chen 11e2512892SShuo Chensections = [] 12e2512892SShuo Chen 13e2512892SShuo Chensection = None 14e2512892SShuo Chen 15e2512892SShuo Chenfor line in sys.stdin: 16246b2f80SShuo Chen if m := re.match('===== (.*) =====', line): 17e2512892SShuo Chen section_name = m.group(1) 18246b2f80SShuo Chen # print(section_name) 19e2512892SShuo Chen if (section): 20e2512892SShuo Chen sections.append(section) 21e2512892SShuo Chen section = (section_name, OrderedDict(), OrderedDict()) 22e2512892SShuo Chen meminfo = True 23e2512892SShuo Chen continue 24e2512892SShuo Chen if re.match('slabinfo -', line): 25e2512892SShuo Chen meminfo = False 26e2512892SShuo Chen continue 27e2512892SShuo Chen if meminfo: 28246b2f80SShuo Chen if m := re.match('(.*): *(\\d+) kB', line): 29e2512892SShuo Chen section[1][m.group(1)] = int(m.group(2)) 30e2512892SShuo Chen else: 31e2512892SShuo Chen if line[0] == '#': 32e2512892SShuo Chen continue 33e2512892SShuo Chen (slab, active, total, objsize) = line.split()[:4] 34e2512892SShuo Chen slabs[slab] = int(objsize) 35e2512892SShuo Chen section[2][slab] = int(active) 36e2512892SShuo Chen 37e2512892SShuo Chen 38e2512892SShuo Chensections.append(section) 39e2512892SShuo Chen 40e2512892SShuo Chenfor i in range(1, len(sections)): 41246b2f80SShuo Chen print('=====', sections[i][0]) 42e2512892SShuo Chen meminfo = sections[i][1] 43e2512892SShuo Chen old = sections[i-1][1] 44e2512892SShuo Chen for key in meminfo: 45e2512892SShuo Chen diff = meminfo[key]-old[key] 46e2512892SShuo Chen if diff: 47246b2f80SShuo Chen print(key, meminfo[key], diff) 48e2512892SShuo Chen 49246b2f80SShuo Chen print('-----') 50e2512892SShuo Chen slab = sections[i][2] 51e2512892SShuo Chen old = sections[i-1][2] 52e2512892SShuo Chen for key in slab: 53e2512892SShuo Chen diff = slab[key]-old[key] 54e2512892SShuo Chen if diff: 55246b2f80SShuo Chen print(key, slabs[key], slab[key], diff) 56e2512892SShuo Chen 57