summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Chazarain <guichaz@gmail.com>2013-05-27 01:26:28 +0200
committerGuillaume Chazarain <guichaz@gmail.com>2013-05-27 01:26:28 +0200
commit65625d1b5cee169247e9479445cfa497c10bc006 (patch)
tree4a4061127742230a31d300e25fb09992a4e6e161
parent59e2537794d91c1375d391293f8fd89ca8b794a8 (diff)
downloadiotop-65625d1b5cee169247e9479445cfa497c10bc006.tar.gz
Make pep8 happy.
-rw-r--r--iotop/data.py21
-rw-r--r--iotop/genetlink.py41
-rw-r--r--iotop/ioprio.py17
-rw-r--r--iotop/netlink.py96
-rw-r--r--iotop/ui.py73
-rw-r--r--iotop/vmstat.py2
-rwxr-xr-xsetup.py5
7 files changed, 169 insertions, 86 deletions
diff --git a/iotop/data.py b/iotop/data.py
index 25b659e..8a6188e 100644
--- a/iotop/data.py
+++ b/iotop/data.py
@@ -58,10 +58,12 @@ from iotop import ioprio, vmstat
from iotop.netlink import Connection, NETLINK_GENERIC, U32Attr, NLM_F_REQUEST
from iotop.genetlink import Controller, GeNlMessage
+
class DumpableObject(object):
- """Base class for all objects that allows easy introspection when printed"""
+ """Base class for objects that allows easy introspection when printed"""
def __repr__(self):
- return '%s: %s>' % (str(type(self))[:-1], pprint.pformat(self.__dict__))
+ return '%s: %s>' % (str(type(self))[:-1],
+ pprint.pformat(self.__dict__))
#
@@ -127,6 +129,7 @@ TASKSTATS_TYPE_AGGR_PID = 4
TASKSTATS_TYPE_PID = 1
TASKSTATS_TYPE_STATS = 3
+
class TaskStatsNetlink(object):
# Keep in sync with format_stats() and pinfo.did_some_io()
@@ -168,6 +171,7 @@ class TaskStatsNetlink(object):
# PIDs manipulations
#
+
def find_uids(options):
"""Build options.uids from options.users by resolving usernames to UIDs"""
options.uids = []
@@ -208,6 +212,7 @@ def safe_utf8_decode(s):
except AttributeError:
return s
+
class ThreadInfo(DumpableObject):
"""Stats for a single thread"""
def __init__(self, tid, taskstats_connection):
@@ -239,7 +244,7 @@ class ProcessInfo(DumpableObject):
self.pid = pid
self.uid = None
self.user = None
- self.threads = {} # {tid: ThreadInfo}
+ self.threads = {} # {tid: ThreadInfo}
self.stats_delta = Stats.build_all_zero()
self.stats_accum = Stats.build_all_zero()
self.stats_accum_timestamp = time.time()
@@ -259,9 +264,9 @@ class ProcessInfo(DumpableObject):
def get_uid(self):
if self.uid:
return self.uid
- # uid in (None, 0) means either we don't know the UID yet or the process
- # runs as root so it can change its UID. In both cases it means we have
- # to find out its current UID.
+ # uid in (None, 0) means either we don't know the UID yet or the
+ # process runs as root so it can change its UID. In both cases it means
+ # we have to find out its current UID.
try:
uid = os.stat('/proc/%d' % self.pid)[stat.ST_UID]
except OSError:
@@ -361,6 +366,7 @@ class ProcessInfo(DumpableObject):
return True
+
class ProcessList(DumpableObject):
def __init__(self, taskstats_connection, options):
# {pid: ProcessInfo}
@@ -396,7 +402,8 @@ class ProcessList(DumpableObject):
for tgid in tgids:
if '0' <= tgid[0] <= '9':
try:
- tids.extend(map(int, os.listdir('/proc/' + tgid + '/task')))
+ tids.extend(map(int,
+ os.listdir('/proc/' + tgid + '/task')))
except OSError:
# The PID went away
pass
diff --git a/iotop/genetlink.py b/iotop/genetlink.py
index 66f3d02..47093c1 100644
--- a/iotop/genetlink.py
+++ b/iotop/genetlink.py
@@ -7,36 +7,41 @@ GPLv2+; See copying for details.
'''
import struct
-from iotop.netlink import NLM_F_REQUEST, NLMSG_MIN_TYPE, Message, parse_attributes
+from iotop.netlink import NLM_F_REQUEST, NLMSG_MIN_TYPE, Message
+from iotop.netlink import parse_attributes
from iotop.netlink import NulStrAttr, Connection, NETLINK_GENERIC
-CTRL_CMD_UNSPEC = 0
-CTRL_CMD_NEWFAMILY = 1
-CTRL_CMD_DELFAMILY = 2
-CTRL_CMD_GETFAMILY = 3
-CTRL_CMD_NEWOPS = 4
-CTRL_CMD_DELOPS = 5
-CTRL_CMD_GETOPS = 6
+CTRL_CMD_UNSPEC = 0
+CTRL_CMD_NEWFAMILY = 1
+CTRL_CMD_DELFAMILY = 2
+CTRL_CMD_GETFAMILY = 3
+CTRL_CMD_NEWOPS = 4
+CTRL_CMD_DELOPS = 5
+CTRL_CMD_GETOPS = 6
-CTRL_ATTR_UNSPEC = 0
-CTRL_ATTR_FAMILY_ID = 1
+CTRL_ATTR_UNSPEC = 0
+CTRL_ATTR_FAMILY_ID = 1
CTRL_ATTR_FAMILY_NAME = 2
-CTRL_ATTR_VERSION = 3
-CTRL_ATTR_HDRSIZE = 4
-CTRL_ATTR_MAXATTR = 5
-CTRL_ATTR_OPS = 6
+CTRL_ATTR_VERSION = 3
+CTRL_ATTR_HDRSIZE = 4
+CTRL_ATTR_MAXATTR = 5
+CTRL_ATTR_OPS = 6
+
class GenlHdr:
- def __init__(self, cmd, version = 0):
+ def __init__(self, cmd, version=0):
self.cmd = cmd
self.version = version
+
def _dump(self):
return struct.pack("BBxx", self.cmd, self.version)
+
def _genl_hdr_parse(data):
return GenlHdr(*struct.unpack("BBxx", data))
-GENL_ID_CTRL = NLMSG_MIN_TYPE
+GENL_ID_CTRL = NLMSG_MIN_TYPE
+
class GeNlMessage(Message):
def __init__(self, family, cmd, attrs=[], flags=0):
@@ -44,7 +49,7 @@ class GeNlMessage(Message):
self.attrs = attrs
self.family = family
Message.__init__(self, family, flags=flags,
- payload=[GenlHdr(self.cmd)]+attrs)
+ payload=[GenlHdr(self.cmd)] + attrs)
@staticmethod
def recv(conn):
@@ -58,9 +63,11 @@ class GeNlMessage(Message):
return genlmsg
+
class Controller:
def __init__(self, conn):
self.conn = conn
+
def get_family_id(self, family):
a = NulStrAttr(CTRL_ATTR_FAMILY_NAME, family)
m = GeNlMessage(GENL_ID_CTRL, CTRL_CMD_GETFAMILY,
diff --git a/iotop/ioprio.py b/iotop/ioprio.py
index 85957fd..07d7c52 100644
--- a/iotop/ioprio.py
+++ b/iotop/ioprio.py
@@ -54,6 +54,7 @@ IOPRIO_SET_ARCH_SYSCALL = [
('x86_64*', '64bit', 251),
]
+
def find_ioprio_syscall_number(syscall_list):
arch = os.uname()[4]
bits = platform.architecture()[0]
@@ -63,6 +64,7 @@ def find_ioprio_syscall_number(syscall_list):
fnmatch.fnmatch(bits, candidate_bits):
return syscall_nr
+
class IoprioSetError(Exception):
def __init__(self, err):
try:
@@ -86,6 +88,7 @@ IOPRIO_WHO_PROCESS = 1
IOPRIO_CLASS_SHIFT = 13
IOPRIO_PRIO_MASK = (1 << IOPRIO_CLASS_SHIFT) - 1
+
def ioprio_value(ioprio_class, ioprio_data):
try:
ioprio_class = PRIORITY_CLASSES.index(ioprio_class)
@@ -93,18 +96,22 @@ def ioprio_value(ioprio_class, ioprio_data):
ioprio_class = PRIORITY_CLASSES.index(None)
return (ioprio_class << IOPRIO_CLASS_SHIFT) | ioprio_data
+
def ioprio_class(ioprio):
return PRIORITY_CLASSES[ioprio >> IOPRIO_CLASS_SHIFT]
+
def ioprio_data(ioprio):
return ioprio & IOPRIO_PRIO_MASK
sched_getscheduler = ctypes_handle.sched_getscheduler
-SCHED_OTHER, SCHED_FIFO, SCHED_RR, SCHED_BATCH, SCHED_ISO, SCHED_IDLE = range(6)
+SCHED_OTHER, SCHED_FIFO, SCHED_RR, SCHED_BATCH, SCHED_ISO, SCHED_IDLE = \
+ range(6)
getpriority = ctypes_handle.getpriority
PRIO_PROCESS = 0
+
def get_ioprio_from_sched(pid):
scheduler = sched_getscheduler(pid)
nice = getpriority(PRIO_PROCESS, pid)
@@ -117,6 +124,7 @@ def get_ioprio_from_sched(pid):
else:
return 'be/%d' % ioprio_nice
+
def get(pid):
if __NR_ioprio_get is None:
return '?sys'
@@ -132,6 +140,7 @@ def get(pid):
return prio_class
return '%s/%d' % (prio_class, ioprio_data(ioprio))
+
def set_ioprio(which, who, ioprio_class, ioprio_data):
if __NR_ioprio_set is None:
raise IoprioSetError('No ioprio_set syscall found')
@@ -142,9 +151,11 @@ def set_ioprio(which, who, ioprio_class, ioprio_data):
try:
err = ctypes.get_errno()
except AttributeError:
- err = 'Unknown error (errno support not available before Python2.6)'
+ err = \
+ 'Unknown error (errno support not available before Python2.6)'
raise IoprioSetError(err)
+
def sort_key(key):
if key[0] == '?':
return -ord(key[1])
@@ -161,6 +172,7 @@ def sort_key(key):
return (1 << (shift * IOPRIO_CLASS_SHIFT)) + prio
+
def to_class_and_data(ioprio_str):
if '/' in ioprio_str:
split = ioprio_str.split('/')
@@ -177,4 +189,3 @@ if __name__ == '__main__':
pid = os.getpid()
print('pid:', pid)
print('ioprio:', get(pid))
-
diff --git a/iotop/netlink.py b/iotop/netlink.py
index bd41348..3154b70 100644
--- a/iotop/netlink.py
+++ b/iotop/netlink.py
@@ -15,24 +15,32 @@ try:
_dummysock = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, 0)
_dummysock.bind((0, 0))
del _dummysock
+
def _nl_bind(descriptor, addr):
descriptor.bind(addr)
+
def _nl_getsockname(descriptor):
return descriptor.getsockname()
+
def _nl_send(descriptor, msg):
descriptor.send(msg)
+
def _nl_recv(descriptor, bufs=16384):
return descriptor.recvfrom(bufs)
except socket.error:
# or fall back to the _netlink C module
try:
import _netlink
+
def _nl_bind(descriptor, addr):
_netlink.bind(descriptor.fileno(), addr[1])
+
def _nl_getsockname(descriptor):
return _netlink.getsockname(descriptor.fileno())
+
def _nl_send(descriptor, msg):
_netlink.send(descriptor.fileno(), msg)
+
def _nl_recv(descriptor, bufs=16384):
return _netlink.recvfrom(descriptor.fileno(), bufs)
except ImportError:
@@ -55,14 +63,14 @@ except socket.error:
def _nl_getsockname(descriptor):
addr = SOCKADDR_NL(0, 0, 0, 0)
- len = ctypes.c_int(ctypes.sizeof(addr));
+ len = ctypes.c_int(ctypes.sizeof(addr))
libc.getsockname(descriptor.fileno(),
ctypes.pointer(addr),
ctypes.pointer(len))
- return addr.nl_pid, addr.nl_groups;
+ return addr.nl_pid, addr.nl_groups
def _nl_send(descriptor, msg):
- return libc.send(descriptor.fileno(), msg, len(msg), 0);
+ return libc.send(descriptor.fileno(), msg, len(msg), 0)
def _nl_recv(descriptor, bufs=16384):
addr = SOCKADDR_NL(0, 0, 0, 0)
@@ -78,18 +86,19 @@ except socket.error:
# flags
-NLM_F_REQUEST = 1
-NLM_F_MULTI = 2
-NLM_F_ACK = 4
-NLM_F_ECHO = 8
+NLM_F_REQUEST = 1
+NLM_F_MULTI = 2
+NLM_F_ACK = 4
+NLM_F_ECHO = 8
# types
-NLMSG_NOOP = 1
-NLMSG_ERROR = 2
-NLMSG_DONE = 3
-NLMSG_OVERRUN = 4
+NLMSG_NOOP = 1
+NLMSG_ERROR = 2
+NLMSG_DONE = 3
+NLMSG_OVERRUN = 4
NLMSG_MIN_TYPE = 0x10
+
class Attr:
def __init__(self, attr_type, data, *values):
self.type = attr_type
@@ -99,9 +108,9 @@ class Attr:
self.data = data
def _dump(self):
- hdr = struct.pack("HH", len(self.data)+4, self.type)
+ hdr = struct.pack("HH", len(self.data) + 4, self.type)
length = len(self.data)
- pad = ((length + 4 - 1) & ~3 ) - length
+ pad = ((length + 4 - 1) & ~3) - length
return hdr + self.data + b'\0' * pad
def __repr__(self):
@@ -109,35 +118,47 @@ class Attr:
def u16(self):
return struct.unpack('H', self.data)[0]
+
def s16(self):
return struct.unpack('h', self.data)[0]
+
def u32(self):
return struct.unpack('I', self.data)[0]
+
def s32(self):
return struct.unpack('i', self.data)[0]
+
def str(self):
return self.data
+
def nulstr(self):
return self.data.split('\0')[0]
+
def nested(self):
return parse_attributes(self.data)
+
class StrAttr(Attr):
def __init__(self, attr_type, data):
Attr.__init__(self, attr_type, "%ds" % len(data), data.encode('utf-8'))
+
class NulStrAttr(Attr):
def __init__(self, attr_type, data):
- Attr.__init__(self, attr_type, "%dsB" % len(data), data.encode('utf-8'), 0)
+ Attr.__init__(self,
+ attr_type, "%dsB" % len(data), data.encode('utf-8'), 0)
+
class U32Attr(Attr):
def __init__(self, attr_type, val):
Attr.__init__(self, attr_type, "I", val)
+
class U8Attr(Attr):
def __init__(self, attr_type, val):
Attr.__init__(self, attr_type, "B", val)
+
class Nested(Attr):
def __init__(self, attr_type, attrs):
self.attrs = attrs
@@ -149,26 +170,27 @@ class Nested(Attr):
contents.append(attr._dump())
contents = ''.join(contents)
length = len(contents)
- hdr = struct.pack("HH", length+4, self.type)
+ hdr = struct.pack("HH", length + 4, self.type)
return hdr + contents
-NETLINK_ROUTE = 0
-NETLINK_UNUSED = 1
-NETLINK_USERSOCK = 2
-NETLINK_FIREWALL = 3
-NETLINK_INET_DIAG = 4
-NETLINK_NFLOG = 5
-NETLINK_XFRM = 6
-NETLINK_SELINUX = 7
-NETLINK_ISCSI = 8
-NETLINK_AUDIT = 9
-NETLINK_FIB_LOOKUP = 10
-NETLINK_CONNECTOR = 11
-NETLINK_NETFILTER = 12
-NETLINK_IP6_FW = 13
-NETLINK_DNRTMSG = 14
+NETLINK_ROUTE = 0
+NETLINK_UNUSED = 1
+NETLINK_USERSOCK = 2
+NETLINK_FIREWALL = 3
+NETLINK_INET_DIAG = 4
+NETLINK_NFLOG = 5
+NETLINK_XFRM = 6
+NETLINK_SELINUX = 7
+NETLINK_ISCSI = 8
+NETLINK_AUDIT = 9
+NETLINK_FIB_LOOKUP = 10
+NETLINK_CONNECTOR = 11
+NETLINK_NETFILTER = 12
+NETLINK_IP6_FW = 13
+NETLINK_DNRTMSG = 14
NETLINK_KOBJECT_UEVENT = 15
-NETLINK_GENERIC = 16
+NETLINK_GENERIC = 16
+
class Message:
def __init__(self, msg_type, flags=0, seq=-1, payload=None):
@@ -192,7 +214,7 @@ class Message:
self.pid = conn.pid
length = len(self.payload)
- hdr = struct.pack("IHHII", length + 4*4, self.type,
+ hdr = struct.pack("IHHII", length + 4 * 4, self.type,
self.flags, self.seq, self.pid)
conn.send(hdr + self.payload)
@@ -200,7 +222,9 @@ class Message:
return '<netlink.Message type=%d, pid=%d, seq=%d, flags=0x%x "%s">' % (
self.type, self.pid, self.seq, self.flags, repr(self.payload))
+
class Connection:
+
def __init__(self, nltype, groups=0, unexpected_msg_handler=None):
self.descriptor = socket.socket(socket.AF_NETLINK,
socket.SOCK_RAW, nltype)
@@ -210,8 +234,10 @@ class Connection:
self.pid, self.groups = _nl_getsockname(self.descriptor)
self._seq = 0
self.unexpected = unexpected_msg_handler
+
def send(self, msg):
_nl_send(self.descriptor, msg)
+
def recv(self):
contents, (nlpid, nlgrps) = _nl_recv(self.descriptor)
# XXX: python doesn't give us message flags, check
@@ -224,19 +250,21 @@ class Connection:
errno = -struct.unpack("i", msg.payload[:4])[0]
if errno != 0:
err = OSError("Netlink error: %s (%d)" % (
- os.strerror(errno), errno))
+ os.strerror(errno), errno))
err.errno = errno
raise err
return msg
+
def seq(self):
self._seq += 1
return self._seq
+
def parse_attributes(data):
attrs = {}
while len(data):
attr_len, attr_type = struct.unpack("HH", data[:4])
attrs[attr_type] = Attr(attr_type, data[4:attr_len])
- attr_len = ((attr_len + 4 - 1) & ~3 )
+ attr_len = ((attr_len + 4 - 1) & ~3)
data = data[attr_len:]
return attrs
diff --git a/iotop/ui.py b/iotop/ui.py
index e033c92..5ea22bc 100644
--- a/iotop/ui.py
+++ b/iotop/ui.py
@@ -42,6 +42,7 @@ from iotop.ioprio import IoprioSetError
UNITS = ['B', 'K', 'M', 'G', 'T', 'P', 'E']
+
def human_size(size):
if size > 0:
sign = ''
@@ -52,20 +53,24 @@ def human_size(size):
return '0.00 B'
expo = int(math.log(size / 2, 2) / 10)
- return '%s%.2f %s' % (sign, (float(size) / (1 << (10 * expo))), UNITS[expo])
+ return '%s%.2f %s' % (
+ sign, (float(size) / (1 << (10 * expo))), UNITS[expo])
+
def format_size(options, bytes):
if options.kilobytes:
return '%.2f K' % (bytes / 1024.0)
return human_size(bytes)
+
def format_bandwidth(options, size, duration):
return format_size(options, size and float(size) / duration) + '/s'
+
def format_stats(options, process, duration):
# Keep in sync with TaskStatsNetlink.members_offsets and
# IOTopUI.get_data(self)
- def delay2percent(delay): # delay in ns, duration in s
+ def delay2percent(delay): # delay in ns, duration in s
return '%.2f %%' % min(99.99, delay / (duration * 10000000.0))
if options.accumulated:
stats = process.stats_accum
@@ -74,7 +79,7 @@ def format_stats(options, process, duration):
else:
stats = process.stats_delta
display_format = lambda size, duration: format_bandwidth(
- options, size, duration)
+ options, size, duration)
io_delay = delay2percent(stats.blkio_delay_total)
swapin_delay = delay2percent(stats.swapin_delay_total)
read_bytes = display_format(stats.read_bytes, duration)
@@ -83,6 +88,7 @@ def format_stats(options, process, duration):
write_bytes = display_format(written_bytes, duration)
return io_delay, swapin_delay, read_bytes, write_bytes
+
def get_max_pid_width():
try:
return len(open('/proc/sys/kernel/pid_max').read().strip())
@@ -97,16 +103,31 @@ MAX_PID_WIDTH = get_max_pid_width()
# UI Exceptions
#
-class CancelInput(Exception): pass
-class InvalidInt(Exception): pass
-class InvalidPid(Exception): pass
-class InvalidTid(Exception): pass
-class InvalidIoprioData(Exception): pass
+
+class CancelInput(Exception):
+ pass
+
+
+class InvalidInt(Exception):
+ pass
+
+
+class InvalidPid(Exception):
+ pass
+
+
+class InvalidTid(Exception):
+ pass
+
+
+class InvalidIoprioData(Exception):
+ pass
#
# The UI
#
+
class IOTopUI(object):
# key, reverse
sorting_keys = [
@@ -147,7 +168,7 @@ class IOTopUI(object):
iterations = 0
poll = select.poll()
if not self.options.batch:
- poll.register(sys.stdin.fileno(), select.POLLIN|select.POLLPRI)
+ poll.register(sys.stdin.fileno(), select.POLLIN | select.POLLPRI)
while self.options.iterations is None or \
iterations < self.options.iterations:
total, actual = self.process_list.refresh_processes()
@@ -204,7 +225,7 @@ class IOTopUI(object):
raise CancelInput()
return default
- def prompt_int(self, prompt, default = None, empty_is_cancel = True):
+ def prompt_int(self, prompt, default=None, empty_is_cancel=True):
inp = self.prompt_str(prompt, default, empty_is_cancel)
try:
return int(inp)
@@ -263,7 +284,8 @@ class IOTopUI(object):
if key in (curses.KEY_LEFT, ord('l')) and selected > 0:
selected -= 1
break
- elif key in (curses.KEY_RIGHT, ord('r')) and selected < set_len:
+ elif (key in (curses.KEY_RIGHT, ord('r')) and
+ selected < set_len):
selected += 1
break
elif key in (curses.KEY_ENTER, ord('\n'), ord('\r')):
@@ -278,10 +300,11 @@ class IOTopUI(object):
classes_ret = ['rt', 'be', 'idle']
if ioprio_class is None:
ioprio_class = 2
- inp = self.prompt_set(prompt, classes_prompt, classes_ret, ioprio_class)
+ inp = self.prompt_set(prompt, classes_prompt,
+ classes_ret, ioprio_class)
return inp
- def prompt_error(self, error = 'Error!'):
+ def prompt_error(self, error='Error!'):
self.win.hline(1, 0, ord(' ') | curses.A_NORMAL, self.width)
self.win.insstr(1, 0, ' %s ' % error, curses.A_REVERSE)
self.win.refresh()
@@ -294,12 +317,15 @@ class IOTopUI(object):
def handle_key(self, key):
def toggle_accumulated():
self.options.accumulated ^= True
+
def toggle_only_io():
self.options.only ^= True
+
def toggle_processes():
self.options.processes ^= True
self.process_list.clear()
self.process_list.refresh_processes()
+
def ionice():
try:
if self.options.processes:
@@ -308,10 +334,10 @@ class IOTopUI(object):
else:
tid = self.prompt_tid()
exec_unit = ThreadInfo(tid,
- self.process_list.taskstats_connection)
+ self.process_list.taskstats_connection)
ioprio_value = exec_unit.get_ioprio()
(ioprio_class, ioprio_data) = \
- ioprio.to_class_and_data(ioprio_value)
+ ioprio.to_class_and_data(ioprio_value)
ioprio_class = self.prompt_class(ioprio_class)
if ioprio_class == 'idle':
ioprio_data = 0
@@ -469,7 +495,8 @@ class IOTopUI(object):
else:
status_msg = ('CONFIG_TASK_DELAY_ACCT not enabled in kernel, '
'cannot determine SWAPIN and IO %')
- num_lines = min(len(lines), self.height - 2 - int(bool(status_msg)))
+ num_lines = min(len(lines),
+ self.height - 2 - int(bool(status_msg)))
for i in range(num_lines):
try:
def print_line(line):
@@ -487,6 +514,7 @@ class IOTopUI(object):
curses.A_BOLD)
self.win.refresh()
+
def run_iotop_window(win, options):
if options.batch:
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
@@ -500,6 +528,7 @@ def run_iotop_window(win, options):
ui = IOTopUI(win, process_list, options)
ui.run()
+
def run_iotop(options):
try:
if options.batch:
@@ -525,6 +554,7 @@ Please do not file bugs on iotop about this.''', file=sys.stderr)
# Profiling
#
+
def _profile(continuation):
prof_file = 'iotop.prof'
try:
@@ -555,14 +585,15 @@ USAGE = '''%s [OPTIONS]
DISK READ and DISK WRITE are the block I/O bandwidth used during the sampling
period. SWAPIN and IO are the percentages of time the thread spent respectively
-while swapping in and waiting on I/O more generally. PRIO is the I/O priority at
-which the thread is running (set using the ionice command).
+while swapping in and waiting on I/O more generally. PRIO is the I/O priority
+at which the thread is running (set using the ionice command).
Controls: left and right arrows to change the sorting column, r to invert the
sorting order, o to toggle the --only option, p to toggle the --processes
option, a to toggle the --accumulated option, i to change I/O priority, q to
quit, any other key to force a refresh.''' % sys.argv[0]
+
def main():
try:
locale.setlocale(locale.LC_ALL, '')
@@ -582,8 +613,9 @@ def main():
metavar='SEC', default=1)
parser.add_option('-p', '--pid', type='int', dest='pids', action='append',
help='processes/threads to monitor [all]', metavar='PID')
- parser.add_option('-u', '--user', type='str', dest='users', action='append',
- help='users to monitor [all]', metavar='USER')
+ parser.add_option('-u', '--user', type='str', dest='users',
+ action='append', help='users to monitor [all]',
+ metavar='USER')
parser.add_option('-P', '--processes', action='store_true',
dest='processes', default=False,
help='only show processes, not all threads')
@@ -618,4 +650,3 @@ def main():
_profile(safe_main_loop)
else:
main_loop()
-
diff --git a/iotop/vmstat.py b/iotop/vmstat.py
index 4a99a86..f3c8977 100644
--- a/iotop/vmstat.py
+++ b/iotop/vmstat.py
@@ -16,6 +16,7 @@
#
# Copyright (c) 2007 Guillaume Chazarain <guichaz@gmail.com>
+
class VmStat(object):
def __init__(self):
self.vmstat_file = open('/proc/vmstat')
@@ -43,4 +44,3 @@ class VmStat(object):
delta = now[0] - self.vmstat[0], now[1] - self.vmstat[1]
self.vmstat = now
return delta
-
diff --git a/setup.py b/setup.py
index cd639ca..7150102 100755
--- a/setup.py
+++ b/setup.py
@@ -14,9 +14,8 @@ if hasattr(distutils_install, 'INSTALL_SCHEMES'):
setup(name='iotop',
version=VERSION,
description='Per process I/O bandwidth monitor',
- long_description=
-'''Iotop is a Python program with a top like UI used to show of behalf of which
-process is the I/O going on.''',
+ long_description='''Iotop is a Python program with a top like UI used to
+show of behalf of which process is the I/O going on.''',
author='Guillaume Chazarain',
author_email='guichaz@gmail.com',
url='http://guichaz.free.fr/iotop',