38 #ifndef CASA_HOSTINFOOSF1_H
39 #define CASA_HOSTINFOOSF1_H
41 # if defined(HOSTINFO_DO_IMPLEMENT)
57 #include <mach/mach_types.h>
58 #include <mach/vm_statistics.h>
59 #include <mach/host_info.h>
60 #include <sys/table.h>
84 extern "C" kern_return_t host_info(
int,
int, host_info_t,
unsigned int *);
85 extern "C" int host_self( );
86 extern "C" int vm_statistics(
long,
struct vm_statistics *);
93 #define pagetok(size) ((size) << pageshift)
95 class HostMachineInfo {
96 friend class HostInfo;
104 ptrdiff_t swap_total;
108 ptrdiff_t memory_total;
109 ptrdiff_t memory_used;
110 ptrdiff_t memory_free;
118 HostMachineInfo::HostMachineInfo( ) : valid(1) {
122 struct tbl_sysinfo sibuf;
125 struct host_basic_info basic_info;
126 unsigned int count = HOST_BASIC_INFO_COUNT;
129 pagesize = getpagesize();
138 pageshift -= LOG1024;
140 ret = host_info( host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count );
141 if ( ret != KERN_SUCCESS ) {
144 memory_total = basic_info.memory_size / 1024;
145 cpus = basic_info.avail_cpus;
149 void HostMachineInfo::update_info( ) {
151 struct tbl_swapinfo swbuf;
152 vm_statistics_data_t vmstats;
153 int swappages=0,swapfree=0,i;
160 (void) vm_statistics(task_self(),&vmstats);
167 while(table(TBL_SWAPINFO,i,&swbuf,1,
sizeof(
struct tbl_swapinfo))>0) {
168 swappages += swbuf.size;
169 swapfree += swbuf.free;
173 swap_total = pagetok(swappages);
174 swap_used = pagetok(swappages - swapfree);
175 swap_free = pagetok(swapfree);
177 memory_free = pagetok(vmstats.free_count);
178 memory_used = memory_total - memory_free;