use perfstat for mem stats

This commit is contained in:
Doug MacEachern 2007-07-15 17:05:17 +00:00
parent 139529c1e5
commit 5ba9b0ee11
2 changed files with 47 additions and 36 deletions

View File

@ -137,22 +137,13 @@ static int kread(sigar_t *sigar, void *data, int size, long offset)
int sigar_os_open(sigar_t **sigar) int sigar_os_open(sigar_t **sigar)
{ {
int status, i; int status, i;
void *dlhandle;
int kmem = -1; int kmem = -1;
vminfo_func_t vminfo = NULL;
struct utsname name; struct utsname name;
if ((dlhandle = dlopen("/unix", RTLD_NOW))) {
vminfo = (vminfo_func_t)dlsym(dlhandle, "vmgetinfo");
dlclose(dlhandle);
}
kmem = open("/dev/kmem", O_RDONLY); kmem = open("/dev/kmem", O_RDONLY);
*sigar = malloc(sizeof(**sigar)); *sigar = malloc(sizeof(**sigar));
(*sigar)->getvminfo = vminfo;
(*sigar)->getprocfd = NULL; /*XXX*/ (*sigar)->getprocfd = NULL; /*XXX*/
(*sigar)->kmem = kmem; (*sigar)->kmem = kmem;
(*sigar)->dmem = -1; (*sigar)->dmem = -1;
@ -383,6 +374,23 @@ static int sigar_perfstat_init(sigar_t *sigar)
return ENOENT; return ENOENT;
} }
sigar->perfstat.mem =
(perfstat_mem_func_t)dlsym(handle,
"sigar_perfstat_memory");
if (!sigar->perfstat.mem) {
if (SIGAR_LOG_IS_DEBUG(sigar)) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"dlsym(sigar_perfstat_memory) failed: %s",
dlerror());
}
dlclose(handle);
sigar->perfstat.avail = -1;
return ENOENT;
}
sigar->perfstat.disk = sigar->perfstat.disk =
(perfstat_disk_func_t)dlsym(handle, (perfstat_disk_func_t)dlsym(handle,
"sigar_perfstat_disk"); "sigar_perfstat_disk");
@ -428,23 +436,25 @@ static int sigar_perfstat_init(sigar_t *sigar)
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
{ {
struct vminfo vm; int status;
#if 0 if (sigar_perfstat_init(sigar) == SIGAR_OK) {
/* XXX: wtf, this is supposed to be a modern way perfstat_memory_total_t minfo;
* to get the same values below. yet it works on 4.3.3
* but not 5.1 sigar_log(sigar, SIGAR_LOG_DEBUG, "[mem] using libperfstat");
*/
if (!sigar->getvminfo) { if (sigar->perfstat.mem(&minfo) == 1) {
return EPERM; mem->total = PAGESHIFT(minfo.real_total);
mem->free = PAGESHIFT(minfo.real_free);
} }
else {
if (sigar->getvminfo(&vm, VMINFO, sizeof(vm)) != 0) {
return errno; return errno;
} }
}
else {
struct vminfo vm;
#else sigar_log(sigar, SIGAR_LOG_DEBUG, "[mem] using /dev/kmem");
int status;
status = kread(sigar, &vm, sizeof(vm), status = kread(sigar, &vm, sizeof(vm),
sigar->koffsets[KOFFSET_VMINFO]); sigar->koffsets[KOFFSET_VMINFO]);
@ -452,10 +462,11 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
return status; return status;
} }
#endif
mem->total = PAGESHIFT(vm.memsizepgs); /* lsattr -El sys0 -a realmem */ mem->total = PAGESHIFT(vm.memsizepgs); /* lsattr -El sys0 -a realmem */
mem->free = PAGESHIFT(vm.numfrb); mem->free = PAGESHIFT(vm.numfrb);
}
mem->used = mem->total - mem->free; mem->used = mem->total - mem->free;
mem->actual_used = mem->used; mem->actual_used = mem->used;
mem->actual_free = mem->free; mem->actual_free = mem->free;

View File

@ -44,8 +44,6 @@ typedef struct {
char **devs; char **devs;
} swaps_t; } swaps_t;
typedef int (*vminfo_func_t) (void *, int, int);
typedef int (*proc_fd_func_t) (sigar_t *, sigar_pid_t, sigar_proc_fd_t *); typedef int (*proc_fd_func_t) (sigar_t *, sigar_pid_t, sigar_proc_fd_t *);
typedef int (*perfstat_cpu_total_func_t)(perfstat_cpu_total_t *); typedef int (*perfstat_cpu_total_func_t)(perfstat_cpu_total_t *);
@ -58,6 +56,8 @@ typedef int (*perfstat_swap_func_t)(perfstat_id_t *,
perfstat_pagingspace_t *, perfstat_pagingspace_t *,
int); int);
typedef int (*perfstat_mem_func_t)(perfstat_memory_total_t *);
typedef int (*perfstat_disk_func_t)(perfstat_id_t *, typedef int (*perfstat_disk_func_t)(perfstat_id_t *,
perfstat_disk_t *, perfstat_disk_t *,
int); int);
@ -73,13 +73,13 @@ struct sigar_t {
int dmem; int dmem;
/* offsets for seeking on kmem */ /* offsets for seeking on kmem */
long koffsets[KOFFSET_MAX]; long koffsets[KOFFSET_MAX];
vminfo_func_t getvminfo;
proc_fd_func_t getprocfd; proc_fd_func_t getprocfd;
struct { struct {
int avail; int avail;
perfstat_cpu_func_t cpu; perfstat_cpu_func_t cpu;
perfstat_cpu_total_func_t cpu_total; perfstat_cpu_total_func_t cpu_total;
perfstat_swap_func_t swap; perfstat_swap_func_t swap;
perfstat_mem_func_t mem;
perfstat_disk_func_t disk; perfstat_disk_func_t disk;
perfstat_ifstat_func_t ifstat; perfstat_ifstat_func_t ifstat;
thread_rusage_func_t thread_rusage; thread_rusage_func_t thread_rusage;