HostInfoOsf1.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 #ifndef CASA_HOSTINFOOSF1_H
00039 #define CASA_HOSTINFOOSF1_H
00040
00041 # if defined(HOSTINFO_DO_IMPLEMENT)
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #define _mach
00052
00053 #include <stdio.h>
00054
00055 #include <unistd.h>
00056 #include <mach.h>
00057 #include <mach/mach_types.h>
00058 #include <mach/vm_statistics.h>
00059 #include <mach/host_info.h>
00060 #include <sys/table.h>
00061
00062 namespace casacore {
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 extern "C" kern_return_t host_info(int, int, host_info_t, unsigned int *);
00085 extern "C" int host_self( );
00086 extern "C" int vm_statistics(long, struct vm_statistics *);
00087
00088
00089 #define LOG1024 10
00090
00091
00092
00093 #define pagetok(size) ((size) << pageshift)
00094
00095 class HostMachineInfo {
00096 friend class HostInfo;
00097
00098 HostMachineInfo( );
00099 void update_info( );
00100
00101 int valid;
00102 int cpus;
00103
00104 ptrdiff_t swap_total;
00105 ptrdiff_t swap_used;
00106 ptrdiff_t swap_free;
00107
00108 ptrdiff_t memory_total;
00109 ptrdiff_t memory_used;
00110 ptrdiff_t memory_free;
00111
00112 int pageshift;
00113 };
00114
00115
00116
00117
00118 HostMachineInfo::HostMachineInfo( ) : valid(1) {
00119
00120 int i = 0;
00121 int pagesize;
00122 struct tbl_sysinfo sibuf;
00123
00124 kern_return_t ret;
00125 struct host_basic_info basic_info;
00126 unsigned int count = HOST_BASIC_INFO_COUNT;
00127
00128
00129 pagesize = getpagesize();
00130 pageshift = 0;
00131 while (pagesize > 1)
00132 {
00133 pageshift++;
00134 pagesize >>= 1;
00135 }
00136
00137
00138 pageshift -= LOG1024;
00139
00140 ret = host_info( host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count );
00141 if ( ret != KERN_SUCCESS ) {
00142 valid = 0;
00143 } else {
00144 memory_total = basic_info.memory_size / 1024;
00145 cpus = basic_info.avail_cpus;
00146 }
00147 }
00148
00149 void HostMachineInfo::update_info( ) {
00150
00151 struct tbl_swapinfo swbuf;
00152 vm_statistics_data_t vmstats;
00153 int swappages=0,swapfree=0,i;
00154
00155
00156
00157
00158
00159
00160 (void) vm_statistics(task_self(),&vmstats);
00161
00162
00163
00164
00165
00166 i=0;
00167 while(table(TBL_SWAPINFO,i,&swbuf,1,sizeof(struct tbl_swapinfo))>0) {
00168 swappages += swbuf.size;
00169 swapfree += swbuf.free;
00170 i++;
00171 }
00172
00173 swap_total = pagetok(swappages);
00174 swap_used = pagetok(swappages - swapfree);
00175 swap_free = pagetok(swapfree);
00176
00177 memory_free = pagetok(vmstats.free_count);
00178 memory_used = memory_total - memory_free;
00179
00180
00181 }
00182
00183 # endif
00184
00185 }
00186
00187 #endif