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
101{
102public:
103
104 static String hostName();
105 static Int processID();
107
108 // Returns True for big endian machines (like SUN).
109 // Returns False for little endian machines (like PC).
110 static Bool bigEndian();
111
112 // Returns 0 if unable to determine the number of CPUs.
113 static Int numCPUs(bool use_aipsrc=false);
114
115 // Get memory info (in KBytes).
116 // Returns -1 if unable to determine memory info.
117 // <group>
118 static ptrdiff_t memoryTotal(bool use_aipsrc=false);
119 static ptrdiff_t memoryUsed();
120 static ptrdiff_t memoryFree();
121 // </group>
122
123 // Get swap space info (in KBytes).
124 // Returns -1 if unable to determine swap info.
125 // <group>
126 static ptrdiff_t swapTotal();
127 static ptrdiff_t swapUsed();
128 static ptrdiff_t swapFree();
129 // </group>
130
131 // Allows to set custom resource values overriding the
132 // existing .apisrc setting and/or system defaults
133 // Expected unit are KiB for memory total
134 // and percentage (%) for memory fraction
135 // Returns the value previously stored
136 // <group>
137 static ptrdiff_t setMemoryTotal(ptrdiff_t memory);
138 static Int setMemoryFraction(Int memfrac);
140 // </group>
141
142private:
143 // we don't want folks creating these...
145 const HostInfo &operator=( const HostInfo & );
146
147 static HostMachineInfo *info;
148 static ptrdiff_t resources_memory;
151};
152
153
155{
156#if defined(AIPS_LITTLE_ENDIAN)
157 return False;
158#else
159 return True;
160#endif
161}
162
163
164
165} //# NAMESPACE CASACORE - END
166
167#endif
static Int processID()
const HostInfo & operator=(const HostInfo &)
static ptrdiff_t swapFree()
static Int resources_memfrac
Definition HostInfo.h:149
static ptrdiff_t swapTotal()
Get swap space info (in KBytes).
static HostMachineInfo * info
Definition HostInfo.h:147
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:154
static ptrdiff_t resources_memory
Definition HostInfo.h:148
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:150
static ptrdiff_t memoryUsed()
static String hostName()
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
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