HostInfo.h

Classes

HostInfo -- Miscellaneous information about this host and process. (full description)

class HostInfo

Interface

Public Members
static String hostName()
static Int processID()
static Double secondsFrom1970()
static Bool bigEndian()
static Int numCPUs( )
static Int memoryTotal()
static Int memoryUsed()
static Int memoryFree()
static Int swapTotal()
static Int swapUsed()
static Int swapFree()
Private Members
HostInfo( )
const HostInfo &operator=( const HostInfo & )

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This class is meant to encapsulate miscellaneous information about the environment that the current process is running in.

At present, the class can be used to obtain the name of the host on which this process is running, the process id of this process, the amount of physical memory (total, used, & free) on this host, the amount of swap space (total, used, and free), the number of CPUs on this host, and a count of the number of seconds from January 1, 1970. Generally you should use the classes Time and MVTime if your primary interest is related to time and dates. If your interest is in timing, you would generally use class Timer, which can also report CPU times as well as "clock" times.

Determination of the number of CPUs, swap space, and physical memory is particularly OS dependent. In cases where this functionality has not yet been implemented, the memory and swap functions will return -1 and the CPU function will return 0.

Example

    cout << "I am process #" << HostInfo::processID() << " running on host " <<
            HostInfo::hostName() << ", which has " << HostInfor::numCPUs( ) << " CPUs." << endl;
    cout << "This host has " << HostInfo::memoryTotal( ) << "K of memory [ " <<
            HostInfo::memoryUsed( ) << " used, " <<
            HostInfo::memoryFree( ) << " free ]." << endl;
    cout << "This host has " << HostInfo::swapTotal( ) << "K of swap space [ " <<
            HostInfo::swapUsed( ) << " used, " <<
            HostInfo::swapFree( ) << " free ]." << endl;
    Double now = HostInfo::secondsFrom1970();
    doSomething();
    cout << "Function doSomething() took " << 
            HostInfo::secondsFrom1970() - now << " seconds to execute."  << endl;
    

Motivation

The ObjectID class uses a combination of hostname, process id, time, and a sequence number to ensure that ObjectID's are distinct. This class encapsulates the way the first three of those items are obtained.

To Do

Member Description

static String hostName()

static Int processID()

static Double secondsFrom1970()

static Bool bigEndian()

Returns True for big endian machines (like SUN). Returns False for little endian machines (like PC).

static Int numCPUs( )

Returns 0 if unable to determine the number of CPUs.

static Int memoryTotal()
static Int memoryUsed()
static Int memoryFree()

Returns -1 if unable to determine memory info.

static Int swapTotal()
static Int swapUsed()
static Int swapFree()

Returns -1 if unable to determine swap info.

HostInfo( )

we don't want folks creating these...

const HostInfo &operator=( const HostInfo & )