casacore
Loading...
Searching...
No Matches
HostInfoOsf1.h
Go to the documentation of this file.
1//# HostInfo_osf1.h: DEC OSF/1 specific memory, swap, and CPU code.
2
3 /*
4 ** This is a greatly MODIFIED version of a "top" machine dependent file.
5 ** The only resemblance it bears to the original is with respect to the
6 ** mechanics of finding various system details. The copyright details
7 ** follow.
8 **
9 ** --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
10 **
11 ** Top users/processes display for Unix
12 ** Version 3
13 **
14 ** This program may be freely redistributed,
15 ** but this entire comment MUST remain intact.
16 **
17 ** Copyright (c) 1984, 1989, William LeFebvre, Rice University
18 ** Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University
19 ** Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory
20 ** Copyright (c) 1996, William LeFebvre, Group sys Consulting
21 ** Copyright (c) 2002, Associated Universities Inc.
22 */
23
24/*
25 * LIBS: -lmach -lpset
26 *
27 * AUTHOR: Darrell Schiebel <drs@nrao.edu>
28 *
29 * ORIGINAL AUTHOR: Anthony Baxter <anthony@aaii.oz.au>
30 * ORIGINAL CONTRIBUTORS: David S. Comay <dsc@seismo.css.gov>
31 * Claus Kalle
32 * Pat Welch <tpw@physics.orst.edu>
33 * William LeFebvre <lefebvre@dis.anl.gov>
34 * Rainer Orth <ro@techfak.uni-bielefeld.de>
35 */
36
37#ifndef CASA_HOSTINFOOSF1_H
38#define CASA_HOSTINFOOSF1_H
39
40# if defined(HOSTINFO_DO_IMPLEMENT)
41
42//
43//--> /usr/include/mach/mach_interface.h:297: <-
44//--> previous declaration of `int vm_statistics(long int, struct vm_statistics *)' with C++ linkage <-
45//
46// so, we hack this by defining _mach to kick <mach/mach_interface.h> out of inclusion,
47// and then below we make this extern "C"... likely this is fixed in some version of
48// DEC OSF/1 which is newer than what we have...
49//
50#define _mach
51
52#include <stdio.h>
53
54#include <unistd.h>
55#include <mach.h>
56#include <mach/mach_types.h>
57#include <mach/vm_statistics.h>
58#include <mach/host_info.h>
59#include <sys/table.h>
60
61namespace casacore { //# NAMESPACE CASACORE - BEGIN
62
63// <summary>
64// HostInfo for OSF1 machines.
65// </summary>
66
67// <use visibility=local>
68
69// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
70// </reviewed>
71
72// <prerequisite>
73// <li> <linkto class=HostInfo>HostInfo</linkto>
74// </prerequisite>
75
76// <synopsis>
77// This file provides the OSF1 specific functions for HostInfo.
78// It is selectively included by HostInfo.cc.
79// </synopsis>
80//
81// <group name="HostInfo">
82
83extern "C" kern_return_t host_info(int, int, host_info_t, unsigned int *);
84extern "C" int host_self( );
85extern "C" int vm_statistics(long, struct vm_statistics *);
86
87/* Log base 2 of 1024 is 10 (2^10 == 1024) */
88#define LOG1024 10
89
90/* these are for getting the memory statistics */
91/* define pagetok in terms of pageshift */
92#define pagetok(size) ((size) << pageshift)
93
94class HostMachineInfo {
95friend class HostInfo;
96
97 HostMachineInfo( );
98 void update_info( );
99
100 int valid;
101 int cpus;
102
103 ptrdiff_t swap_total;
104 ptrdiff_t swap_used;
105 ptrdiff_t swap_free;
106
107 ptrdiff_t memory_total;
108 ptrdiff_t memory_used;
109 ptrdiff_t memory_free;
110
111 int pageshift; /* log base 2 of the pagesize */
112};
113
114// </group>
115
116
117HostMachineInfo::HostMachineInfo( ) : valid(1) {
118
119 int i = 0;
120 int pagesize;
121 struct tbl_sysinfo sibuf;
122
123 kern_return_t ret;
124 struct host_basic_info basic_info;
125 unsigned int count = HOST_BASIC_INFO_COUNT;
126
127 /* get the page size with "getpagesize" and calculate pageshift from it */
128 pagesize = getpagesize();
129 pageshift = 0;
130 while (pagesize > 1)
131 {
132 pageshift++;
133 pagesize >>= 1;
134 }
135
136 /* we only need the amount of log(2)1024 for our conversion */
137 pageshift -= LOG1024;
138
139 ret = host_info( host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count );
140 if ( ret != KERN_SUCCESS ) {
141 valid = 0;
142 } else {
143 memory_total = basic_info.memory_size / 1024;
144 cpus = basic_info.avail_cpus;
145 }
146}
147
148void HostMachineInfo::update_info( ) {
149
150 struct tbl_swapinfo swbuf;
151 vm_statistics_data_t vmstats;
152 int swappages=0,swapfree=0,i;
153
154 /* memory information */
155 /* this is possibly bogus - we work out total # pages by */
156 /* adding up the free, active, inactive, wired down, and */
157 /* zero filled. Anyone who knows a better way, TELL ME! */
158 /* Change: dont use zero filled. */
159 (void) vm_statistics(task_self(),&vmstats);
160
161 /* thanks DEC for the table() command. No thanks at all for */
162 /* omitting the man page for it from OSF/1 1.2, and failing */
163 /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
164 /* include files. */
165 i=0;
166 while(table(TBL_SWAPINFO,i,&swbuf,1,sizeof(struct tbl_swapinfo))>0) {
167 swappages += swbuf.size;
168 swapfree += swbuf.free;
169 i++;
170 }
171
172 swap_total = pagetok(swappages);
173 swap_used = pagetok(swappages - swapfree);
174 swap_free = pagetok(swapfree);
175
176 memory_free = pagetok(vmstats.free_count);
177 memory_used = memory_total - memory_free;
178// some memory is left unaccounted for, using the following...
179// memory_used = pagetok(vmstats.active_count + vmstats.inactive_count + vmstats.wire_count);
180}
181
182# endif
183
184} //# NAMESPACE CASACORE - END
185
186#endif
this file contains all the compiler specific defines
Definition mainpage.dox:28