casacore
HostInfoHurd.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.
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: -lstdc++
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 
38 #ifndef CASA_HOSTINFOHURD_H
39 #define CASA_HOSTINFOHURD_H
40 
41 # if defined(HOSTINFO_DO_IMPLEMENT)
42 
43 
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 
48 extern "C" {
49 #include <mach/mach.h>
50 }
51 
52 namespace casacore { //# NAMESPACE CASACORE - BEGIN
53 
54 // <summary>
55 // HostInfo for GNU HURD 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 GNU HURD 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 */
78 static int pageshift; /* log base 2 of the pagesize */
79 static int pagesize_;
80 
81 /* define pagetok in terms of pageshift */
82 #define pagetok(size) ((size) << pageshift)
83 
84 class HostMachineInfo {
85 friend 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 
105 HostMachineInfo::HostMachineInfo( ) : valid(1) {
106  int pagesize;
107 
108  kern_return_t ret;
109  struct host_basic_info basic_info;
110  mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
111 
112  /* get the page size with "getpagesize" and calculate pageshift from it */
113  pagesize_ = pagesize = getpagesize();
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  ret = host_info( mach_host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count );
125  if ( ret != KERN_SUCCESS ) {
126  valid = 0;
127  } else {
128  memory_total = basic_info.memory_size / 1024;
129  cpus = basic_info.avail_cpus;
130  }
131 }
132 
133 void HostMachineInfo::update_info( ) {
134 
135  vm_statistics_data_t vmstats;
136  kern_return_t kr;
137 
138  /* memory information */
139  kr = vm_statistics( mach_task_self(), &vmstats);
140  if ( kr != KERN_SUCCESS ) {
141  valid = 0;
142  return;
143  }
144 
145  memory_used = pagetok(vmstats.active_count + vmstats.wire_count);
146  memory_free = memory_total - memory_used;
147  swap_used = pagetok( vmstats.active_count + vmstats.inactive_count + vmstats.wire_count );
148  swap_free = pagetok( vmstats.free_count );
149  swap_total = pagetok( vmstats.active_count + vmstats.inactive_count +
150  vmstats.wire_count + vmstats.free_count );
151 }
152 
153 
154 } //# NAMESPACE CASACORE - END
155 
156 # endif
157 #endif
this file contains all the compiler specific defines
Definition: mainpage.dox:28