2 * mem_solaric.c - module to get memory/swap usages in percent, for Solaris
4 * Copyright (c) 2001 Jonathan Lang <lang@synopsys.com>
5 * Copyright (c) 2002 Seiichi SATO <ssato@sh.rim.or.jp>
7 * licensed under the GPL
22 /* initialize function */
25 /* solaris doesn't need initialization */
29 /* return memory/swap usage in percent 0 to 100 */
30 void mem_getusage(int *per_mem
, int *per_swap
, const struct mem_options
*opts
)
34 static int swap_total
;
39 mem_total
= sysconf(_SC_PHYS_PAGES
);
40 mem_free
= sysconf(_SC_AVPHYS_PAGES
);
43 if (swapctl(SC_AINFO
, &anon
) == -1)
45 swap_total
= anon
.ani_max
;
46 swap_free
= anon
.ani_max
- anon
.ani_resv
;
48 /* calc mem/swap usage in percent */
49 *per_mem
= 100 * (1 - ((double) mem_free
/ (double) mem_total
));
50 *per_swap
= 100 * (1 - ((double) swap_free
/ (double) swap_total
));