-
Notifications
You must be signed in to change notification settings - Fork 2
/
memstats
executable file
·40 lines (35 loc) · 1.04 KB
/
memstats
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
#!/usr/bin/env python
import os, array, sys
import pagemap
kpcount = pagemap.kpagecount("")
amap = pagemap.archmap("")
krange = kpcount.counts(amap.pfn_offset(), kpcount.pages())
def measure(pid):
vss, rss, uss, pss = 0, 0, 0, 0
pmap = pagemap.processmap(pid)
for m in pmap.maps():
vss += m.end - m.start
r = pmap.range(m.start, m.end)
for idx in range(len(r)):
pfn = r[idx] & ((1 << 55) - 1)
if pfn == 0:
continue
rss += 4096
# skip framebuffer mappings
if pfn <= kpcount.pages():
c = krange[int(pfn) - amap.pfn_offset()]
else:
c = 0
if c == 1:
uss += 4096
if c:
pss += int(4096.0 / c)
return vss, rss, pss, uss
for pid in sys.argv[1:]:
vss, rss, pss, uss = measure(int(pid))
print "%8d: VSS % 7dk RSS % 7dk PSS % 7dk USS % 7dk" % (
int(pid),
vss / 1024,
rss / 1024,
pss / 1024,
uss / 1024)