re-org sigar_disk_usage_t struct

This commit is contained in:
Doug MacEachern 2007-10-13 21:56:18 +00:00
parent 07e4db1d14
commit 4d7e7a3bd7
3 changed files with 59 additions and 53 deletions

View File

@ -432,22 +432,26 @@ SIGAR_DECLARE(int)
sigar_file_system_list_destroy(sigar_t *sigar, sigar_file_system_list_destroy(sigar_t *sigar,
sigar_file_system_list_t *fslist); sigar_file_system_list_t *fslist);
#define SIGAR_DISK_USAGE_T \
sigar_uint64_t disk_reads; \
sigar_uint64_t disk_writes; \
sigar_uint64_t disk_write_bytes; \
sigar_uint64_t disk_read_bytes; \
sigar_uint64_t disk_queue; \
sigar_uint64_t disk_rtime; \
sigar_uint64_t disk_wtime; \
sigar_uint64_t disk_time
typedef struct { typedef struct {
SIGAR_DISK_USAGE_T; sigar_uint64_t reads;
sigar_uint64_t writes;
sigar_uint64_t write_bytes;
sigar_uint64_t read_bytes;
sigar_uint64_t queue;
sigar_uint64_t rtime;
sigar_uint64_t wtime;
sigar_uint64_t time;
} sigar_disk_usage_t; } sigar_disk_usage_t;
/* XXX for sigar_file_system_usage_t compat */
#define disk_reads disk.reads
#define disk_writes disk.writes
#define disk_write_bytes disk.write_bytes
#define disk_read_bytes disk.read_bytes
#define disk_queue disk.queue
typedef struct { typedef struct {
SIGAR_DISK_USAGE_T; sigar_disk_usage_t disk;
double use_percent; double use_percent;
sigar_uint64_t total; sigar_uint64_t total;
sigar_uint64_t free; sigar_uint64_t free;
@ -466,7 +470,7 @@ sigar_file_system_usage_get(sigar_t *sigar,
SIGAR_DECLARE(int) sigar_disk_usage_get(sigar_t *sigar, SIGAR_DECLARE(int) sigar_disk_usage_get(sigar_t *sigar,
const char *name, const char *name,
sigar_disk_usage_t *usage); sigar_disk_usage_t *disk);
SIGAR_DECLARE(int) SIGAR_DECLARE(int)
sigar_file_system_ping(sigar_t *sigar, sigar_file_system_ping(sigar_t *sigar,

View File

@ -309,10 +309,13 @@ int sigar_group_name_get(sigar_t *sigar, int gid, char *buf, int buflen);
return SIGAR_OK; \ return SIGAR_OK; \
} }
#define SIGAR_DISK_STATS_INIT(disk) \
(disk)->reads = (disk)->writes = \
(disk)->read_bytes = (disk)->write_bytes = \
(disk)->queue = (disk)->time = SIGAR_FIELD_NOTIMPL;
#define SIGAR_DISK_STATS_NOTIMPL(fsusage) \ #define SIGAR_DISK_STATS_NOTIMPL(fsusage) \
fsusage->disk_reads = fsusage->disk_writes = \ SIGAR_DISK_STATS_INIT(&fsusage->disk)
fsusage->disk_read_bytes = fsusage->disk_write_bytes = \
fsusage->disk_queue = fsusage->disk_time = SIGAR_FIELD_NOTIMPL;
/* key used for filesystem (/) -> device (/dev/hda1) mapping */ /* key used for filesystem (/) -> device (/dev/hda1) mapping */
#define SIGAR_FSDEV_ID(sb) ((sb).st_ino + (sb).st_dev) #define SIGAR_FSDEV_ID(sb) ((sb).st_ino + (sb).st_dev)

View File

@ -1302,7 +1302,7 @@ 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 *fsusage) sigar_disk_usage_t *disk)
{ {
char stat[1025], dev[1025]; char stat[1025], dev[1025];
char *name, *ptr, *fsdev; char *name, *ptr, *fsdev;
@ -1336,20 +1336,20 @@ static int get_iostat_sys(sigar_t *sigar,
ptr = dev; ptr = dev;
ptr = sigar_skip_token(ptr); ptr = sigar_skip_token(ptr);
fsusage->disk_reads = sigar_strtoull(ptr); disk->reads = sigar_strtoull(ptr);
ptr = sigar_skip_token(ptr); ptr = sigar_skip_token(ptr);
fsusage->disk_writes = sigar_strtoull(ptr); disk->writes = sigar_strtoull(ptr);
fsusage->disk_read_bytes = SIGAR_FIELD_NOTIMPL; disk->read_bytes = SIGAR_FIELD_NOTIMPL;
fsusage->disk_write_bytes = SIGAR_FIELD_NOTIMPL; disk->write_bytes = SIGAR_FIELD_NOTIMPL;
fsusage->disk_queue = SIGAR_FIELD_NOTIMPL; disk->queue = SIGAR_FIELD_NOTIMPL;
return SIGAR_OK; return SIGAR_OK;
} }
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 *fsusage) sigar_disk_usage_t *disk)
{ {
FILE *fp; FILE *fp;
char buffer[1025]; char buffer[1025];
@ -1408,29 +1408,29 @@ static int get_iostat_proc_dstat(sigar_t *sigar,
&aveq); /* 11 # of millis spent doing I/Os (weighted) */ &aveq); /* 11 # of millis spent doing I/Os (weighted) */
if (num == 11) { if (num == 11) {
fsusage->disk_rtime = ruse; disk->rtime = ruse;
fsusage->disk_wtime = wuse; disk->wtime = wuse;
fsusage->disk_time = use; disk->time = use;
fsusage->disk_queue = aveq / 1000; disk->queue = aveq / 1000;
} }
else if (num == 4) { else if (num == 4) {
wio = rsect; wio = rsect;
rsect = rmerge; rsect = rmerge;
wsect = ruse; wsect = ruse;
fsusage->disk_queue = SIGAR_FIELD_NOTIMPL; disk->queue = SIGAR_FIELD_NOTIMPL;
} }
else { else {
status = ENOENT; status = ENOENT;
} }
fsusage->disk_reads = rio; disk->reads = rio;
fsusage->disk_writes = wio; disk->writes = wio;
fsusage->disk_read_bytes = rsect; disk->read_bytes = rsect;
fsusage->disk_write_bytes = wsect; disk->write_bytes = wsect;
/* convert sectors to bytes (512 is fixed size in 2.6 kernels) */ /* convert sectors to bytes (512 is fixed size in 2.6 kernels) */
fsusage->disk_read_bytes *= 512; disk->read_bytes *= 512;
fsusage->disk_write_bytes *= 512; disk->write_bytes *= 512;
fclose(fp); fclose(fp);
return status; return status;
@ -1444,7 +1444,7 @@ 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 *fsusage) sigar_disk_usage_t *disk)
{ {
FILE *fp; FILE *fp;
char buffer[1025]; char buffer[1025];
@ -1481,22 +1481,22 @@ static int get_iostat_procp(sigar_t *sigar,
if ((major == ST_MAJOR(sb)) && (minor == ST_MINOR(sb))) { if ((major == ST_MAJOR(sb)) && (minor == ST_MINOR(sb))) {
ptr = sigar_skip_token(ptr); /* blocks */ ptr = sigar_skip_token(ptr); /* blocks */
ptr = sigar_skip_token(ptr); /* name */ ptr = sigar_skip_token(ptr); /* name */
fsusage->disk_reads = sigar_strtoull(ptr); /* rio */ disk->reads = sigar_strtoull(ptr); /* rio */
ptr = sigar_skip_token(ptr); /* rmerge */ ptr = sigar_skip_token(ptr); /* rmerge */
fsusage->disk_read_bytes = sigar_strtoull(ptr); /* rsect */ disk->read_bytes = sigar_strtoull(ptr); /* rsect */
fsusage->disk_rtime = sigar_strtoull(ptr); /* ruse */ disk->rtime = sigar_strtoull(ptr); /* ruse */
ptr = sigar_skip_token(ptr); /* wmerge */ ptr = sigar_skip_token(ptr); /* wmerge */
fsusage->disk_write_bytes = sigar_strtoull(ptr); /* wsect */ disk->write_bytes = sigar_strtoull(ptr); /* wsect */
fsusage->disk_writes = sigar_strtoull(ptr); /* wio */ disk->writes = sigar_strtoull(ptr); /* wio */
fsusage->disk_wtime = sigar_strtoull(ptr); /* wuse */ disk->wtime = sigar_strtoull(ptr); /* wuse */
ptr = sigar_skip_token(ptr); /* running */ ptr = sigar_skip_token(ptr); /* running */
fsusage->disk_time = sigar_strtoull(ptr); /* use */ disk->time = sigar_strtoull(ptr); /* use */
fsusage->disk_queue = sigar_strtoull(ptr); /* aveq */ disk->queue = sigar_strtoull(ptr); /* aveq */
fsusage->disk_queue /= 1000; disk->queue /= 1000;
/* convert sectors to bytes (512 is fixed size in 2.6 kernels) */ /* convert sectors to bytes (512 is fixed size in 2.6 kernels) */
fsusage->disk_read_bytes *= 512; disk->read_bytes *= 512;
fsusage->disk_write_bytes *= 512; disk->write_bytes *= 512;
fclose(fp); fclose(fp);
return SIGAR_OK; return SIGAR_OK;
@ -1509,9 +1509,9 @@ 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 *usage) sigar_disk_usage_t *disk)
{ {
SIGAR_DISK_STATS_NOTIMPL(usage); /* init */ SIGAR_DISK_STATS_INIT(disk);
/* /*
* 2.2 has metrics /proc/stat, but wtf is the device mapping? * 2.2 has metrics /proc/stat, but wtf is the device mapping?
@ -1522,11 +1522,11 @@ 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, usage); return get_iostat_sys(sigar, name, disk);
case IOSTAT_DISKSTATS: case IOSTAT_DISKSTATS:
return get_iostat_proc_dstat(sigar, name, usage); return get_iostat_proc_dstat(sigar, name, disk);
case IOSTAT_PARTITIONS: case IOSTAT_PARTITIONS:
return get_iostat_procp(sigar, name, usage); return get_iostat_procp(sigar, name, disk);
/* /*
* case IOSTAT_SOME_OTHER_WIERD_THING: * case IOSTAT_SOME_OTHER_WIERD_THING:
* break; * break;
@ -1560,8 +1560,7 @@ int sigar_file_system_usage_get(sigar_t *sigar,
fsusage->free_files = buf.f_ffree; fsusage->free_files = buf.f_ffree;
fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage); fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage);
(void)sigar_disk_usage_get(sigar, dirname, (void)sigar_disk_usage_get(sigar, dirname, &fsusage->disk);
(sigar_disk_usage_t *)fsusage);
return SIGAR_OK; return SIGAR_OK;
} }