summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornia <nia@NetBSD.org>2021-08-08 09:05:53 +0200
committerBenBE <BenBE@geshi.org>2021-08-09 09:08:37 +0200
commit5b8654d3419e8d369be031f212c48d111309b8c7 (patch)
tree0a2522f0c7da8f7005db3d92f465d3132ce1db91
parenteb4ff3c69cf2b0c78d5158728fe0cc0245f2d080 (diff)
netbsd: Add support for DiskIOMeter
-rw-r--r--netbsd/Platform.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/netbsd/Platform.c b/netbsd/Platform.c
index d99ea6e3..0d717e9d 100644
--- a/netbsd/Platform.c
+++ b/netbsd/Platform.c
@@ -24,6 +24,7 @@ in the source distribution for its full text.
#include <time.h>
#include <prop/proplib.h>
#include <sys/envsys.h>
+#include <sys/iostat.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
@@ -163,6 +164,7 @@ const MeterClass* const Platform_meterTypes[] = {
&LeftCPUs8Meter_class,
&RightCPUs8Meter_class,
&BlankMeter_class,
+ &DiskIOMeter_class,
NULL
};
@@ -329,9 +331,41 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
}
bool Platform_getDiskIO(DiskIOData* data) {
- // TODO
- (void)data;
- return false;
+ const int mib[] = { CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl) };
+ struct io_sysctl *iostats = NULL;
+ size_t size = 0;
+
+ /* get the size of the IO statistic array */
+ (void)sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0);
+ if (size == 0)
+ return false;
+
+ iostats = xMalloc(size);
+ if (sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0) < 0) {
+ free(iostats);
+ return false;
+ }
+
+ uint64_t bytesReadSum = 0;
+ uint64_t bytesWriteSum = 0;
+ uint64_t busyTimeSum = 0;
+
+ for (size_t i = 0, count = size / sizeof(struct io_sysctl); i < count; i++) {
+ /* ignore NFS activity */
+ if (iostats[i].type != IOSTAT_DISK)
+ continue;
+
+ bytesReadSum += iostats[i].rbytes;
+ bytesWriteSum += iostats[i].wbytes;
+ busyTimeSum += iostats[i].busysum_usec;
+ }
+
+ data->totalBytesRead = bytesReadSum;
+ data->totalBytesWritten = bytesWriteSum;
+ data->totalMsTimeSpend = busyTimeSum / 1000;
+
+ free(iostats);
+ return true;
}
bool Platform_getNetworkIO(NetworkIOData* data) {

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