24#ifndef CASA_HOSTINFOSOLARIS_H
25#define CASA_HOSTINFOSOLARIS_H
27# if defined(HOSTINFO_DO_IMPLEMENT)
51#include <sys/sysinfo.h>
84# ifndef KSTAT_DATA_UINT32
95#define pagetok(size) ((*p_pagetok)(size))
98static void get_swapinfo(
int *total,
int *fr);
101class HostMachineInfo {
102friend class HostInfo;
109 static int pageshift;
110 int (*p_pagetok) (int);
112 static inline int pagetok_none(
int size) {
return(size); }
113 static inline int pagetok_left(
int size) {
return(size << pageshift); }
114 static inline int pagetok_right(
int size) {
return(size >> pageshift); }
121 ptrdiff_t memory_total;
122 ptrdiff_t memory_used;
123 ptrdiff_t memory_free;
125 ptrdiff_t swap_total;
133int HostMachineInfo::pageshift = 0;
135HostMachineInfo::~HostMachineInfo( ) {
if ( kc ) kstat_close(kc); }
137HostMachineInfo::HostMachineInfo( ) : valid(1), kc(NULL)
142 i = sysconf(_SC_PAGESIZE);
144 while ((i >>= 1) > 0) pageshift++;
155 p_pagetok = pagetok_left;
157 else if (pageshift == 0)
159 p_pagetok = pagetok_none;
163 p_pagetok = pagetok_right;
164 pageshift = -pageshift;
167 long maxmem = sysconf(_SC_PHYS_PAGES);
168 memory_total = pagetok (maxmem);
173 kstat_t *ks = kstat_lookup(kc,
"unix", 0,
"system_misc");
174 if (kstat_read(kc, ks, 0) == -1) {
175 perror(
"kstat_read");
178 kstat_named_t *kn = (kstat_named_t*) kstat_data_lookup(ks,
"ncpus");
179 cpus = kn->value.ui32;
182void HostMachineInfo::kupdate( )
186 static kid_t kcid = 0;
197 perror(
"kstat_open ");
200 kcid = kc->kc_chain_id;
209 nkcid = kstat_chain_update(kc);
216 perror(
"kstat_read ");
224void HostMachineInfo::update_info( )
227 static int swaptotal;
232 ks = kstat_lookup(kc,
"unix", 0,
"system_pages");
233 if (kstat_read(kc, ks, 0) == -1) {
234 perror(
"kstat_read");
237 kn = (kstat_named_t*) kstat_data_lookup(ks,
"freemem");
239 freemem = kn->value.ul;
241 memory_free = pagetok (freemem);
242 memory_used = memory_total - memory_free;
244 get_swapinfo(&swaptotal, &swapfree);
245 swap_total = pagetok(swaptotal);
246 swap_used = pagetok(swaptotal - swapfree);
247 swap_free = pagetok(swapfree);
251void get_swapinfo(
int *total,
int *fr)
255 struct anoninfo anon;
257 if (swapctl(SC_AINFO, &anon) == -1) {
261 *total = anon.ani_max;
262 *fr = anon.ani_max - anon.ani_resv;
266 struct swaptable *swt;
268 static char path[256];
271 cnt = swapctl(SC_GETNSWP, 0);
274 swt = (
struct swaptable *)malloc(
sizeof(
int) +
275 cnt *
sizeof(
struct swapent));
286 ste = &(swt->swt_ent[0]);
290 ste++->ste_path = path;
294 swapctl(SC_LIST, swt);
298 ste = &(swt->swt_ent[0]);
303 if (!(ste->ste_flags & ST_INDEL) &&
304 !(ste->ste_flags & ST_DOINGDEL))
this file contains all the compiler specific defines