start linux disk service_time impl

This commit is contained in:
Doug MacEachern 2007-11-03 23:10:59 +00:00
parent 382dcba038
commit 60b0114c50
1 changed files with 61 additions and 20 deletions

View File

@ -1182,6 +1182,7 @@ int sigar_file_system_list_get(sigar_t *sigar,
typedef struct { typedef struct {
char name[256]; char name[256];
sigar_disk_usage_t disk;
} iodev_t; } iodev_t;
static iodev_t *get_fsdev(sigar_t *sigar, static iodev_t *get_fsdev(sigar_t *sigar,
@ -1302,18 +1303,18 @@ static iodev_t *get_fsdev(sigar_t *sigar,
static int get_iostat_sys(sigar_t *sigar, static int get_iostat_sys(sigar_t *sigar,
const char *dirname, const char *dirname,
sigar_disk_usage_t *disk) sigar_disk_usage_t *disk,
iodev_t **iodev)
{ {
char stat[1025], dev[1025]; char stat[1025], dev[1025];
char *name, *ptr, *fsdev; char *name, *ptr, *fsdev;
int partition, status; int partition, status;
iodev_t *iodev;
if (!(iodev = get_fsdev(sigar, dirname))) { if (!(*iodev = get_fsdev(sigar, dirname))) {
return ENOENT; return ENOENT;
} }
name = fsdev = iodev->name; name = fsdev = (*iodev)->name;
if (FSDEV_IS_DEV(name)) { if (FSDEV_IS_DEV(name)) {
name += 5; /* strip "/dev/" */ name += 5; /* strip "/dev/" */
@ -1349,26 +1350,26 @@ static int get_iostat_sys(sigar_t *sigar,
static int get_iostat_proc_dstat(sigar_t *sigar, static int get_iostat_proc_dstat(sigar_t *sigar,
const char *dirname, const char *dirname,
sigar_disk_usage_t *disk) sigar_disk_usage_t *disk,
iodev_t **iodev)
{ {
FILE *fp; FILE *fp;
char buffer[1025]; char buffer[1025];
char *ptr; char *ptr;
struct stat sb; struct stat sb;
iodev_t *iodev;
if (!(iodev = get_fsdev(sigar, dirname))) { if (!(*iodev = get_fsdev(sigar, dirname))) {
return ENOENT; return ENOENT;
} }
if (stat(iodev->name, &sb) < 0) { if (stat((*iodev)->name, &sb) < 0) {
return errno; return errno;
} }
if (SIGAR_LOG_IS_DEBUG(sigar)) { if (SIGAR_LOG_IS_DEBUG(sigar)) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG, sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
PROC_DISKSTATS " %s -> %s [%d,%d]", PROC_DISKSTATS " %s -> %s [%d,%d]",
dirname, iodev->name, dirname, (*iodev)->name,
ST_MAJOR(sb), ST_MINOR(sb)); ST_MAJOR(sb), ST_MINOR(sb));
} }
@ -1417,7 +1418,7 @@ static int get_iostat_proc_dstat(sigar_t *sigar,
wio = rsect; wio = rsect;
rsect = rmerge; rsect = rmerge;
wsect = ruse; wsect = ruse;
disk->queue = SIGAR_FIELD_NOTIMPL; disk->time = disk->queue = SIGAR_FIELD_NOTIMPL;
} }
else { else {
status = ENOENT; status = ENOENT;
@ -1444,26 +1445,26 @@ static int get_iostat_proc_dstat(sigar_t *sigar,
static int get_iostat_procp(sigar_t *sigar, static int get_iostat_procp(sigar_t *sigar,
const char *dirname, const char *dirname,
sigar_disk_usage_t *disk) sigar_disk_usage_t *disk,
iodev_t **iodev)
{ {
FILE *fp; FILE *fp;
char buffer[1025]; char buffer[1025];
char *ptr; char *ptr;
struct stat sb; struct stat sb;
iodev_t *iodev;
if (!(iodev = get_fsdev(sigar, dirname))) { if (!(*iodev = get_fsdev(sigar, dirname))) {
return ENOENT; return ENOENT;
} }
if (stat(iodev->name, &sb) < 0) { if (stat((*iodev)->name, &sb) < 0) {
return errno; return errno;
} }
if (SIGAR_LOG_IS_DEBUG(sigar)) { if (SIGAR_LOG_IS_DEBUG(sigar)) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG, sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
PROC_PARTITIONS " %s -> %s [%d,%d]", PROC_PARTITIONS " %s -> %s [%d,%d]",
dirname, iodev->name, dirname, (*iodev)->name,
ST_MAJOR(sb), ST_MINOR(sb)); ST_MAJOR(sb), ST_MINOR(sb));
} }
@ -1485,9 +1486,9 @@ static int get_iostat_procp(sigar_t *sigar,
ptr = sigar_skip_token(ptr); /* rmerge */ ptr = sigar_skip_token(ptr); /* rmerge */
disk->read_bytes = sigar_strtoull(ptr); /* rsect */ disk->read_bytes = sigar_strtoull(ptr); /* rsect */
disk->rtime = sigar_strtoull(ptr); /* ruse */ disk->rtime = sigar_strtoull(ptr); /* ruse */
disk->writes = sigar_strtoull(ptr); /* wio */
ptr = sigar_skip_token(ptr); /* wmerge */ ptr = sigar_skip_token(ptr); /* wmerge */
disk->write_bytes = sigar_strtoull(ptr); /* wsect */ disk->write_bytes = sigar_strtoull(ptr); /* wsect */
disk->writes = sigar_strtoull(ptr); /* wio */
disk->wtime = sigar_strtoull(ptr); /* wuse */ disk->wtime = sigar_strtoull(ptr); /* wuse */
ptr = sigar_skip_token(ptr); /* running */ ptr = sigar_skip_token(ptr); /* running */
disk->time = sigar_strtoull(ptr); /* use */ disk->time = sigar_strtoull(ptr); /* use */
@ -1511,6 +1512,8 @@ static int get_iostat_procp(sigar_t *sigar,
int sigar_disk_usage_get(sigar_t *sigar, const char *name, int sigar_disk_usage_get(sigar_t *sigar, const char *name,
sigar_disk_usage_t *disk) sigar_disk_usage_t *disk)
{ {
int status;
iodev_t *iodev = NULL;
SIGAR_DISK_STATS_INIT(disk); SIGAR_DISK_STATS_INIT(disk);
/* /*
@ -1522,19 +1525,57 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name,
*/ */
switch (sigar->iostat) { switch (sigar->iostat) {
case IOSTAT_SYS: case IOSTAT_SYS:
return get_iostat_sys(sigar, name, disk); status = get_iostat_sys(sigar, name, disk, &iodev);
break;
case IOSTAT_DISKSTATS: case IOSTAT_DISKSTATS:
return get_iostat_proc_dstat(sigar, name, disk); status = get_iostat_proc_dstat(sigar, name, disk, &iodev);
break;
case IOSTAT_PARTITIONS: case IOSTAT_PARTITIONS:
return get_iostat_procp(sigar, name, disk); status = get_iostat_procp(sigar, name, disk, &iodev);
break;
/* /*
* case IOSTAT_SOME_OTHER_WIERD_THING: * case IOSTAT_SOME_OTHER_WIERD_THING:
* break; * break;
*/ */
case IOSTAT_NONE: case IOSTAT_NONE:
default: default:
return ENOENT; status = ENOENT;
break;
} }
if ((status == SIGAR_OK) && iodev) {
sigar_uptime_t uptime;
sigar_uint64_t interval, ios;
double tput, util;
sigar_uptime_get(sigar, &uptime);
disk->snaptime = uptime.uptime;
if (iodev->disk.snaptime) {
interval = disk->snaptime - iodev->disk.snaptime;
}
else {
interval = disk->snaptime;
}
ios =
(disk->reads - iodev->disk.reads) +
(disk->writes - iodev->disk.writes);
if (disk->time == SIGAR_FIELD_NOTIMPL) {
disk->service_time = SIGAR_FIELD_NOTIMPL;
}
else {
tput = ((double)ios) * HZ / interval;
util = ((double)(disk->time - iodev->disk.time)) / interval * HZ;
disk->service_time = tput ? util / tput : 0.0;
}
memcpy(&iodev->disk, &disk, sizeof(&iodev->disk));
}
return status;
} }
#include <sys/vfs.h> #include <sys/vfs.h>