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#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
48
49#include <mach/mach.h>
50
51namespace casacore { // # NAMESPACE CASACORE - BEGIN
52
53// <summary>
54// HostInfo for Darwin machines.
55// </summary>
56
57// <use visibility=local>
58
59// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
60// </reviewed>
61
62// <prerequisite>
63// <li> <linkto class=HostInfo>HostInfo</linkto>
64// </prerequisite>
65
66// <synopsis>
67// This file provides the Linux specific functions for HostInfo.
68// It is selectively included by HostInfo.cc.
69// </synopsis>
70//
71// <group name="HostInfo">
72
73/* Log base 2 of 1024 is 10 (2^10 == 1024) */
74#define LOG1024 10
75
76/* these are for getting the memory statistics */
77static int pageshift; /* log base 2 of the pagesize */
78static int pagesize_;
79
80/* define pagetok in terms of pageshift */
81#define pagetok(size) ((size) << pageshift)
82
83class HostMachineInfo {
84 friend class HostInfo;
85
86 HostMachineInfo();
87 void update_info();
88
89 int valid;
90 int cpus;
91
92 ptrdiff_t memory_total;
93 ptrdiff_t memory_used;
94 ptrdiff_t memory_free;
95
96 ptrdiff_t swap_total;
97 ptrdiff_t swap_used;
98 ptrdiff_t swap_free;
99};
100
101// </group>
102
103HostMachineInfo::HostMachineInfo() : valid(1) {
104 int pagesize;
105
106 kern_return_t ret;
107 struct host_basic_info basic_info;
108 unsigned int count = HOST_BASIC_INFO_COUNT;
109
110 /* get the page size with portable sysconf and calculate pageshift from it */
111 pagesize_ = pagesize = sysconf(_SC_PAGESIZE);
112 pageshift = 0;
113 while (pagesize > 1) {
114 pageshift++;
115 pagesize >>= 1;
116 }
117
118 /* we only need the amount of log(2)1024 for our conversion */
119 pageshift -= LOG1024;
120
121#ifdef AIPS_64B
122 ret = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info64_t)&basic_info, &count);
123#else
124 ret = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&basic_info, &count);
125#endif
126 if (ret != KERN_SUCCESS) {
127 valid = 0;
128 } else {
129#ifdef AIPS_64B
130 memory_total = basic_info.max_mem / 1024;
131#else
132 memory_total = basic_info.memory_size / 1024;
133#endif
134 cpus = basic_info.avail_cpus;
135 }
136}
137
138void HostMachineInfo::update_info() {
139#ifdef AIPS_64B
140 struct vm_statistics64 vmstats;
141#else
142 struct vm_statistics vmstats;
143#endif
144 kern_return_t kr;
145 unsigned int count;
146
147 /* memory information */
148 /* this is possibly bogus - we work out total # pages by */
149 /* adding up the free, active, inactive, wired down, and */
150 /* zero filled. Anyone who knows a better way, TELL ME! */
151 /* Change: dont use zero filled. */
152 count = sizeof(vmstats) / sizeof(integer_t);
153
154#ifdef AIPS_64B
155 kr = host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&vmstats, &count);
156#else
157 kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstats, &count);
158#endif
159 if (kr != KERN_SUCCESS) {
160 valid = 0;
161 return;
162 }
163
164 // /* thanks DEC for the table() command. No thanks at all for */
165 // /* omitting the man page for it from OSF/1 1.2, and failing */
166 // /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
167 // /* include files. */
168 // i=0;
169 // while(table(TBL_SWAPINFO,i,&swbuf,1,sizeof(struct tbl_swapinfo))>0) {
170 // swappages += swbuf.size;
171 // swapfree += swbuf.free;
172 // i++;
173 // }
174 //
175 // swap_used = pagetok(swappages - swapfree);
176 // swap_free = pagetok(swapfree);
177 // swap_total = pagetok(swappages);
178
179 memory_used = pagetok(vmstats.active_count + vmstats.wire_count);
180 memory_free = memory_total - memory_used;
181 swap_used = pagetok(vmstats.active_count + vmstats.inactive_count + vmstats.wire_count);
182 swap_free = pagetok(vmstats.free_count);
183 swap_total = pagetok(vmstats.active_count + vmstats.inactive_count + vmstats.wire_count +
184 vmstats.free_count);
185}
186
187} // namespace casacore
188
189#endif
190#endif
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28