mirror of https://github.com/xzeldon/htop.git
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
This commit is contained in:
parent
becd33795c
commit
f94934472f
|
@ -543,6 +543,8 @@ bool Platform_getDiskIO(DiskIOData* data) {
|
||||||
if (!fd)
|
if (!fd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
char lastTopDisk[32] = { '\0' };
|
||||||
|
|
||||||
unsigned long long int read_sum = 0, write_sum = 0, timeSpend_sum = 0;
|
unsigned long long int read_sum = 0, write_sum = 0, timeSpend_sum = 0;
|
||||||
char lineBuffer[256];
|
char lineBuffer[256];
|
||||||
while (fgets(lineBuffer, sizeof(lineBuffer), fd)) {
|
while (fgets(lineBuffer, sizeof(lineBuffer), fd)) {
|
||||||
|
@ -556,22 +558,11 @@ bool Platform_getDiskIO(DiskIOData* data) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* only count root disks, e.g. do not count IO from sda and sda1 twice */
|
/* only count root disks, e.g. do not count IO from sda and sda1 twice */
|
||||||
if ((diskname[0] == 's' || diskname[0] == 'h')
|
if (lastTopDisk[0] && String_startsWith(diskname, lastTopDisk))
|
||||||
&& diskname[1] == 'd'
|
|
||||||
&& isalpha((unsigned char)diskname[2])
|
|
||||||
&& isdigit((unsigned char)diskname[3]))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* only count root disks, e.g. do not count IO from mmcblk0 and mmcblk0p1 twice */
|
/* This assumes disks are listed directly before any of their partitions */
|
||||||
if (diskname[0] == 'm'
|
String_safeStrncpy(lastTopDisk, diskname, sizeof(lastTopDisk));
|
||||||
&& diskname[1] == 'm'
|
|
||||||
&& diskname[2] == 'c'
|
|
||||||
&& diskname[3] == 'b'
|
|
||||||
&& diskname[4] == 'l'
|
|
||||||
&& diskname[5] == 'k'
|
|
||||||
&& isdigit((unsigned char)diskname[6])
|
|
||||||
&& diskname[7] == 'p')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
read_sum += read_tmp;
|
read_sum += read_tmp;
|
||||||
write_sum += write_tmp;
|
write_sum += write_tmp;
|
||||||
|
|
Loading…
Reference in New Issue