summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Wise <pabs3@bonedaddy.net>2022-02-01 11:31:15 +0800
committerPaul Wise <pabs3@bonedaddy.net>2022-02-01 11:31:15 +0800
commit9c49d594a5ddea14dcb30f0f2b7dc67018767295 (patch)
treeac5b7bc587e6f0a88435998a3655ecb39837020f
parent2787b5d5a595c3a4679c5f22f817b24a55d485fe (diff)
downloadiotop-9c49d594a5ddea14dcb30f0f2b7dc67018767295.tar.gz
Automatically hide the SWAPIN/IO columns when they are unavailable
Now that the Linux kernel can enable or disable data collection for them at runtime, showing the columns when collection is disabled is even less useful, since the previous data could still be present in the Linux kernel buffers. Preserve the behaviour of the batch mode though, so that programs parsing its output aren't broken by the changes to the Linux kernel, but they may still be broken when the output changes from ?unavailable? to real data. Since the current sorting keys code makes it hard to dynamically choose which columns are shown or hidden, when the two columns are hidden, just skip over displaying them or using them as sorting keys. Rewrite the data display code to be more flexible wrt column choice though. Suggested-by: Boian Bonev <bbonev@ipacct.com>
-rw-r--r--iotop/ui.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/iotop/ui.py b/iotop/ui.py
index 7ae8bad..77f82c7 100644
--- a/iotop/ui.py
+++ b/iotop/ui.py
@@ -224,6 +224,12 @@ class IOTopUI(object):
new_sorting_key += delta
new_sorting_key = max(0, new_sorting_key)
new_sorting_key = min(len(IOTopUI.sorting_keys) - 1, new_sorting_key)
+ if not self.has_swapin_io:
+ if new_sorting_key in (5, 6):
+ if delta <= 0:
+ new_sorting_key = 4
+ elif delta > 0:
+ new_sorting_key = 7
return new_sorting_key
# I wonder if switching to urwid for the display would be better here
@@ -421,14 +427,22 @@ class IOTopUI(object):
def format(p):
stats = format_stats(self.options, p, self.process_list.duration)
io_delay, swapin_delay, read_bytes, write_bytes = stats
+ format = '%%%dd' % MAX_PID_WIDTH
+ params = p.pid,
+ format += ' %4s'
+ params += p.get_ioprio(),
+ format += ' %-8s'
+ params += p.get_user()[:8],
+ format += ' %11s %11s'
+ params += read_bytes, write_bytes
if self.has_swapin_io:
- delay_stats = '%7s %7s ' % (swapin_delay, io_delay)
- else:
- delay_stats = ' ?unavailable? '
- pid_format = '%%%dd' % MAX_PID_WIDTH
- line = (pid_format + ' %4s %-8s %11s %11s %s') % (
- p.pid, p.get_ioprio(), p.get_user()[:8], read_bytes,
- write_bytes, delay_stats)
+ format += ' %7s %7s'
+ params += swapin_delay, io_delay
+ elif self.options.batch:
+ format += ' %s '
+ params += '?unavailable?',
+ format += ' '
+ line = format % (params)
cmdline = p.get_cmdline()
if not self.options.batch:
remaining_length = self.width - len(line)
@@ -481,6 +495,7 @@ class IOTopUI(object):
# and iotop then uses the sysctl value instead.
if sysctl_task_delayacct() == False:
self.has_swapin_io = False
+ self.adjust_sorting_key(0)
lines = self.get_data()
if self.options.time:
titles = [' TIME'] + titles
@@ -571,6 +586,8 @@ class IOTopUI(object):
pos = 0
remaining_cols = self.width
for i in range(len(titles)):
+ if not self.has_swapin_io and i in (5, 6):
+ continue
attr = curses.A_REVERSE
title = titles[i]
if i == self.sorting_key: