/* * mem_details.c * * HP-UX 10.20 & 11.00 verified * Scott Robertson * $Revision: 1.2 $ * $Date: 2001/07/19 11:47:15 $ * * This program is subject to change without notice. * No warranty is expressed or implied. * Your mileage may vary. * * Usage: mem_details * * Compile: cc +DD32 -D_PSTAT64 mem_details.c -o mem_details * * Added some more details - March 28, 2008 (dmorris) * */ static char ident[] = "@(#)mem_details.c $Revision: 1.2.1 $"; #define KB 1024 #define ONEGIG (1024L*1024L*1024L) #include /* assert() */ #include #include #include #include /* pstat() [duh] */ #define LOWER_SIZE_PCT_LIM 0.00001 #ifdef __LP64__ #define ULONG_SPEC "%lu" #else /* !__LP64__ */ #define ULONG_SPEC "%llu" #endif /* __LP64__ */ size_t sys_page_size; void usage(char *pname) { assert(pname != NULL); printf("Usage: %s \n", pname); exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { struct pst_static sbuf; struct pst_dynamic dbuf; struct pst_vminfo vbuf; double page_size, swapmem_on; 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; char *buff; int ret, err; struct rlimit rlim_d; _T_LONG_T original_swap_reclaims = 0; int idx = 0; int32_t loops = 1; int32_t secs = 1; sys_page_size = sysconf(_SC_PAGE_SIZE); if ( argc > 3 ) { usage(argv[0]); } if ( argc >= 2 ) { loops = atoi(argv[1]); } if ( argc == 3 ) { secs = atoi(argv[2]); } /* * Report loop */ if (pstat_getvminfo(&vbuf, sizeof(vbuf), (size_t)1, 0) != -1) { original_swap_reclaims = vbuf.psv_spgrec; } while ( loops-- ) { /* * get static information about the system * [Note: This is loop interior since physical_memory can change * on v3 and later... static is no longer static] */ 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) { swapmem_on = vbuf.psv_swapmem_on; 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; printf("%-15s\t%6s\t%6s\t%6s\t%6s\n", "Memory Stat","total","used","avail","%used"); 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); 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); 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); if (swapmem_on) { 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); } 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); printf("Activations: " ULONG_SPEC " total, " ULONG_SPEC " rate. \tDeactivations: " ULONG_SPEC " total, " ULONG_SPEC " rate.\n", vbuf.psv_spswpin, vbuf.psv_rswpin, vbuf.psv_spswpout, vbuf.psv_rswpout); printf("Reclaims from Swap: " ULONG_SPEC " total (Up " ULONG_SPEC "), " ULONG_SPEC " rate.\n", vbuf.psv_spgrec, (vbuf.psv_spgrec - original_swap_reclaims), vbuf.psv_rpgrec); if ( vbuf.psv_rswpout && !vbuf.psv_rswpin ) { printf("WARNING: Possible memory pressure.\n" "\tDeactivation (Swap Out) with no Swap ins\n"); } if ( (avail_swap_dev + avail_swap_mem) * sys_page_size <= (ONEGIG/8L) ) { printf("WARNING: Swap space low.\n"); } if ( loops ) { sleep(secs); } } exit(EXIT_SUCCESS); }