Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/HostInfoDarwin_8h_source.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 21:40:39 2011 Кодировка: Поисковые слова: р п п р п п р п п р п п р п п р п |
00001 /* 00002 ** This is a greatly MODIFIED version of a "top" machine dependent file. 00003 ** The only resemblance it bears to the original is with respect to the 00004 ** mechanics of finding various system details. The copyright details 00005 ** follow. 00006 ** 00007 ** This is a modified version of the osf1 version. Initially, I tried 00008 ** to use the m_macosx.c version by Andrew S. Townley, but ran into 00009 ** problems... 00010 ** 00011 ** --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 00012 ** 00013 ** Top users/processes display for Unix 00014 ** Version 3 00015 ** 00016 ** This program may be freely redistributed, 00017 ** but this entire comment MUST remain intact. 00018 ** 00019 ** Copyright (c) 1984, 1989, William LeFebvre, Rice University 00020 ** Copyright (c) 1989 - 1994, William LeFebvre, Northwestern University 00021 ** Copyright (c) 1994, 1995, William LeFebvre, Argonne National Laboratory 00022 ** Copyright (c) 1996, William LeFebvre, Group sys Consulting 00023 ** Copyright (c) 2002, Associated Universities Inc. 00024 */ 00025 00026 /* 00027 ** LIBS: -lstdc++ 00028 ** 00029 ** AUTHOR: Darrell Schiebel <drs@nrao.edu> 00030 ** 00031 ** ORIGINAL AUTHOR: Anthony Baxter <anthony@aaii.oz.au> 00032 ** ORIGINAL CONTRIBUTORS: David S. Comay <dsc@seismo.css.gov> 00033 ** Claus Kalle 00034 ** Pat Welch <tpw@physics.orst.edu> 00035 ** William LeFebvre <lefebvre@dis.anl.gov> 00036 ** Rainer Orth <ro@techfak.uni-bielefeld.de> 00037 ** 00038 ** $Id: HostInfoDarwin.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00039 ** 00040 */ 00041 00042 #ifndef CASA_HOSTINFODARWIN_H 00043 #define CASA_HOSTINFODARWIN_H 00044 00045 # if defined(HOSTINFO_DO_IMPLEMENT) 00046 00047 00048 #include <stdio.h> 00049 #include <stdlib.h> 00050 #include <unistd.h> 00051 00052 #include <mach/mach.h> 00053 00054 namespace casa { //# NAMESPACE CASA - BEGIN 00055 00056 // <summary> 00057 // HostInfo for Darwin machines. 00058 // </summary> 00059 00060 // <use visibility=local> 00061 00062 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00063 // </reviewed> 00064 00065 // <prerequisite> 00066 // <li> <linkto class=HostInfo>HostInfo</linkto> 00067 // </prerequisite> 00068 00069 // <synopsis> 00070 // This file provides the Linux specific functions for HostInfo. 00071 // It is selectively included by HostInfo.cc. 00072 // </synopsis> 00073 // 00074 // <group name="HostInfo"> 00075 00076 /* Log base 2 of 1024 is 10 (2^10 == 1024) */ 00077 #define LOG1024 10 00078 00079 /* these are for getting the memory statistics */ 00080 static int pageshift; /* log base 2 of the pagesize */ 00081 static int pagesize_; 00082 00083 /* define pagetok in terms of pageshift */ 00084 #define pagetok(size) ((size) << pageshift) 00085 00086 class HostMachineInfo { 00087 friend class HostInfo; 00088 00089 HostMachineInfo( ); 00090 void update_info( ); 00091 00092 int valid; 00093 int cpus; 00094 00095 ssize_t memory_total; 00096 ssize_t memory_used; 00097 ssize_t memory_free; 00098 00099 ssize_t swap_total; 00100 ssize_t swap_used; 00101 ssize_t swap_free; 00102 }; 00103 00104 // </group> 00105 00106 00107 HostMachineInfo::HostMachineInfo( ) : valid(1) { 00108 register int pagesize; 00109 00110 kern_return_t ret; 00111 struct host_basic_info basic_info; 00112 unsigned int count = HOST_BASIC_INFO_COUNT; 00113 00114 /* get the page size with "getpagesize" and calculate pageshift from it */ 00115 pagesize_ = pagesize = getpagesize(); 00116 pageshift = 0; 00117 while (pagesize > 1) 00118 { 00119 pageshift++; 00120 pagesize >>= 1; 00121 } 00122 00123 /* we only need the amount of log(2)1024 for our conversion */ 00124 pageshift -= LOG1024; 00125 00126 ret = host_info( mach_host_self(), HOST_BASIC_INFO, (host_info_t) &basic_info, &count ); 00127 if ( ret != KERN_SUCCESS ) { 00128 valid = 0; 00129 } else { 00130 memory_total = basic_info.memory_size / 1024; 00131 cpus = basic_info.avail_cpus; 00132 } 00133 } 00134 00135 void HostMachineInfo::update_info( ) { 00136 00137 struct vm_statistics vmstats; 00138 kern_return_t kr; 00139 unsigned int count; 00140 00141 /* memory information */ 00142 /* this is possibly bogus - we work out total # pages by */ 00143 /* adding up the free, active, inactive, wired down, and */ 00144 /* zero filled. Anyone who knows a better way, TELL ME! */ 00145 /* Change: dont use zero filled. */ 00146 count = sizeof(vmstats)/sizeof(integer_t); 00147 00148 kr = host_statistics( mach_host_self(), HOST_VM_INFO, (host_info_t) &vmstats, &count ); 00149 00150 if ( kr != KERN_SUCCESS ) { 00151 valid = 0; 00152 return; 00153 } 00154 00155 // /* thanks DEC for the table() command. No thanks at all for */ 00156 // /* omitting the man page for it from OSF/1 1.2, and failing */ 00157 // /* to document SWAPINFO in the 1.3 man page. Lets hear it for */ 00158 // /* include files. */ 00159 // i=0; 00160 // while(table(TBL_SWAPINFO,i,&swbuf,1,sizeof(struct tbl_swapinfo))>0) { 00161 // swappages += swbuf.size; 00162 // swapfree += swbuf.free; 00163 // i++; 00164 // } 00165 // 00166 // swap_used = pagetok(swappages - swapfree); 00167 // swap_free = pagetok(swapfree); 00168 // swap_total = pagetok(swappages); 00169 00170 memory_used = pagetok(vmstats.active_count + vmstats.wire_count); 00171 memory_free = memory_total - memory_used; 00172 swap_used = pagetok( vmstats.active_count + vmstats.inactive_count + vmstats.wire_count ); 00173 swap_free = pagetok( vmstats.free_count ); 00174 swap_total = pagetok( vmstats.active_count + vmstats.inactive_count + 00175 vmstats.wire_count + vmstats.free_count ); 00176 } 00177 00178 00179 } //# NAMESPACE CASA - END 00180 00181 # endif 00182 #endif