|
1 | 1 | #include "diskio.h" |
2 | | -#include "common/io/io.h" |
3 | | -#include "util/stringUtils.h" |
4 | 2 |
|
5 | | -#include <ctype.h> |
6 | | -#include <limits.h> |
| 3 | +#include <devstat.h> |
| 4 | +#include <memory.h> |
7 | 5 |
|
8 | 6 | const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) |
9 | 7 | { |
10 | | - return "Not supported on this platform"; |
| 8 | + if (devstat_checkversion(NULL) < 0) |
| 9 | + return "devstat_checkversion() failed"; |
| 10 | + |
| 11 | + struct statinfo stats = { |
| 12 | + .dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)), |
| 13 | + }; |
| 14 | + if (devstat_getdevs(NULL, &stats) < 0) |
| 15 | + return "devstat_getdevs() failed"; |
| 16 | + |
| 17 | + for (int i = 0; i < stats.dinfo->numdevs; i++) |
| 18 | + { |
| 19 | + struct devstat* current = &stats.dinfo->devices[i]; |
| 20 | + |
| 21 | + char deviceName[128]; |
| 22 | + snprintf(deviceName, sizeof(deviceName), "%s%d", current->device_name, current->unit_number); |
| 23 | + |
| 24 | + if (options->namePrefix.length && strncmp(deviceName, options->namePrefix.chars, options->namePrefix.length) != 0) |
| 25 | + continue; |
| 26 | + |
| 27 | + FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); |
| 28 | + ffStrbufInitS(&device->name, deviceName); |
| 29 | + ffStrbufInitF(&device->devPath, "/dev/%s", deviceName); |
| 30 | + |
| 31 | + ffStrbufInit(&device->type); |
| 32 | + switch (current->device_type & DEVSTAT_TYPE_IF_MASK) |
| 33 | + { |
| 34 | + case DEVSTAT_TYPE_IF_SCSI: ffStrbufAppendS(&device->type, "SCSI"); break; |
| 35 | + case DEVSTAT_TYPE_IF_IDE: ffStrbufAppendS(&device->type, "IDE"); break; |
| 36 | + case DEVSTAT_TYPE_IF_OTHER: ffStrbufAppendS(&device->type, "OTHER"); break; |
| 37 | + } |
| 38 | + device->bytesRead = current->bytes[DEVSTAT_READ]; |
| 39 | + device->readCount = current->operations[DEVSTAT_READ]; |
| 40 | + device->bytesWritten = current->bytes[DEVSTAT_WRITE]; |
| 41 | + device->writeCount = current->operations[DEVSTAT_WRITE]; |
| 42 | + } |
| 43 | + |
| 44 | + if (stats.dinfo->mem_ptr) |
| 45 | + free(stats.dinfo->mem_ptr); |
| 46 | + free(stats.dinfo); |
| 47 | + |
| 48 | + return NULL; |
11 | 49 | } |
0 commit comments