summaryrefslogtreecommitdiffstats
path: root/freebsd
diff options
context:
space:
mode:
authorChristian Goettsche <cgzones@googlemail.com>2020-10-21 17:06:32 +0200
committercgzones <cgzones@googlemail.com>2020-10-29 22:21:42 +0100
commitc2fdfd99eb5bffee0f6d1e1838fb4708eac18425 (patch)
treeeee28e177708eb99f14c6aa6f67f818daaf69e18 /freebsd
parentc91061c84bcce51934f05df7a7ee4d219f01bc71 (diff)
FreeBSD: implement Platform_getDiskIO()
Diffstat (limited to 'freebsd')
-rw-r--r--freebsd/Platform.c47
-rw-r--r--freebsd/Platform.h5
2 files changed, 43 insertions, 9 deletions
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 <devstat.h>
#include <math.h>
#include <time.h>
#include <net/if.h>
@@ -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, &current) < 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(&current.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,

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