diff options
author | Nathan Scott <nathans@redhat.com> | 2021-03-01 11:55:15 +1100 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2021-03-01 11:55:15 +1100 |
commit | 2d1839289eca016893b898dc713cbf1a1df92fc1 (patch) | |
tree | 70990056703220405da20a7c97e66e3d53dff59c /linux | |
parent | 379421d3b2a5a1cf718b555663ec873ef7ea90d8 (diff) |
Fix integer sizing issues in the NetworkIO Meter
On Linux kernels the size of the values exported for network
device bytes and packets has used a 64 bit integer for quite
some time (2.6+ IIRC). Make the procfs value extraction use
correct types and change internal types used to rate convert
these counters (within the NetworkIO Meter) 64 bit integers,
where appropriate.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/Platform.c | 31 | ||||
-rw-r--r-- | linux/Platform.h | 6 |
2 files changed, 14 insertions, 23 deletions
diff --git a/linux/Platform.c b/linux/Platform.c index da2ae606..00b8e309 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -534,42 +534,35 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(unsigned long int* bytesReceived, - unsigned long int* packetsReceived, - unsigned long int* bytesTransmitted, - unsigned long int* packetsTransmitted) { +bool Platform_getNetworkIO(NetworkIOData* data) { FILE* fd = fopen(PROCDIR "/net/dev", "r"); if (!fd) return false; - unsigned long int bytesReceivedSum = 0, packetsReceivedSum = 0, bytesTransmittedSum = 0, packetsTransmittedSum = 0; + memset(data, 0, sizeof(NetworkIOData)); char lineBuffer[512]; while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { char interfaceName[32]; - unsigned long int bytesReceivedParsed, packetsReceivedParsed, bytesTransmittedParsed, packetsTransmittedParsed; - if (sscanf(lineBuffer, "%31s %lu %lu %*u %*u %*u %*u %*u %*u %lu %lu", + unsigned long long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted; + if (sscanf(lineBuffer, "%31s %llu %llu %*u %*u %*u %*u %*u %*u %llu %llu", interfaceName, - &bytesReceivedParsed, - &packetsReceivedParsed, - &bytesTransmittedParsed, - &packetsTransmittedParsed) != 5) + &bytesReceived, + &packetsReceived, + &bytesTransmitted, + &packetsTransmitted) != 5) continue; if (String_eq(interfaceName, "lo:")) continue; - bytesReceivedSum += bytesReceivedParsed; - packetsReceivedSum += packetsReceivedParsed; - bytesTransmittedSum += bytesTransmittedParsed; - packetsTransmittedSum += packetsTransmittedParsed; + data->bytesReceived += bytesReceived; + data->packetsReceived += packetsReceived; + data->bytesTransmitted += bytesTransmitted; + data->packetsTransmitted += packetsTransmitted; } fclose(fd); - *bytesReceived = bytesReceivedSum; - *packetsReceived = packetsReceivedSum; - *bytesTransmitted = bytesTransmittedSum; - *packetsTransmitted = packetsTransmittedSum; return true; } diff --git a/linux/Platform.h b/linux/Platform.h index d87ef55a..f932c583 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -15,6 +15,7 @@ in the source distribution for its full text. #include "BatteryMeter.h" #include "DiskIOMeter.h" #include "Meter.h" +#include "NetworkIOMeter.h" #include "Process.h" #include "ProcessLocksScreen.h" #include "SignalsPanel.h" @@ -67,10 +68,7 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int* bytesReceived, - unsigned long int* packetsReceived, - unsigned long int* bytesTransmitted, - unsigned long int* packetsTransmitted); +bool Platform_getNetworkIO(NetworkIOData* data); void Platform_getBattery(double *percent, ACPresence *isOnAC); |