HostInfo.h

Go to the documentation of this file.
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$
00028 
00029 #ifndef CASA_HOSTINFO_H
00030 #define CASA_HOSTINFO_H
00031 
00032 #include <casacore/casa/aips.h>
00033 #include <cstring>
00034 #include <cstddef>
00035 
00036 namespace casacore { //# NAMESPACE CASACORE - 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 ptrdiff_t memoryTotal(bool use_aipsrc=false);
00122     static ptrdiff_t memoryUsed();
00123     static ptrdiff_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 ptrdiff_t swapTotal();
00130     static ptrdiff_t swapUsed();
00131     static ptrdiff_t swapFree();
00132     // </group>
00133 
00134     // Allows to set custom resource values overriding the
00135     // existing .apisrc setting and/or system defaults
00136     // Expected unit are KiB for memory total
00137     // and percentage (%) for memory fraction
00138     // Returns the value previously stored
00139     // <group>
00140     static ptrdiff_t setMemoryTotal(ptrdiff_t memory);
00141     static Int setMemoryFraction(Int memfrac);
00142     static Int setNumCPUs(Int numCPUs);
00143     // </group>
00144 
00145 private:
00146     // we don't want folks creating these...
00147     HostInfo( );
00148     const HostInfo &operator=( const HostInfo & );
00149 
00150     static HostMachineInfo *info;
00151     static ptrdiff_t resources_memory;
00152     static Int resources_memfrac;
00153     static Int resources_numCPUs;
00154 };
00155 
00156 
00157 inline Bool HostInfo::bigEndian()
00158 {
00159 #if defined(AIPS_LITTLE_ENDIAN)
00160     return False;
00161 #else
00162     return True;
00163 #endif
00164 }
00165 
00166 
00167 
00168 } //# NAMESPACE CASACORE - END
00169 
00170 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1