summaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-08-21 21:47:19 +0200
committerBenBE <BenBE@geshi.org>2021-09-02 22:12:58 +0200
commitf94934472f6325db33a45ca5a3a29e371085e507 (patch)
tree0b8a2408b34b343eca40d79003561e20359b81ec /linux
parentbecd33795c99a3f1b26024dd9fa8cc880f4d399d (diff)
Linux: rework disk-io parsing
Generalize sub-diskname handling, like sdb1/sdb2, to not count the usage twice with the aggregate top-diskname, like sdb. Rely on /proc/diskstats being ordered, e.g. no sub-diskname precedes its top-diskname. Closes: #675
Diffstat (limited to 'linux')
-rw-r--r--linux/Platform.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/linux/Platform.c b/linux/Platform.c
index 7d1c190a..05023d50 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -543,6 +543,8 @@ bool Platform_getDiskIO(DiskIOData* data) {
if (!fd)
return false;
+ char lastTopDisk[32] = { '\0' };
+
unsigned long long int read_sum = 0, write_sum = 0, timeSpend_sum = 0;
char lineBuffer[256];
while (fgets(lineBuffer, sizeof(lineBuffer), fd)) {
@@ -556,22 +558,11 @@ bool Platform_getDiskIO(DiskIOData* data) {
continue;
/* only count root disks, e.g. do not count IO from sda and sda1 twice */
- if ((diskname[0] == 's' || diskname[0] == 'h')
- && diskname[1] == 'd'
- && isalpha((unsigned char)diskname[2])
- && isdigit((unsigned char)diskname[3]))
+ if (lastTopDisk[0] && String_startsWith(diskname, lastTopDisk))
continue;
- /* only count root disks, e.g. do not count IO from mmcblk0 and mmcblk0p1 twice */
- if (diskname[0] == 'm'
- && diskname[1] == 'm'
- && diskname[2] == 'c'
- && diskname[3] == 'b'
- && diskname[4] == 'l'
- && diskname[5] == 'k'
- && isdigit((unsigned char)diskname[6])
- && diskname[7] == 'p')
- continue;
+ /* This assumes disks are listed directly before any of their partitions */
+ String_safeStrncpy(lastTopDisk, diskname, sizeof(lastTopDisk));
read_sum += read_tmp;
write_sum += write_tmp;

© 2014-2024 Faster IT GmbH | imprint | privacy policy