From 5b8654d3419e8d369be031f212c48d111309b8c7 Mon Sep 17 00:00:00 2001 From: nia Date: Sun, 8 Aug 2021 09:05:53 +0200 Subject: netbsd: Add support for DiskIOMeter --- netbsd/Platform.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'netbsd') 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 #include #include +#include #include #include #include @@ -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) { -- cgit v1.2.3