implement disk i/o metrics

This commit is contained in:
Doug MacEachern 2004-12-07 16:53:34 +00:00
parent e4a6c819be
commit 9721ca0121
2 changed files with 72 additions and 1 deletions

View File

@ -1,10 +1,11 @@
#include "sigar.h" #include "sigar.h"
#include "sigar_private.h" #include "sigar_private.h"
#include "sigar_os.h"
#include "sigar_util.h" #include "sigar_util.h"
#include "sigar_os.h"
#include <sys/dk.h> #include <sys/dk.h>
#include <sys/lwp.h> #include <sys/lwp.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
int sigar_os_open(sigar_t **sigar) int sigar_os_open(sigar_t **sigar)
@ -22,6 +23,8 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->pinfo = NULL; (*sigar)->pinfo = NULL;
(*sigar)->fsdev = NULL;
return SIGAR_OK; return SIGAR_OK;
} }
@ -31,6 +34,9 @@ int sigar_os_close(sigar_t *sigar)
if (sigar->pinfo) { if (sigar->pinfo) {
free(sigar->pinfo); free(sigar->pinfo);
} }
if (sigar->fsdev) {
sigar_cache_destroy(sigar->fsdev);
}
free(sigar); free(sigar);
return SIGAR_OK; return SIGAR_OK;
} }
@ -542,11 +548,44 @@ int sigar_file_system_list_get(sigar_t *sigar,
#define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \ #define SIGAR_FS_BLOCKS_TO_BYTES(buf, f) \
((buf.f * (buf.f_bsize / 512)) >> 1) ((buf.f * (buf.f_bsize / 512)) >> 1)
#define FSDEV_ID(sb) (sb.st_ino + sb.st_dev)
static int create_fsdev_cache(sigar_t *sigar)
{
sigar_file_system_list_t fslist;
int i;
int status =
sigar_file_system_list_get(sigar, &fslist);
if (status != SIGAR_OK) {
return status;
}
sigar->fsdev = sigar_cache_new(15);
for (i=0; i<fslist.number; i++) {
sigar_file_system_t *fsp = &fslist.data[i];
if (fsp->type == SIGAR_FSTYPE_LOCAL_DISK) {
sigar_cache_entry_t *ent;
struct stat sb;
if (stat(fsp->dir_name, &sb) < 0) {
continue;
}
ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb));
ent->value = strdup(fsp->dev_name);
}
}
}
int sigar_file_system_usage_get(sigar_t *sigar, int sigar_file_system_usage_get(sigar_t *sigar,
const char *dirname, const char *dirname,
sigar_file_system_usage_t *fsusage) sigar_file_system_usage_t *fsusage)
{ {
struct statfs buf; struct statfs buf;
struct stat sb;
if (statfs(dirname, &buf) != 0) { if (statfs(dirname, &buf) != 0) {
return errno; return errno;
@ -561,6 +600,36 @@ int sigar_file_system_usage_get(sigar_t *sigar,
SIGAR_DISK_STATS_NOTIMPL(fsusage); SIGAR_DISK_STATS_NOTIMPL(fsusage);
if (!sigar->fsdev) {
if (create_fsdev_cache(sigar) != SIGAR_OK) {
return SIGAR_OK;
}
}
if (stat(dirname, &sb) == 0) {
sigar_cache_entry_t *ent;
struct pst_lvinfo lv;
struct stat devsb;
char *devname;
int retval;
ent = sigar_cache_get(sigar->fsdev, FSDEV_ID(sb));
if (ent->value == NULL) {
return SIGAR_OK;
}
if (stat((char *)ent->value, &devsb) < 0) {
return SIGAR_OK;
}
retval = pstat_getlv(&lv, sizeof(lv), 0, (int)devsb.st_rdev);
if (retval == 1) {
fsusage->disk_reads = lv.psl_rxfer;
fsusage->disk_writes = lv.psl_wxfer;
}
}
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -12,6 +12,8 @@ struct sigar_t {
time_t last_getprocs; time_t last_getprocs;
sigar_pid_t last_pid; sigar_pid_t last_pid;
struct pst_status *pinfo; struct pst_status *pinfo;
sigar_cache_t *fsdev;
}; };
int hpux_get_mib_ifentry(int ppa, mib_ifEntry *mib); int hpux_get_mib_ifentry(int ppa, mib_ifEntry *mib);