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:
parent
4cb161ea45
commit
0279ad465a
2 changed files with 12 additions and 9 deletions
18
smem
18
smem
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
import re, os, sys, pwd, grp, optparse, errno, tarfile
|
import re, os, sys, pwd, grp, optparse, errno, tarfile
|
||||||
|
|
||||||
|
warned = False
|
||||||
|
|
||||||
class procdata(object):
|
class procdata(object):
|
||||||
def __init__(self, source):
|
def __init__(self, source):
|
||||||
self._ucache = {}
|
self._ucache = {}
|
||||||
|
|
@ -128,11 +130,15 @@ def kernelsize():
|
||||||
return _kernelsize
|
return _kernelsize
|
||||||
|
|
||||||
def pidmaps(pid):
|
def pidmaps(pid):
|
||||||
|
global warned
|
||||||
maps = {}
|
maps = {}
|
||||||
start = None
|
start = None
|
||||||
|
seen = False
|
||||||
for l in src.mapdata(pid):
|
for l in src.mapdata(pid):
|
||||||
f = l.split()
|
f = l.split()
|
||||||
if f[-1] == 'kB':
|
if f[-1] == 'kB':
|
||||||
|
if f[0].startswith('Pss'):
|
||||||
|
seen = True
|
||||||
maps[start][f[0][:-1].lower()] = int(f[1])
|
maps[start][f[0][:-1].lower()] = int(f[1])
|
||||||
else:
|
else:
|
||||||
start, end = f[0].split('-')
|
start, end = f[0].split('-')
|
||||||
|
|
@ -144,6 +150,10 @@ def pidmaps(pid):
|
||||||
offset=int(f[2], 16),
|
offset=int(f[2], 16),
|
||||||
device=f[3], inode=f[4], name=name)
|
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:
|
if options.mapfilter:
|
||||||
f = {}
|
f = {}
|
||||||
for m in maps:
|
for m in maps:
|
||||||
|
|
@ -584,12 +594,6 @@ def showbar(l, columns, sort):
|
||||||
pylab.legend([p[0] for p in pl], key)
|
pylab.legend([p[0] for p in pl], key)
|
||||||
pylab.show()
|
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 = optparse.OptionParser("%prog [options]")
|
||||||
parser.add_option("-H", "--no-header", action="store_true",
|
parser.add_option("-H", "--no-header", action="store_true",
|
||||||
|
|
@ -648,8 +652,6 @@ try:
|
||||||
except:
|
except:
|
||||||
src = procdata(options.source)
|
src = procdata(options.source)
|
||||||
|
|
||||||
kernel_version_check()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if options.mappings:
|
if options.mappings:
|
||||||
showmaps()
|
showmaps()
|
||||||
|
|
|
||||||
3
smem.8
3
smem.8
|
|
@ -144,7 +144,8 @@ Show pie graph.
|
||||||
\fBsmem\fP requires:
|
\fBsmem\fP requires:
|
||||||
|
|
||||||
.IP \(bu 3
|
.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
|
.IP \(bu
|
||||||
Python 2.x (at least 2.4 or so).
|
Python 2.x (at least 2.4 or so).
|
||||||
.IP \(bu
|
.IP \(bu
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue