1 /*
2  * mem_solaric.c - module to get memory/swap usages in percent, for Solaris
3  *
4  * Copyright (c) 2001 Jonathan Lang <lang@synopsys.com>
5  * Copyright (c) 2002 Seiichi SATO <ssato@sh.rim.or.jp>
6  *
7  * licensed under the GPL
8  */
9 
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include "mem.h"
18 
19 #include <sys/stat.h>
20 #include <sys/swap.h>
21 
22 /* initialize function */
mem_init(void)23 void mem_init(void)
24 {
25 	/* solaris doesn't need initialization */
26 	return;
27 }
28 
29 /* return memory/swap usage in percent 0 to 100 */
mem_getusage(int * per_mem,int * per_swap,const struct mem_options * opts)30 void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts)
31 {
32 	static int mem_total;
33 	static int mem_free;
34 	static int swap_total;
35 	static int swap_free;
36 	struct anoninfo anon;
37 
38 	/* get mem usage */
39 	mem_total = sysconf(_SC_PHYS_PAGES);
40 	mem_free = sysconf(_SC_AVPHYS_PAGES);
41 
42 	/* get swap usage */
43 	if (swapctl(SC_AINFO, &anon) == -1)
44 		exit(1);
45 	swap_total = anon.ani_max;
46 	swap_free = anon.ani_max - anon.ani_resv;
47 
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));
51 }
52