Actively detect PSS support

Rather than checking the kernel version, look for PSS field when
parsing smaps data and issue a warning.

(based on a suggestion by Paul Townsend)
This commit is contained in:
Matt Mackall 2011-08-17 13:49:33 -05:00
commit 0a86063d5b
2 changed files with 12 additions and 9 deletions

18
smem
View file

@ -10,6 +10,8 @@
import re, os, sys, pwd, grp, optparse, errno, tarfile
warned = False
class procdata(object):
def __init__(self, source):
self._ucache = {}
@ -128,11 +130,15 @@ def kernelsize():
return _kernelsize
def pidmaps(pid):
global warned
maps = {}
start = None
seen = False
for l in src.mapdata(pid):
f = l.split()
if f[-1] == 'kB':
if f[0].startswith('Pss'):
seen = True
maps[start][f[0][:-1].lower()] = int(f[1])
else:
start, end = f[0].split('-')
@ -144,6 +150,10 @@ def pidmaps(pid):
offset=int(f[2], 16),
device=f[3], inode=f[4], name=name)
if not seen and not warned:
sys.stderr.write('warning: kernel does not appear to support PSS measurement\n')
warned = True
if options.mapfilter:
f = {}
for m in maps:
@ -584,12 +594,6 @@ def showbar(l, columns, sort):
pylab.legend([p[0] for p in pl], key)
pylab.show()
def kernel_version_check():
kernel_release = src.version().split()[2].split('-')[0]
if kernel_release < "2.6.27":
name = os.path.basename(sys.argv[0])
sys.stderr.write(name + " requires a kernel >= 2.6.27\n")
sys.exit(-1)
parser = optparse.OptionParser("%prog [options]")
parser.add_option("-H", "--no-header", action="store_true",
@ -648,8 +652,6 @@ try:
except:
src = procdata(options.source)
kernel_version_check()
try:
if options.mappings:
showmaps()

3
smem.8
View file

@ -144,7 +144,8 @@ Show pie graph.
\fBsmem\fP requires:
.IP \(bu 3
Linux kernel 2.6.27 or newer.
Linux kernel providing 'Pss' metric in /proc/<pid>/smaps (generally
2.6.27 or newer).
.IP \(bu
Python 2.x (at least 2.4 or so).
.IP \(bu