casa
$Rev:20696$
|
00001 //# HostInfo_irix.h: SGI Irix specific memory, swap, and CPU code. 00002 //# $Id: HostInfoIrix.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_HOSTINFOIRIX_H 00026 #define CASA_HOSTINFOIRIX_H 00027 00028 # if defined(HOSTINFO_DO_IMPLEMENT) 00029 00030 /* 00031 * AUTHOR: Darrell Schiebel <drs@nrao.edu> 00032 * 00033 * ORIGINAL AUTHORS: Sandeep Cariapa <cariapa@sgi.com> 00034 * Larry McVoy <lm@sgi.com> 00035 * John Schimmel <jes@sgi.com> 00036 * Ariel Faigon <ariel@sgi.com> 00037 */ 00038 00039 #include <stdio.h> 00040 #include <stdlib.h> 00041 #include <sys/types.h> 00042 #include <unistd.h> 00043 #include <sys/stat.h> 00044 #include <sys/swap.h> 00045 #include <sys/sysmp.h> 00046 #include <sys/sysinfo.h> 00047 00048 namespace casa { //# NAMESPACE CASA - BEGIN 00049 00050 // <summary> 00051 // HostInfo for IRIX machines. 00052 // </summary> 00053 00054 // <use visibility=local> 00055 00056 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00057 // </reviewed> 00058 00059 // <prerequisite> 00060 // <li> <linkto class=HostInfo>HostInfo</linkto> 00061 // </prerequisite> 00062 00063 // <synopsis> 00064 // This file provides the IRIX specific functions for HostInfo. 00065 // It is selectively included by HostInfo.cc. 00066 // </synopsis> 00067 // 00068 // <group name="HostInfo"> 00069 00070 #define pagetok(pages) ((((uint64_t) pages) * pagesize) >> 10) 00071 00072 class HostMachineInfo { 00073 friend class HostInfo; 00074 00075 HostMachineInfo( ); 00076 void update_info( ); 00077 00078 int valid; 00079 int cpus; 00080 00081 ssize_t swap_total; 00082 ssize_t swap_used; 00083 ssize_t swap_free; 00084 00085 ssize_t memory_total; 00086 ssize_t memory_used; 00087 ssize_t memory_free; 00088 00089 ssize_t pagesize; 00090 00091 }; 00092 00093 // </group> 00094 00095 00096 HostMachineInfo::HostMachineInfo( ) : valid(1) { 00097 00098 pagesize = getpagesize(); 00099 00100 if ((cpus = sysmp(MP_NPROCS)) == -1) { 00101 perror("sysmp(MP_NPROCS)"); 00102 valid = 0; 00103 return; 00104 } 00105 00106 struct rminfo realmem; 00107 if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) { 00108 perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)"); 00109 valid = 0; 00110 return; 00111 } 00112 00113 memory_total = pagetok(realmem.physmem); 00114 } 00115 00116 void HostMachineInfo::update_info( ) { 00117 int i; 00118 struct rminfo realmem; 00119 struct sysinfo sysinfo; 00120 off_t fswap; /* current free swap in blocks */ 00121 off_t tswap; /* total swap in blocks */ 00122 00123 swapctl(SC_GETFREESWAP, &fswap); 00124 swapctl(SC_GETSWAPTOT, &tswap); 00125 00126 if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) { 00127 perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)"); 00128 valid = 0; 00129 return; 00130 } 00131 00132 memory_free = pagetok(realmem.freemem); 00133 memory_used = memory_total - memory_free; 00134 swap_total = tswap / 2; 00135 swap_free = fswap / 2; 00136 swap_used = swap_total - swap_free; 00137 } 00138 00139 # endif 00140 00141 } //# NAMESPACE CASA - END 00142 00143 #endif