59 |
|
#include <unistd.h> |
60 |
|
#define SWAP_BATCH 5 |
61 |
|
#endif |
62 |
+ |
#ifdef AIX |
63 |
+ |
#include <unistd.h> |
64 |
+ |
#include <libperfstat.h> |
65 |
+ |
#endif |
66 |
+ |
#ifdef WIN32 |
67 |
+ |
#include <windows.h> |
68 |
+ |
#endif |
69 |
|
|
70 |
|
sg_swap_stats *sg_get_swap_stats(){ |
71 |
|
|
99 |
|
#if defined(NETBSD) || defined(OPENBSD) |
100 |
|
struct uvmexp *uvm; |
101 |
|
#endif |
102 |
+ |
#ifdef AIX |
103 |
+ |
perfstat_memory_total_t mem; |
104 |
+ |
long long pagesize; |
105 |
+ |
#endif |
106 |
+ |
#ifdef WIN32 |
107 |
+ |
MEMORYSTATUSEX memstats; |
108 |
+ |
#endif |
109 |
|
|
110 |
|
#ifdef HPUX |
111 |
|
swap_stat.total = 0; |
144 |
|
swapidx = pstat_swapinfo[num - 1].pss_idx + 1; |
145 |
|
} |
146 |
|
#endif |
147 |
+ |
#ifdef AIX |
148 |
+ |
if ((pagesize = sysconf(_SC_PAGESIZE)) == -1) { |
149 |
+ |
sg_set_error_with_errno(SG_ERROR_SYSCONF, "_SC_PAGESIZE"); |
150 |
+ |
return NULL; |
151 |
+ |
} |
152 |
+ |
|
153 |
+ |
/* return code is number of structures returned */ |
154 |
+ |
if(perfstat_memory_total(NULL, &mem, sizeof(perfstat_memory_total_t), 1) != 1) { |
155 |
+ |
sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "perfstat_memory_total"); |
156 |
+ |
return NULL; |
157 |
+ |
} |
158 |
+ |
|
159 |
+ |
swap_stat.total = ((long long)mem.pgsp_total) * pagesize; |
160 |
+ |
swap_stat.free = ((long long)mem.pgsp_free) * pagesize; |
161 |
+ |
swap_stat.used = swap_stat.total - swap_stat.free; |
162 |
+ |
#endif |
163 |
|
#ifdef SOLARIS |
164 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
165 |
|
sg_set_error_with_errno(SG_ERROR_SYSCONF, "_SC_PAGESIZE"); |
211 |
|
for (n = 0; ; ++n) { |
212 |
|
mib[mibsize] = n; |
213 |
|
size = sizeof xsw; |
214 |
< |
if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, NULL) < 0) { |
214 |
> |
if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, 0) < 0) { |
215 |
|
break; |
216 |
|
} |
217 |
|
if (xsw.xsw_version != XSWDEV_VERSION) { |
249 |
|
swap_stat.total = (long long)uvm->pagesize * (long long)uvm->swpages; |
250 |
|
swap_stat.used = (long long)uvm->pagesize * (long long)uvm->swpginuse; |
251 |
|
swap_stat.free = swap_stat.total - swap_stat.used; |
252 |
+ |
#endif |
253 |
+ |
#ifdef WIN32 |
254 |
+ |
memstats.dwLength = sizeof(memstats); |
255 |
+ |
if (!GlobalMemoryStatusEx(&memstats)) { |
256 |
+ |
sg_set_error_with_errno(SG_ERROR_MEMSTATUS, |
257 |
+ |
"GloblaMemoryStatusEx"); |
258 |
+ |
return NULL; |
259 |
+ |
} |
260 |
+ |
/* the PageFile stats include Phys memory "minus an overhead". |
261 |
+ |
* Due to this unknown "overhead" there's no way to extract just page |
262 |
+ |
* file use from these numbers */ |
263 |
+ |
swap_stat.total = memstats.ullTotalPageFile; |
264 |
+ |
swap_stat.free = memstats.ullAvailPageFile; |
265 |
+ |
swap_stat.used = swap_stat.total - swap_stat.free; |
266 |
|
#endif |
267 |
|
|
268 |
|
return &swap_stat; |