casacore
HostInfo.h
Go to the documentation of this file.
1 //# HostInfo.h: Miscellaneous information about this host and process.
2 //# Copyright (C) 1997,2002
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef CASA_HOSTINFO_H
30 #define CASA_HOSTINFO_H
31 
32 #include <casacore/casa/aips.h>
33 #include <cstring>
34 #include <cstddef>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 class String;
39 class HostMachineInfo;
40 
41 // <summary>
42 // Miscellaneous information about this host and process.
43 // </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> None
52 // </prerequisite>
53 //
54 // <synopsis>
55 // This class is meant to encapsulate miscellaneous information about the
56 // environment that the current process is running in.
57 //
58 // At present, the class can be used to obtain the name of the host on which
59 // this process is running, the process id of this process, the amount of
60 // physical memory (total, used, & free) on this host, the amount of swap
61 // space (total, used, and free), the number of CPUs on this host, and a
62 // count of the number of seconds from January 1, 1970. Generally you
63 // should use the classes <linkto class=Time>Time</linkto> and
64 // <linkto class=MVTime>MVTime</linkto> if your primary interest is related
65 // to time and dates. If your interest is in timing, you would generally use
66 // class <linkto class=Timer>Timer</linkto>, which can also report CPU times
67 // as well as "clock" times.
68 //
69 // Determination of the number of CPUs, swap space, and physical memory is
70 // particularly OS dependent. In cases where this functionality has not yet
71 // been implemented, the memory and swap functions will return -1 and the
72 // CPU function will return 0.
73 // </synopsis>
74 //
75 // <example>
76 // <srcblock>
77 // cout << "I am process #" << HostInfo::processID() << " running on host " <<
78 // HostInfo::hostName() << ", which has " << HostInfor::numCPUs( ) << " CPUs." << endl;
79 // cout << "This host has " << HostInfo::memoryTotal( ) << "K of memory [ " <<
80 // HostInfo::memoryUsed( ) << " used, " <<
81 // HostInfo::memoryFree( ) << " free ]." << endl;
82 // cout << "This host has " << HostInfo::swapTotal( ) << "K of swap space [ " <<
83 // HostInfo::swapUsed( ) << " used, " <<
84 // HostInfo::swapFree( ) << " free ]." << endl;
85 // Double now = HostInfo::secondsFrom1970();
86 // doSomething();
87 // cout << "Function doSomething() took " <<
88 // HostInfo::secondsFrom1970() - now << " seconds to execute." << endl;
89 // </srcblock>
90 // </example>
91 //
92 // <motivation>
93 // The <linkto class=ObjectID>ObjectID</linkto> class uses a combination of
94 // hostname, process id, time, and a sequence number to ensure that ObjectID's
95 // are distinct. This class encapsulates the way the first three of those items
96 // are obtained.
97 // </motivation>
98 //
99 // <todo asof="2002/08/01">
100 // <li> OS version?
101 // </todo>
102 
103 class HostInfo
104 {
105 public:
106 
107  static String hostName();
108  static Int processID();
110 
111  // Returns True for big endian machines (like SUN).
112  // Returns False for little endian machines (like PC).
113  static Bool bigEndian();
114 
115  // Returns 0 if unable to determine the number of CPUs.
116  static Int numCPUs(bool use_aipsrc=false);
117 
118  // Get memory info (in KBytes).
119  // Returns -1 if unable to determine memory info.
120  // <group>
121  static ptrdiff_t memoryTotal(bool use_aipsrc=false);
122  static ptrdiff_t memoryUsed();
123  static ptrdiff_t memoryFree();
124  // </group>
125 
126  // Get swap space info (in KBytes).
127  // Returns -1 if unable to determine swap info.
128  // <group>
129  static ptrdiff_t swapTotal();
130  static ptrdiff_t swapUsed();
131  static ptrdiff_t swapFree();
132  // </group>
133 
134  // Allows to set custom resource values overriding the
135  // existing .apisrc setting and/or system defaults
136  // Expected unit are KiB for memory total
137  // and percentage (%) for memory fraction
138  // Returns the value previously stored
139  // <group>
140  static ptrdiff_t setMemoryTotal(ptrdiff_t memory);
141  static Int setMemoryFraction(Int memfrac);
143  // </group>
144 
145 private:
146  // we don't want folks creating these...
148  const HostInfo &operator=( const HostInfo & );
149 
150  static HostMachineInfo *info;
151  static ptrdiff_t resources_memory;
154 };
155 
156 
158 {
159 #if defined(AIPS_LITTLE_ENDIAN)
160  return False;
161 #else
162  return True;
163 #endif
164 }
165 
166 
167 
168 } //# NAMESPACE CASACORE - END
169 
170 #endif
static Int processID()
const HostInfo & operator=(const HostInfo &)
static ptrdiff_t swapFree()
static Int resources_memfrac
Definition: HostInfo.h:152
static ptrdiff_t swapTotal()
Get swap space info (in KBytes).
static HostMachineInfo * info
Definition: HostInfo.h:150
static Double secondsFrom1970()
static Int setMemoryFraction(Int memfrac)
static ptrdiff_t memoryFree()
static Bool bigEndian()
Returns True for big endian machines (like SUN).
Definition: HostInfo.h:157
static ptrdiff_t resources_memory
Definition: HostInfo.h:151
static ptrdiff_t swapUsed()
static ptrdiff_t setMemoryTotal(ptrdiff_t memory)
Allows to set custom resource values overriding the existing.apisrc setting and/or system defaults Ex...
HostInfo()
we don't want folks creating these...
static Int setNumCPUs(Int numCPUs)
static ptrdiff_t memoryTotal(bool use_aipsrc=false)
Get memory info (in KBytes).
static Int numCPUs(bool use_aipsrc=false)
Returns 0 if unable to determine the number of CPUs.
static Int resources_numCPUs
Definition: HostInfo.h:153
static ptrdiff_t memoryUsed()
static String hostName()
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55