casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
HostInfoHpux.h
Go to the documentation of this file.
00001 //# HostInfo_hpux.h: HP/UX specific memory, swap, and CPU code.
00002 //# $Id: HostInfoHpux.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
00003 
00004  /*
00005  **  This is a greatly MODIFIED version of a "top" machine dependent file.
00006  **  The only resemblance it bears to the original is with respect to the
00007  **  mechanics of finding various system details. The copyright details
00008  **  follow.
00009  **
00010  **  --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
00011  **
00012  **  Top users/processes display for Unix
00013  **  Version 3
00014  **
00015  **  This program may be freely redistributed,
00016  **  but this entire comment MUST remain intact.
00017  **
00018  **  Copyright (c) 1984, 1989, William LeFebvre, Rice University
00019  **  Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University
00020  **  Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory
00021  **  Copyright (c) 1996, William LeFebvre, Group sys Consulting
00022  **  Copyright (c) 2002, Associated Universities Inc.
00023  */
00024 
00025 #ifndef CASA_HOSTINFOHPUX_H
00026 #define CASA_HOSTINFOHPUX_H
00027 
00028 # if defined(HOSTINFO_DO_IMPLEMENT)
00029 
00030 /*
00031  *          AUTHOR:       Darrell Schiebel  <drs@nrao.edu>
00032  *
00033  * ORIGINAL AUTHOR:       John Haxby        <john_haxby@hp.com>
00034  * ORIGINAL CONTRIBUTORS: Rich Holland      <holland@synopsys.com>
00035  *                        Kevin Schmidt     <kevin@mcl.ucsb.edu> 
00036  */
00037 
00038 #include <stdio.h>
00039 #include <errno.h>
00040 #include <stdlib.h>
00041 #include <unistd.h>
00042 #include <sys/param.h>
00043 #include <sys/pstat.h>
00044 
00045 namespace casa { //# NAMESPACE CASA - BEGIN
00046 
00047 // <summary>
00048 // HostInfo for HP-UX machines.
00049 // </summary>
00050 
00051 // <use visibility=local>
00052 
00053 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00054 // </reviewed>
00055 
00056 // <prerequisite>
00057 //   <li> <linkto class=HostInfo>HostInfo</linkto>
00058 // </prerequisite>
00059 
00060 // <synopsis> 
00061 // This file provides the HP-UX specific functions for HostInfo.
00062 // It is selectively included by HostInfo.cc.
00063 // </synopsis>
00064 //
00065 // <group name="HostInfo">
00066 
00067 /* these are for getting the memory statistics */
00068 
00069 /* Log base 2 of 1024 is 10 (2^10 == 1024) */
00070 #define LOG1024         10
00071 
00072 /* define pagetok in terms of pageshift */
00073 #define pagetok(size) ((size) << pageshift)
00074 
00075 class HostMachineInfo {
00076 friend class HostInfo;
00077 
00078     HostMachineInfo( );
00079     void update_info( );
00080 
00081     int valid;
00082     int cpus;
00083 
00084     ssize_t swap_total;
00085     ssize_t swap_used;
00086     ssize_t swap_free;
00087 
00088     ssize_t memory_total;
00089     ssize_t memory_used;
00090     ssize_t memory_free;
00091 
00092     int pageshift;              /* log base 2 of the pagesize */
00093 };
00094 
00095 // </group>
00096 
00097 
00098 HostMachineInfo::HostMachineInfo( ) :valid(1) {
00099 
00100     struct pst_static info;
00101     int pagesize;
00102 
00103     if (pstat_getstatic (&info, sizeof (info), 1, 0) < 0) {
00104         perror ("pstat_getstatic");
00105         valid = 0;
00106     }
00107 
00108     /*
00109      * Calculate pageshift -- the value needed to convert pages to Kbytes.
00110      * This will usually be 2.
00111      */
00112     pageshift = 0;
00113     for (pagesize = info.page_size; pagesize > 1; pagesize >>= 1)
00114         pageshift += 1;
00115     pageshift -= LOG1024;
00116 
00117     static struct pst_dynamic dynamic;
00118 
00119     pstat_getdynamic (&dynamic, sizeof (dynamic), 1, 0);
00120     cpus = dynamic.psd_proc_cnt;
00121     memory_total = pagetok (dynamic.psd_rm);
00122 }
00123 
00124 void HostMachineInfo::update_info( ) {
00125 
00126     static struct pst_dynamic dynamic;
00127 
00128     pstat_getdynamic (&dynamic, sizeof (dynamic), 1, 0);
00129     memory_used = pagetok (dynamic.psd_arm);
00130     memory_free = memory_total - memory_used;
00131     swap_total = pagetok (dynamic.psd_vm);
00132     swap_used = pagetok (dynamic.psd_avm);
00133     swap_free = swap_total - swap_used;
00134 }
00135 
00136 # endif
00137 
00138 } //# NAMESPACE CASA - END
00139 
00140 #endif