casa
$Rev:20696$
|
00001 //# HostInfo.h: Miscellaneous information about this host and process. 00002 //# Copyright (C) 1997,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: HostInfo.h 20891 2010-05-17 07:10:15Z gervandiepen $ 00028 00029 #ifndef CASA_HOSTINFO_H 00030 #define CASA_HOSTINFO_H 00031 00032 #include <casa/aips.h> 00033 #include <cstring> 00034 #include <unistd.h> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 class String; 00039 class HostMachineInfo; 00040 00041 // <summary> 00042 // Miscellaneous information about this host and process. 00043 // </summary> 00044 00045 // <use visibility=export> 00046 00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00048 // </reviewed> 00049 00050 // <prerequisite> 00051 // <li> None 00052 // </prerequisite> 00053 // 00054 // <synopsis> 00055 // This class is meant to encapsulate miscellaneous information about the 00056 // environment that the current process is running in. 00057 // 00058 // At present, the class can be used to obtain the name of the host on which 00059 // this process is running, the process id of this process, the amount of 00060 // physical memory (total, used, & free) on this host, the amount of swap 00061 // space (total, used, and free), the number of CPUs on this host, and a 00062 // count of the number of seconds from January 1, 1970. Generally you 00063 // should use the classes <linkto class=Time>Time</linkto> and 00064 // <linkto class=MVTime>MVTime</linkto> if your primary interest is related 00065 // to time and dates. If your interest is in timing, you would generally use 00066 // class <linkto class=Timer>Timer</linkto>, which can also report CPU times 00067 // as well as "clock" times. 00068 // 00069 // Determination of the number of CPUs, swap space, and physical memory is 00070 // particularly OS dependent. In cases where this functionality has not yet 00071 // been implemented, the memory and swap functions will return -1 and the 00072 // CPU function will return 0. 00073 // </synopsis> 00074 // 00075 // <example> 00076 // <srcblock> 00077 // cout << "I am process #" << HostInfo::processID() << " running on host " << 00078 // HostInfo::hostName() << ", which has " << HostInfor::numCPUs( ) << " CPUs." << endl; 00079 // cout << "This host has " << HostInfo::memoryTotal( ) << "K of memory [ " << 00080 // HostInfo::memoryUsed( ) << " used, " << 00081 // HostInfo::memoryFree( ) << " free ]." << endl; 00082 // cout << "This host has " << HostInfo::swapTotal( ) << "K of swap space [ " << 00083 // HostInfo::swapUsed( ) << " used, " << 00084 // HostInfo::swapFree( ) << " free ]." << endl; 00085 // Double now = HostInfo::secondsFrom1970(); 00086 // doSomething(); 00087 // cout << "Function doSomething() took " << 00088 // HostInfo::secondsFrom1970() - now << " seconds to execute." << endl; 00089 // </srcblock> 00090 // </example> 00091 // 00092 // <motivation> 00093 // The <linkto class=ObjectID>ObjectID</linkto> class uses a combination of 00094 // hostname, process id, time, and a sequence number to ensure that ObjectID's 00095 // are distinct. This class encapsulates the way the first three of those items 00096 // are obtained. 00097 // </motivation> 00098 // 00099 // <todo asof="2002/08/01"> 00100 // <li> OS version? 00101 // </todo> 00102 00103 class HostInfo 00104 { 00105 public: 00106 00107 static String hostName(); 00108 static Int processID(); 00109 static Double secondsFrom1970(); 00110 00111 // Returns True for big endian machines (like SUN). 00112 // Returns False for little endian machines (like PC). 00113 static Bool bigEndian(); 00114 00115 // Returns 0 if unable to determine the number of CPUs. 00116 static Int numCPUs(bool use_aipsrc=false); 00117 00118 // Get memory info (in KBytes). 00119 // Returns -1 if unable to determine memory info. 00120 // <group> 00121 static ssize_t memoryTotal(bool use_aipsrc=false); 00122 static ssize_t memoryUsed(); 00123 static ssize_t memoryFree(); 00124 // </group> 00125 00126 // Get swap space info (in KBytes). 00127 // Returns -1 if unable to determine swap info. 00128 // <group> 00129 static ssize_t swapTotal(); 00130 static ssize_t swapUsed(); 00131 static ssize_t swapFree(); 00132 // </group> 00133 00134 private: 00135 // we don't want folks creating these... 00136 HostInfo( ); 00137 const HostInfo &operator=( const HostInfo & ); 00138 00139 static HostMachineInfo *info; 00140 }; 00141 00142 00143 inline Bool HostInfo::bigEndian() 00144 { 00145 #if defined(AIPS_LITTLE_ENDIAN) 00146 return False; 00147 #else 00148 return True; 00149 #endif 00150 } 00151 00152 00153 00154 } //# NAMESPACE CASA - END 00155 00156 #endif