HostInfoIrix.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 #ifndef CASA_HOSTINFOIRIX_H
00026 #define CASA_HOSTINFOIRIX_H
00027
00028 # if defined(HOSTINFO_DO_IMPLEMENT)
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <sys/types.h>
00042 #include <unistd.h>
00043 #include <sys/stat.h>
00044 #include <sys/swap.h>
00045 #include <sys/sysmp.h>
00046 #include <sys/sysinfo.h>
00047
00048 namespace casacore {
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #define pagetok(pages) ((((uint64_t) pages) * pagesize) >> 10)
00071
00072 class HostMachineInfo {
00073 friend class HostInfo;
00074
00075 HostMachineInfo( );
00076 void update_info( );
00077
00078 int valid;
00079 int cpus;
00080
00081 ptrdiff_t swap_total;
00082 ptrdiff_t swap_used;
00083 ptrdiff_t swap_free;
00084
00085 ptrdiff_t memory_total;
00086 ptrdiff_t memory_used;
00087 ptrdiff_t memory_free;
00088
00089 ptrdiff_t pagesize;
00090
00091 };
00092
00093
00094
00095
00096 HostMachineInfo::HostMachineInfo( ) : valid(1) {
00097
00098 pagesize = getpagesize();
00099
00100 if ((cpus = sysmp(MP_NPROCS)) == -1) {
00101 perror("sysmp(MP_NPROCS)");
00102 valid = 0;
00103 return;
00104 }
00105
00106 struct rminfo realmem;
00107 if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) {
00108 perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)");
00109 valid = 0;
00110 return;
00111 }
00112
00113 memory_total = pagetok(realmem.physmem);
00114 }
00115
00116 void HostMachineInfo::update_info( ) {
00117 int i;
00118 struct rminfo realmem;
00119 struct sysinfo sysinfo;
00120 off_t fswap;
00121 off_t tswap;
00122
00123 swapctl(SC_GETFREESWAP, &fswap);
00124 swapctl(SC_GETSWAPTOT, &tswap);
00125
00126 if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == -1) {
00127 perror("sysmp(MP_SAGET,MPSA_RMINFO, ...)");
00128 valid = 0;
00129 return;
00130 }
00131
00132 memory_free = pagetok(realmem.freemem);
00133 memory_used = memory_total - memory_free;
00134 swap_total = tswap / 2;
00135 swap_free = fswap / 2;
00136 swap_used = swap_total - swap_free;
00137 }
00138
00139 # endif
00140
00141 }
00142
00143 #endif