From 3f2e2a009195056077a4669d0bf0a29f28a9a195 Mon Sep 17 00:00:00 2001 From: Yaolong Huang Date: Thu, 4 Sep 2014 12:45:10 +0800 Subject: [PATCH 1/2] Fix the disk_io_counter bug in kernel 2.6 to 2.6.25 In kernel from 2.6 to 2.6.25, /proc/diskstats for subpartitions in a disk has only 7 fields. Check this in http://www.mjmwired.net/kernel/Documentation/iostats.txt --- psutil/_pslinux.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 66fea9126..107d17021 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -638,8 +638,13 @@ def disk_io_counters(): f.close() for line in lines: # http://www.mjmwired.net/kernel/Documentation/iostats.txt - _, _, name, reads, _, rbytes, rtime, writes, _, wbytes, wtime = \ - line.split()[:11] + fields = line.split() + if len(fields) > 7: + _, _, name, reads, _, rbytes, rtime, writes, _, wbytes, wtime = \ + fields[:11] + else: # from kernel 2.6 to 2.6.25 + _, _, name, reads, rbytes, writes, wbytes = fields + rtime, wtime = 0, 0 if name in partitions: rbytes = int(rbytes) * SECTOR_SIZE wbytes = int(wbytes) * SECTOR_SIZE From 1cb3605cbecc403b5be80ebac8181cc6016a3c35 Mon Sep 17 00:00:00 2001 From: Yaolong Huang Date: Thu, 4 Sep 2014 12:53:19 +0800 Subject: [PATCH 2/2] Fix the comment space problem. --- psutil/_pslinux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 107d17021..0b5907fde 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -642,7 +642,7 @@ def disk_io_counters(): if len(fields) > 7: _, _, name, reads, _, rbytes, rtime, writes, _, wbytes, wtime = \ fields[:11] - else: # from kernel 2.6 to 2.6.25 + else: # from kernel 2.6 to 2.6.25 _, _, name, reads, rbytes, writes, wbytes = fields rtime, wtime = 0, 0 if name in partitions: