python-psutil/pr_1364.patch

32 lines
1.5 KiB
Diff
Raw Normal View History

From 6688d5fca0f5d19ff7741b2d1585882c4663541b Mon Sep 17 00:00:00 2001
From: Jelle van der Waa <jelle@vdwaa.nl>
Date: Sun, 18 Nov 2018 19:55:08 +0100
Subject: [PATCH] [Linux] read_sysfs() fails on Linux 4.18+
Linux kernel 4.18+ added 4 fields to /sys/block/$dev/stat, ignore them
and parse the rest as usual.
---
psutil/_pslinux.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index b775d39ae..12f17e861 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1099,8 +1099,13 @@ def read_sysfs():
with open_text(os.path.join(root, 'stat')) as f:
fields = f.read().strip().split()
name = os.path.basename(root)
- (reads, reads_merged, rbytes, rtime, writes, writes_merged,
- wbytes, wtime, _, busy_time, _) = map(int, fields)
+ if len(fields) == 11:
+ (reads, reads_merged, rbytes, rtime, writes, writes_merged,
+ wbytes, wtime, _, busy_time, _) = map(int, fields)
+ else: # Linux 4.18+ adds for fields for discard
+ (reads, reads_merged, rbytes, rtime, writes, writes_merged,
+ wbytes, wtime, _, busy_time, _, _, _, _, _) = map(int,
+ fields)
yield (name, reads, writes, rbytes, wbytes, rtime,
wtime, reads_merged, writes_merged, busy_time)