|
| 1 | +#include "diskio.h" |
| 2 | +#include "util/stringUtils.h" |
| 3 | +#include "util/mallocHelper.h" |
| 4 | + |
| 5 | +#include <sys/disk.h> |
| 6 | +#include <sys/sysctl.h> |
| 7 | + |
| 8 | +const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) |
| 9 | +{ |
| 10 | + int mib[] = {CTL_HW, HW_DISKSTATS}; |
| 11 | + size_t len; |
| 12 | + if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0) |
| 13 | + return "sysctl({HW_DISKSTATS}, NULL) failed"; |
| 14 | + uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats)); |
| 15 | + |
| 16 | + printf("C: %d\n", nDrive); |
| 17 | + |
| 18 | + struct diskstats* stats = malloc(len); |
| 19 | + |
| 20 | + if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0) |
| 21 | + return "sysctl({HW_DISKSTATS}, stats) failed"; |
| 22 | + |
| 23 | + for (uint32_t i = 0; i < nDrive; ++i) |
| 24 | + { |
| 25 | + struct diskstats* st = &stats[i]; |
| 26 | + |
| 27 | + if (options->namePrefix.length && strncmp(st->ds_name, options->namePrefix.chars, options->namePrefix.length) != 0) |
| 28 | + continue; |
| 29 | + |
| 30 | + FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); |
| 31 | + ffStrbufInitF(&device->devPath, "/dev/%s", st->ds_name); |
| 32 | + ffStrbufInitS(&device->name, st->ds_name); |
| 33 | + device->bytesRead = st->ds_rbytes; |
| 34 | + device->readCount = st->ds_rxfer; |
| 35 | + device->bytesWritten = st->ds_wbytes; |
| 36 | + device->writeCount = st->ds_wxfer; |
| 37 | + } |
| 38 | + |
| 39 | + return NULL; |
| 40 | +} |
0 commit comments