casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef CASA_HOSTINFO_H
27#define CASA_HOSTINFO_H
28
29#include <casacore/casa/aips.h>
30#include <cstring>
31#include <cstddef>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35class String;
36class HostMachineInfo;
37
38// <summary>
39// Miscellaneous information about this host and process.
40// </summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> None
49// </prerequisite>
50//
51// <synopsis>
52// This class is meant to encapsulate miscellaneous information about the
53// environment that the current process is running in.
54//
55// At present, the class can be used to obtain the name of the host on which
56// this process is running, the process id of this process, the amount of
57// physical memory (total, used, & free) on this host, the amount of swap
58// space (total, used, and free), the number of CPUs on this host, and a
59// count of the number of seconds from January 1, 1970. Generally you
60// should use the classes <linkto class=Time>Time</linkto> and
61// <linkto class=MVTime>MVTime</linkto> if your primary interest is related
62// to time and dates. If your interest is in timing, you would generally use
63// class <linkto class=Timer>Timer</linkto>, which can also report CPU times
64// as well as "clock" times.
65//
66// Determination of the number of CPUs, swap space, and physical memory is
67// particularly OS dependent. In cases where this functionality has not yet
68// been implemented, the memory and swap functions will return -1 and the
69// CPU function will return 0.
70// </synopsis>
71//
72// <example>
73// <srcblock>
74// cout << "I am process #" << HostInfo::processID() << " running on host " <<
75// HostInfo::hostName() << ", which has " << HostInfor::numCPUs( ) << " CPUs." << endl;
76// cout << "This host has " << HostInfo::memoryTotal( ) << "K of memory [ " <<
77// HostInfo::memoryUsed( ) << " used, " <<
78// HostInfo::memoryFree( ) << " free ]." << endl;
79// cout << "This host has " << HostInfo::swapTotal( ) << "K of swap space [ " <<
80// HostInfo::swapUsed( ) << " used, " <<
81// HostInfo::swapFree( ) << " free ]." << endl;
82// Double now = HostInfo::secondsFrom1970();
83// doSomething();
84// cout << "Function doSomething() took " <<
85// HostInfo::secondsFrom1970() - now << " seconds to execute." << endl;
86// </srcblock>
87// </example>
88//
89// <motivation>
90// The <linkto class=ObjectID>ObjectID</linkto> class uses a combination of
91// hostname, process id, time, and a sequence number to ensure that ObjectID's
92// are distinct. This class encapsulates the way the first three of those items
93// are obtained.
94// </motivation>
95//
96// <todo asof="2002/08/01">
97// <li> OS version?
98// </todo>
99
100class HostInfo {
101 public:
102 static String hostName();
103 static Int processID();
105
106 // Returns True for big endian machines (like SUN).
107 // Returns False for little endian machines (like PC).
108 static Bool bigEndian();
109
110 // Returns 0 if unable to determine the number of CPUs.
111 static Int numCPUs(bool use_aipsrc = false);
112
113 // Get memory info (in KBytes).
114 // Returns -1 if unable to determine memory info.
115 // <group>
116 static ptrdiff_t memoryTotal(bool use_aipsrc = false);
117 static ptrdiff_t memoryUsed();
118 static ptrdiff_t memoryFree();
119 // </group>
120
121 // Get swap space info (in KBytes).
122 // Returns -1 if unable to determine swap info.
123 // <group>
124 static ptrdiff_t swapTotal();
125 static ptrdiff_t swapUsed();
126 static ptrdiff_t swapFree();
127 // </group>
128
129 // Allows to set custom resource values overriding the
130 // existing .apisrc setting and/or system defaults
131 // Expected unit are KiB for memory total
132 // and percentage (%) for memory fraction
133 // Returns the value previously stored
134 // <group>
135 static ptrdiff_t setMemoryTotal(ptrdiff_t memory);
136 static Int setMemoryFraction(Int memfrac);
138 // </group>
139
140 private:
141 // we don't want folks creating these...
143 const HostInfo &operator=(const HostInfo &);
144
145 static HostMachineInfo *info;
146 static ptrdiff_t resources_memory;
149};
150
152#if defined(AIPS_LITTLE_ENDIAN)
153 return False;
154#else
155 return True;
156#endif
157}
158
159} // namespace casacore
160
161#endif
static Int processID()
const HostInfo & operator=(const HostInfo &)
static ptrdiff_t swapFree()
static Int resources_memfrac
Definition HostInfo.h:147
static ptrdiff_t swapTotal()
Get swap space info (in KBytes).
static HostMachineInfo * info
Definition HostInfo.h:145
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:151
static ptrdiff_t resources_memory
Definition HostInfo.h:146
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:148
static ptrdiff_t memoryUsed()
static String hostName()
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53