57 |
|
#include <sys/param.h> |
58 |
|
#include <sys/pstat.h> |
59 |
|
#include <unistd.h> |
60 |
+ |
#define SWAP_BATCH 5 |
61 |
|
#endif |
62 |
|
|
63 |
|
sg_swap_stats *sg_get_swap_stats(){ |
65 |
|
static sg_swap_stats swap_stat; |
66 |
|
|
67 |
|
#ifdef HPUX |
68 |
< |
struct pst_swapinfo pstat_swapinfo; |
68 |
> |
struct pst_swapinfo pstat_swapinfo[SWAP_BATCH]; |
69 |
|
int swapidx = 0; |
70 |
+ |
int num, i; |
71 |
|
#endif |
72 |
|
#ifdef SOLARIS |
73 |
|
struct anoninfo ai; |
98 |
|
swap_stat.used = 0; |
99 |
|
swap_stat.free = 0; |
100 |
|
|
101 |
< |
/* The 128 here is arbitrary, it can be increased at the expense |
102 |
< |
of more system calls to pstat(). */ |
103 |
< |
for (swapidx = 0; swapidx < 128; swapidx++) { |
104 |
< |
if (pstat_getswap(&pstat_swapinfo, sizeof(pstat_swapinfo), 1, swapidx) == -1) { |
101 |
> |
while (1) { |
102 |
> |
num = pstat_getswap(pstat_swapinfo, sizeof pstat_swapinfo[0], |
103 |
> |
SWAP_BATCH, swapidx); |
104 |
> |
if (num == -1) { |
105 |
> |
sg_set_error_with_errno(SG_ERROR_PSTAT, |
106 |
> |
"pstat_getswap"); |
107 |
> |
return NULL; |
108 |
> |
} else if (num == 0) { |
109 |
|
break; |
110 |
|
} |
111 |
|
|
112 |
< |
if (pstat_swapinfo.pss_idx != swapidx) { |
113 |
< |
continue; |
108 |
< |
} |
112 |
> |
for (i = 0; i < num; i++) { |
113 |
> |
struct pst_swapinfo *si = &pstat_swapinfo[i]; |
114 |
|
|
115 |
< |
if ((pstat_swapinfo.pss_flags & SW_ENABLED) != SW_ENABLED) { |
116 |
< |
continue; |
115 |
> |
if ((si->pss_flags & SW_ENABLED) != SW_ENABLED) { |
116 |
> |
continue; |
117 |
> |
} |
118 |
> |
|
119 |
> |
if ((si->pss_flags & SW_BLOCK) == SW_BLOCK) { |
120 |
> |
swap_stat.total += ((long long) si->pss_nblksavail) * 1024LL; |
121 |
> |
swap_stat.used += ((long long) si->pss_nfpgs) * 1024LL; |
122 |
> |
swap_stat.free = swap_stat.total - swap_stat.used; |
123 |
> |
} |
124 |
> |
if ((si->pss_flags & SW_FS) == SW_FS) { |
125 |
> |
swap_stat.total += ((long long) si->pss_limit) * 1024LL; |
126 |
> |
swap_stat.used += ((long long) si->pss_allocated) * 1024LL; |
127 |
> |
swap_stat.free = swap_stat.total - swap_stat.used; |
128 |
> |
} |
129 |
|
} |
130 |
< |
|
114 |
< |
if ((pstat_swapinfo.pss_flags & SW_BLOCK) == SW_BLOCK) { |
115 |
< |
swap_stat.total += ((long long) pstat_swapinfo.pss_nblksavail) * 1024LL; |
116 |
< |
swap_stat.used += ((long long) pstat_swapinfo.pss_nfpgs) * 1024LL; |
117 |
< |
swap_stat.free = swap_stat.total - swap_stat.used; |
118 |
< |
} |
119 |
< |
if ((pstat_swapinfo.pss_flags & SW_FS) == SW_FS) { |
120 |
< |
swap_stat.total += ((long long) pstat_swapinfo.pss_limit) * 1024LL; |
121 |
< |
swap_stat.used += ((long long) pstat_swapinfo.pss_allocated) * 1024LL; |
122 |
< |
swap_stat.free = swap_stat.total - swap_stat.used; |
123 |
< |
} |
130 |
> |
swapidx = pstat_swapinfo[num - 1].pss_idx + 1; |
131 |
|
} |
132 |
|
#endif |
133 |
|
#ifdef SOLARIS |