From c2fdfd99eb5bffee0f6d1e1838fb4708eac18425 Mon Sep 17 00:00:00 2001 From: Christian Goettsche Date: Wed, 21 Oct 2020 17:06:32 +0200 Subject: FreeBSD: implement Platform_getDiskIO() --- freebsd/Platform.c | 47 +++++++++++++++++++++++++++++++++++++++++------ freebsd/Platform.h | 5 ++--- 2 files changed, 43 insertions(+), 9 deletions(-) (limited to 'freebsd') diff --git a/freebsd/Platform.c b/freebsd/Platform.c index b23a8624..bdd49bf6 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -7,6 +7,7 @@ in the source distribution for its full text. #include "Platform.h" +#include #include #include #include @@ -21,6 +22,7 @@ in the source distribution for its full text. #include "ClockMeter.h" #include "DateMeter.h" #include "DateTimeMeter.h" +#include "DiskIOMeter.h" #include "FreeBSDProcess.h" #include "FreeBSDProcessList.h" #include "HostnameMeter.h" @@ -111,6 +113,7 @@ const MeterClass* const Platform_meterTypes[] = { &BlankMeter_class, &ZfsArcMeter_class, &ZfsCompressedArcMeter_class, + &DiskIOMeter_class, &NetworkIOMeter_class, NULL }; @@ -240,12 +243,44 @@ char* Platform_getProcessEnv(pid_t pid) { return env; } -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend) { - // TODO - *bytesRead = *bytesWrite = *msTimeSpend = 0; - return false; +bool Platform_getDiskIO(DiskIOData* data) { + + if (devstat_checkversion(NULL) < 0) + return false; + + struct devinfo info = { 0 }; + struct statinfo current = { .dinfo = &info }; + + // get number of devices + if (devstat_getdevs(NULL, ¤t) < 0) + return false; + + int count = current.dinfo->numdevs; + + unsigned long int bytesReadSum = 0, bytesWriteSum = 0, timeSpendSum = 0; + + // get data + for (int i = 0; i < count; i++) { + uint64_t bytes_read, bytes_write; + long double busy_time; + + devstat_compute_statistics(¤t.dinfo->devices[i], + NULL, + 1.0, + DSM_TOTAL_BYTES_READ, &bytes_read, + DSM_TOTAL_BYTES_WRITE, &bytes_write, + DSM_TOTAL_BUSY_TIME, &busy_time, + DSM_NONE); + + bytesReadSum += bytes_read; + bytesWriteSum += bytes_write; + timeSpendSum += 1000 * busy_time; + } + + data->totalBytesRead = bytesReadSum; + data->totalBytesWritten = bytesWriteSum; + data->totalMsTimeSpend = timeSpendSum; + return true; } bool Platform_getNetworkIO(unsigned long int *bytesReceived, diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 40fb2d97..894b3e25 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -9,6 +9,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "DiskIOMeter.h" #include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -43,9 +44,7 @@ void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -bool Platform_getDiskIO(unsigned long int *bytesRead, - unsigned long int *bytesWrite, - unsigned long int *msTimeSpend); +bool Platform_getDiskIO(DiskIOData* data); bool Platform_getNetworkIO(unsigned long int *bytesReceived, unsigned long int *packetsReceived, -- cgit v1.2.3