1
2
3 __author__ = "Samual M. Rushing"
4
5
6 import sys
7 import types
8 import os
9 import re
10
12 d = {}
13
14 for m in sys.modules.values():
15 for sym in dir(m):
16 o = getattr (m, sym)
17 if type(o) is types.ClassType:
18 d[o] = sys.getrefcount (o)
19
20 pairs = [ (x[1], x[0]) for x in d.items() ]
21 pairs.sort()
22 pairs.reverse()
23 return pairs
24
25
30
31
33 fd = open("/proc/%d/status" % os.getpid(), "r")
34 lines = fd.readlines()
35 fd.close()
36 nvms = 0
37 for line in lines:
38 a = line.split()
39 if a[0] == 'VmData:':
40 assert a[2] == 'kB'
41 nvms = int(a[1])
42 return nvms
43
44 _a1kid = 1
50
51 _vmstat = 0
70
71 vm('STARTUP')
72
73
75 def usage_add(u, id, v):
76 try:
77 u_id = u[id]
78 x = (1 + u_id[0], v+u_id[1])
79
80 except KeyError:
81 x = (1, v)
82 u[id] = x
83
84 fd = open(fname, 'r')
85 vml = re.compile('^#VMSTAT:')
86 usage = {}
87 while 1:
88 l = fd.readline()
89 if l == '':
90 break
91 if vml.match(l):
92 a = l.strip().split()
93 if a[2] != '#':
94 continue
95 id = ' '.join(a[3:])
96 vec = float(a[1])
97 usage_add(usage, id, vec)
98 fd.close()
99 tmp = [ ( -v[1]/float(v[0]), id, v) for (id, v) in usage.items() ]
100 tmp.sort()
101 for (fom, id, v) in tmp[:20]:
102 print id, v
103
104
105 if __name__ == '__main__':
106 vm()
107 print_top_N()
108 vm()
109 print_top_N()
110 vm()
111 tmp = 'adadsadadasd' * 1000
112 vm()
113 tmp = None
114 vm()
115