25 #ifndef CASA_HOSTINFOSOLARIS_H
26 #define CASA_HOSTINFOSOLARIS_H
28 # if defined(HOSTINFO_DO_IMPLEMENT)
51 #include <sys/types.h>
52 #include <sys/sysinfo.h>
85 # ifndef KSTAT_DATA_UINT32
96 #define pagetok(size) ((*p_pagetok)(size))
99 static void get_swapinfo(
int *total,
int *fr);
102 class HostMachineInfo {
103 friend class HostInfo;
110 static int pageshift;
111 int (*p_pagetok) (int);
113 static inline int pagetok_none(
int size) {
return(size); }
114 static inline int pagetok_left(
int size) {
return(size << pageshift); }
115 static inline int pagetok_right(
int size) {
return(size >> pageshift); }
122 ptrdiff_t memory_total;
123 ptrdiff_t memory_used;
124 ptrdiff_t memory_free;
126 ptrdiff_t swap_total;
134 int HostMachineInfo::pageshift = 0;
136 HostMachineInfo::~HostMachineInfo( ) {
if ( kc ) kstat_close(kc); }
138 HostMachineInfo::HostMachineInfo( ) : valid(1), kc(NULL)
143 i = sysconf(_SC_PAGESIZE);
145 while ((i >>= 1) > 0) pageshift++;
156 p_pagetok = pagetok_left;
158 else if (pageshift == 0)
160 p_pagetok = pagetok_none;
164 p_pagetok = pagetok_right;
165 pageshift = -pageshift;
168 long maxmem = sysconf(_SC_PHYS_PAGES);
169 memory_total = pagetok (maxmem);
174 kstat_t *ks = kstat_lookup(kc,
"unix", 0,
"system_misc");
175 if (kstat_read(kc, ks, 0) == -1) {
176 perror(
"kstat_read");
179 kstat_named_t *kn = (kstat_named_t*) kstat_data_lookup(ks,
"ncpus");
180 cpus = kn->value.ui32;
183 void HostMachineInfo::kupdate( )
187 static kid_t kcid = 0;
198 perror(
"kstat_open ");
201 kcid = kc->kc_chain_id;
210 nkcid = kstat_chain_update(kc);
217 perror(
"kstat_read ");
225 void HostMachineInfo::update_info( )
228 static int swaptotal;
233 ks = kstat_lookup(kc,
"unix", 0,
"system_pages");
234 if (kstat_read(kc, ks, 0) == -1) {
235 perror(
"kstat_read");
238 kn = (kstat_named_t*) kstat_data_lookup(ks,
"freemem");
240 freemem = kn->value.ul;
242 memory_free = pagetok (freemem);
243 memory_used = memory_total - memory_free;
245 get_swapinfo(&swaptotal, &swapfree);
246 swap_total = pagetok(swaptotal);
247 swap_used = pagetok(swaptotal - swapfree);
248 swap_free = pagetok(swapfree);
252 void get_swapinfo(
int *total,
int *fr)
256 struct anoninfo anon;
258 if (swapctl(SC_AINFO, &anon) == -1) {
262 *total = anon.ani_max;
263 *fr = anon.ani_max - anon.ani_resv;
267 struct swaptable *swt;
269 static char path[256];
272 cnt = swapctl(SC_GETNSWP, 0);
275 swt = (
struct swaptable *)malloc(
sizeof(
int) +
276 cnt *
sizeof(
struct swapent));
287 ste = &(swt->swt_ent[0]);
291 ste++->ste_path =
path;
295 swapctl(SC_LIST, swt);
299 ste = &(swt->swt_ent[0]);
304 if (!(ste->ste_flags & ST_INDEL) &&
305 !(ste->ste_flags & ST_DOINGDEL))
std::string path(const std::string &name)
#define casacore
<X11/Intrinsic.h> #defines true, false, casacore::Bool, and String.