Commit dacd4007 authored by Kirill Smelkov's avatar Kirill Smelkov

shmtop: .

- order by top users first
- print values in GB, not 512b blocks
parent 1eb58004
#!/usr/bin/python #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2017-2019 Nexedi SA and Contributors.
# Julien Muchembled <jm@nexedi.com>
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""shmtop - show top-like RAM usaege of a tmpfs instance
even hidden files are accounted.
XXX text
"""
mntpt = '/dev/shm'
import errno, os, pwd import errno, os, pwd
os.chdir('/proc') os.chdir('/proc')
z = [] z = []
...@@ -12,7 +40,7 @@ for p in os.listdir('.'): ...@@ -12,7 +40,7 @@ for p in os.listdir('.'):
try: try:
for y in os.listdir(x): for y in os.listdir(x):
y = x + '/' + y y = x + '/' + y
if os.readlink(y).startswith('/dev/shm/'): if os.readlink(y).startswith(mntpt + '/'):
y = os.open(y, 0) y = os.open(y, 0)
try: try:
n += os.fstat(y).st_blocks n += os.fstat(y).st_blocks
...@@ -30,7 +58,17 @@ for p in os.listdir('.'): ...@@ -30,7 +58,17 @@ for p in os.listdir('.'):
raise raise
continue continue
uid = map(int, x['Uid'].split()) uid = map(int, x['Uid'].split())
z.append((pwd.getpwuid(uid[0]).pw_name, x['Name'].strip(), pid, n)) z.append((pwd.getpwuid(uid[0]).pw_name, x['Name'].strip(), pid, n*512))
z.sort(key=lambda x: x[3]) z.sort(key=lambda x: x[3], reverse=True)
from pprint import pprint as pp #from pprint import pprint as pp
pp(z) #pp(z)
GB = 1024.*1024*1024
print("# %s" % mntpt)
rss_total = 0.
for user, name, pid, rss in z:
print '%s (%d,%s)\t%7.1fGB' % (name, pid, user, rss / GB)
rss_total += rss
print("( total:\t%.1fGB )" % (rss_total / GB))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment