From 96e339369f7ee071fe76ae72ad2a7df9df249f84 Mon Sep 17 00:00:00 2001 From: Guillaume Chazarain Date: Sun, 23 Aug 2009 17:20:16 +0200 Subject: [PATCH] Added a heuristic to detect kernels without CONFIG_TASK_DELAY_ACCT --- NEWS | 1 + iotop/data.py | 7 +++++++ iotop/ui.py | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 24bc1f7..ed304d1 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 0.3.2 ~~~~~ o Split long command lines in the middle instead of cutting them at the end. +o Added a heuristic to detect kernels without CONFIG_TASK_DELAY_ACCT 0.3.1 ~~~~~ diff --git a/iotop/data.py b/iotop/data.py index 0c71315..91bea54 100644 --- a/iotop/data.py +++ b/iotop/data.py @@ -56,11 +56,18 @@ class Stats(DumpableObject): ('cancelled_write_bytes', 264) ] + has_blkio_delay_total = False + def __init__(self, task_stats_buffer): for name, offset in Stats.members_offsets: data = task_stats_buffer[offset:offset + 8] setattr(self, name, struct.unpack('Q', data)[0]) + # This is a heuristic to detect if CONFIG_TASK_DELAY_ACCT is enabled in + # the kernel. + if not Stats.has_blkio_delay_total: + Stats.has_blkio_delay_total = self.blkio_delay_total != 0 + def accumulate(self, other_stats, operator=sum): """Returns a new Stats object built from operator(self, other_stats)""" delta_stats = Stats.__new__(Stats) diff --git a/iotop/ui.py b/iotop/ui.py index 093dc8e..41cfd04 100644 --- a/iotop/ui.py +++ b/iotop/ui.py @@ -9,7 +9,7 @@ import struct import sys import time -from iotop.data import find_uids, TaskStatsNetlink, ProcessList +from iotop.data import find_uids, TaskStatsNetlink, ProcessList, Stats from iotop.version import VERSION # @@ -257,7 +257,13 @@ class IOTopUI(object): title = title[:remaining_cols] remaining_cols -= len(title) self.win.addstr(title, attr) - for i in xrange(len(lines)): + if Stats.has_blkio_delay_total: + status_msg = None + else: + status_msg = ('CONFIG_TASK_DELAY_ACCT not enabled in kernel, ' + 'cannot determine IO %') + num_lines = min(len(lines), self.height - 2 - int(bool(status_msg))) + for i in xrange(num_lines): try: self.win.insstr(i + 2, 0, lines[i].encode('utf-8')) except curses.error: @@ -266,6 +272,8 @@ class IOTopUI(object): (value, self.win.getmaxyx(), i, lines[i]) value = str(value).encode('string_escape') raise exc_type, value, traceback + if status_msg: + self.win.insstr(self.height - 1, 0, status_msg, curses.A_BOLD) self.win.refresh() def run_iotop_window(win, options): -- 2.11.4.GIT