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