Skip to content

Commit

Permalink
DragonFlyBSD: support Disk IO meter
Browse files Browse the repository at this point in the history
  • Loading branch information
cgzones committed Jan 20, 2024
1 parent 1414cdc commit 2f67a2b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ AC_SEARCH_LIBS([ceil], [m], [], [AC_MSG_ERROR([can not find required function ce

if test "$my_htop_platform" = dragonflybsd; then
AC_SEARCH_LIBS([kvm_open], [kvm], [], [AC_MSG_ERROR([can not find required function kvm_open()])])
AC_SEARCH_LIBS([getdevs], [devstat], [], [AC_MSG_ERROR([can not find required function getdevs()])])
fi

if test "$my_htop_platform" = freebsd; then
Expand Down
61 changes: 58 additions & 3 deletions dragonflybsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ in the source distribution for its full text.

#include "dragonflybsd/Platform.h"

#include <devstat.h>
#include <errno.h>
#include <ifaddrs.h>
#include <math.h>
#include <time.h>
Expand Down Expand Up @@ -118,6 +120,7 @@ const MeterClass* const Platform_meterTypes[] = {
&RightCPUs4Meter_class,
&LeftCPUs8Meter_class,
&RightCPUs8Meter_class,
&DiskIOMeter_class,
&NetworkIOMeter_class,
&FileDescriptorMeter_class,
&BlankMeter_class,
Expand Down Expand Up @@ -251,9 +254,61 @@ void Platform_getFileDescriptors(double* used, double* max) {
}

bool Platform_getDiskIO(DiskIOData* data) {
// TODO
(void)data;
return false;
struct statinfo dev_stats = { 0 };
struct device_selection* dev_sel = NULL;
int n_selected, n_selections;
long sel_gen;

dev_stats.dinfo = xCalloc(1, sizeof(struct devinfo));

int ret = getdevs(&dev_stats);
if (ret < 0) {
CRT_debug("getdevs() failed [%d]: %s", ret, strerror(errno));
free(dev_stats.dinfo);
return false;
}

ret = selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen,
dev_stats.dinfo->generation, dev_stats.dinfo->devices, dev_stats.dinfo->numdevs,
NULL, 0, NULL, 0, DS_SELECT_ONLY, dev_stats.dinfo->numdevs, 1);
if (ret < 0) {
CRT_debug("selectdevs() failed [%d]: %s", ret, strerror(errno));
free(dev_stats.dinfo);
return false;
}

uint64_t bytesReadSum = 0;
uint64_t bytesWriteSum = 0;
uint64_t busyMsTimeSum = 0;

for (int i = 0; i < dev_stats.dinfo->numdevs; i++) {
const struct devstat* device = &dev_stats.dinfo->devices[dev_sel[i].position];

switch (device->device_type & DEVSTAT_TYPE_MASK) {
case DEVSTAT_TYPE_DIRECT:
case DEVSTAT_TYPE_SEQUENTIAL:
case DEVSTAT_TYPE_WORM:
case DEVSTAT_TYPE_CDROM:
case DEVSTAT_TYPE_OPTICAL:
case DEVSTAT_TYPE_CHANGER:
case DEVSTAT_TYPE_STORARRAY:
case DEVSTAT_TYPE_FLOPPY:
break;
default:
continue;
}

bytesReadSum += device->bytes_read;
bytesWriteSum += device->bytes_written;
busyMsTimeSum += (device->busy_time.tv_sec * 1000 + device->busy_time.tv_usec / 1000);
}

data->totalBytesRead = bytesReadSum;
data->totalBytesWritten = bytesWriteSum;
data->totalMsTimeSpend = busyMsTimeSum;

free(dev_stats.dinfo);
return true;
}

bool Platform_getNetworkIO(NetworkIOData* data) {
Expand Down

0 comments on commit 2f67a2b

Please sign in to comment.