/*
* @(#)$Header: memdetail.c,v 1.1 2001/05/03 15:35:00 nsr1521 Exp $
*
* determine detailed current memory utilized and print.
*
* No warranty is expressed or implied.
* Your mileage may vary.
*
* Contact: srobertson@bcbs-ga.com
*
*/
static char ident[] = "@(#)$Revision: 1.1 $";
#define KB 1024
#include <unistd.h>
#include <sys/param.h>
#include <sys/pstat.h>
main() {
struct pst_static sbuf;
struct pst_dynamic dbuf;
struct pst_vminfo vbuf;
double page_size, sys_mem;
double phys_mem, used_phys_mem, avail_mem;
double total_virtual_mem, active_virtual_mem, avail_virtual_mem;
double total_real_mem, active_real_mem, avail_real_mem;
double total_swap_dev, used_swap_dev, avail_swap_dev;
double total_swap_mem, used_swap_mem, avail_swap_mem;
/* get static information about the system */
if (pstat_getstatic(&sbuf, sizeof(sbuf), (size_t)1, 0) != -1)
{
phys_mem = sbuf.physical_memory;
page_size = sbuf.page_size;
}
else
perror("pstat_getstatic()");
/* get dynamic information about the system */
if (pstat_getdynamic(&dbuf, sizeof(dbuf), (size_t)1, 0) != -1)
{
avail_mem = dbuf.psd_free;
total_virtual_mem = dbuf.psd_vm;
active_virtual_mem = dbuf.psd_avm;
total_real_mem = dbuf.psd_rm;
active_real_mem = dbuf.psd_arm;
}
else
perror("pstat_getdynamic()");
/* get VM information about the system */
if (pstat_getvminfo(&vbuf, sizeof(vbuf), (size_t)1, 0) != -1)
{
sys_mem = vbuf.psv_sysmem;
total_swap_dev = vbuf.psv_swapspc_max;
avail_swap_dev = vbuf.psv_swapspc_cnt;
total_swap_mem = vbuf.psv_swapmem_max;
avail_swap_mem = vbuf.psv_swapmem_cnt;
}
else
perror("pstat_getvminfo()");
/* calculate used physical memory */
used_phys_mem = phys_mem - avail_mem;
/* calculate avail virtual memory */
avail_virtual_mem = total_virtual_mem - active_virtual_mem;
/* calculate avail real memory */
avail_real_mem = total_real_mem - active_real_mem;
/* calculate used swap on device */
used_swap_dev = total_swap_dev - avail_swap_dev;
/* calculate used swap on memory */
used_swap_mem = total_swap_mem - avail_swap_mem;
(void)printf("%-15s\t%6s\t%6s\t%6s\t%6s\n",
"Memory Stat","total","used","avail","%used");
(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"physical",
(phys_mem * page_size) / (KB * KB),
(used_phys_mem * page_size) / (KB * KB),
(avail_mem * page_size) / (KB * KB),
used_phys_mem * 100 / phys_mem);
(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"active virtual",
(total_virtual_mem * page_size) / (KB * KB),
(active_virtual_mem * page_size) / (KB * KB),
(avail_virtual_mem * page_size) / (KB * KB),
active_virtual_mem * 100 / total_virtual_mem);
(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"active real",
(total_real_mem * page_size) / (KB * KB),
(active_real_mem * page_size) / (KB * KB),
(avail_real_mem * page_size) / (KB * KB),
active_real_mem * 100 / total_real_mem);
(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"memory swap",
(total_swap_mem * page_size) / (KB * KB),
(used_swap_mem * page_size) / (KB * KB),
(avail_swap_mem * page_size) / (KB * KB),
used_swap_mem * 100 / total_swap_mem);
(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"device swap",
(total_swap_dev * page_size) / (KB * KB),
(used_swap_dev * page_size) / (KB * KB),
(avail_swap_dev * page_size) / (KB * KB),
used_swap_dev * 100 / total_swap_dev);
return;
}
Monday, September 10, 2007
HPUX Mem Info C Code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment