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

View File

@ -44,8 +44,6 @@ typedef struct {
char **devs;
} 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 (*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 *,
int);
typedef int (*perfstat_mem_func_t)(perfstat_memory_total_t *);
typedef int (*perfstat_disk_func_t)(perfstat_id_t *,
perfstat_disk_t *,
int);
@ -73,13 +73,13 @@ struct sigar_t {
int dmem;
/* offsets for seeking on kmem */
long koffsets[KOFFSET_MAX];
vminfo_func_t getvminfo;
proc_fd_func_t getprocfd;
struct {
int avail;
perfstat_cpu_func_t cpu;
perfstat_cpu_total_func_t cpu_total;
perfstat_swap_func_t swap;
perfstat_mem_func_t mem;
perfstat_disk_func_t disk;
perfstat_ifstat_func_t ifstat;
thread_rusage_func_t thread_rusage;