HostInfoDarwin.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef CASA_HOSTINFODARWIN_H
00042 #define CASA_HOSTINFODARWIN_H
00043
00044 # if defined(HOSTINFO_DO_IMPLEMENT)
00045
00046
00047 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <unistd.h>
00050
00051 #include <mach/mach.h>
00052
00053 namespace casacore {
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #define LOG1024 10
00077
00078
00079 static int pageshift;
00080 static int pagesize_;
00081
00082
00083 #define pagetok(size) ((size) << pageshift)
00084
00085 class HostMachineInfo {
00086 friend class HostInfo;
00087
00088 HostMachineInfo( );
00089 void update_info( );
00090
00091 int valid;
00092 int cpus;
00093
00094 ptrdiff_t memory_total;
00095 ptrdiff_t memory_used;
00096 ptrdiff_t memory_free;
00097
00098 ptrdiff_t swap_total;
00099 ptrdiff_t swap_used;
00100 ptrdiff_t swap_free;
00101 };
00102
00103
00104
00105
00106 HostMachineInfo::HostMachineInfo( ) : valid(1) {
00107 int pagesize;
00108
00109 kern_return_t ret;
00110 struct host_basic_info basic_info;
00111 unsigned int count = HOST_BASIC_INFO_COUNT;
00112
00113
00114 pagesize_ = pagesize = getpagesize();
00115 pageshift = 0;
00116 while (pagesize > 1)
00117 {
00118 pageshift++;
00119 pagesize >>= 1;
00120 }
00121
00122
00123 pageshift -= LOG1024;
00124
00125 #ifdef AIPS_64B
00126 ret = host_info( mach_host_self(), HOST_BASIC_INFO, (host_info64_t) &basic_info, &count );
00127 #else
00128 ret = host_info( mach_host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count );
00129 #endif
00130 if ( ret != KERN_SUCCESS ) {
00131 valid = 0;
00132 } else {
00133 #ifdef AIPS_64B
00134 memory_total = basic_info.max_mem / 1024;
00135 #else
00136 memory_total = basic_info.memory_size / 1024;
00137 #endif
00138 cpus = basic_info.avail_cpus;
00139 }
00140 }
00141
00142 void HostMachineInfo::update_info( ) {
00143
00144 #ifdef AIPS_64B
00145 struct vm_statistics64 vmstats;
00146 #else
00147 struct vm_statistics vmstats;
00148 #endif
00149 kern_return_t kr;
00150 unsigned int count;
00151
00152
00153
00154
00155
00156
00157 count = sizeof(vmstats)/sizeof(integer_t);
00158
00159 #ifdef AIPS_64B
00160 kr = host_statistics64( mach_host_self(), HOST_VM_INFO64, (host_info64_t) &vmstats, &count );
00161 #else
00162 kr = host_statistics( mach_host_self(), HOST_VM_INFO, (host_info_t) &vmstats, &count );
00163 #endif
00164 if ( kr != KERN_SUCCESS ) {
00165 valid = 0;
00166 return;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 memory_used = pagetok(vmstats.active_count + vmstats.wire_count);
00185 memory_free = memory_total - memory_used;
00186 swap_used = pagetok( vmstats.active_count + vmstats.inactive_count + vmstats.wire_count );
00187 swap_free = pagetok( vmstats.free_count );
00188 swap_total = pagetok( vmstats.active_count + vmstats.inactive_count +
00189 vmstats.wire_count + vmstats.free_count );
00190 }
00191
00192
00193 }
00194
00195 # endif
00196 #endif