File iotop-hide-swapin-unavailable.patch of Package iotop.38532

commit 9c49d594a5ddea14dcb30f0f2b7dc67018767295
Author: Paul Wise <pabs3@bonedaddy.net>
Date:   Tue Feb 1 11:31:15 2022 +0800

    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>

Index: iotop-0.6/iotop/ui.py
===================================================================
--- iotop-0.6.orig/iotop/ui.py
+++ iotop-0.6/iotop/ui.py
@@ -184,6 +184,12 @@ class IOTopUI(object):
         self.sorting_key += delta
         self.sorting_key = max(0, self.sorting_key)
         self.sorting_key = min(len(IOTopUI.sorting_keys) - 1, self.sorting_key)
+        if not self.has_swapin_io:
+            if self.sorting_key in (5, 6):
+                if delta <= 0:
+                    self.sorting_key = 4
+                elif delta > 0:
+                    self.sorting_key = 7
         if orig_sorting_key != self.sorting_key:
             self.sorting_reverse = IOTopUI.sorting_keys[self.sorting_key][1]
 
@@ -377,14 +383,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)
@@ -439,6 +453,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
@@ -462,6 +477,8 @@ class IOTopUI(object):
                            self.width)
             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:
openSUSE Build Service is sponsored by