22 |
|
#include "config.h" |
23 |
|
#endif |
24 |
|
|
25 |
– |
#include <stdio.h> |
25 |
|
#include "statgrab.h" |
26 |
|
#ifdef SOLARIS |
27 |
|
#include <sys/stat.h> |
28 |
|
#include <sys/swap.h> |
29 |
|
#include <unistd.h> |
30 |
|
#endif |
31 |
+ |
#ifdef LINUX |
32 |
+ |
#include <stdio.h> |
33 |
+ |
#include "tools.h" |
34 |
+ |
#endif |
35 |
|
|
36 |
|
swap_stat_t *get_swap_stats(){ |
37 |
|
|
38 |
|
static swap_stat_t swap_stat; |
39 |
|
|
40 |
+ |
#ifdef SOLARIS |
41 |
|
struct anoninfo ai; |
42 |
|
int pagesize; |
43 |
+ |
#endif |
44 |
+ |
#ifdef LINUX |
45 |
+ |
FILE *f; |
46 |
+ |
char *line_ptr; |
47 |
+ |
#endif |
48 |
|
|
49 |
+ |
#ifdef SOLARIS |
50 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
51 |
|
return NULL; |
52 |
|
} |
56 |
|
swap_stat.total = (long long)ai.ani_max * (long long)pagesize; |
57 |
|
swap_stat.used = (long long)ai.ani_resv * (long long)pagesize; |
58 |
|
swap_stat.free = swap_stat.total - swap_stat.used; |
59 |
+ |
#endif |
60 |
+ |
#ifdef LINUX |
61 |
+ |
if ((f=fopen("/proc/meminfo", "r" ))==NULL) { |
62 |
+ |
return NULL; |
63 |
+ |
} |
64 |
+ |
if((line_ptr=f_read_line(f, "Swap:"))==NULL){ |
65 |
+ |
fclose(f); |
66 |
+ |
return NULL; |
67 |
+ |
} |
68 |
+ |
if((sscanf(line_ptr, "Swap: %lld %lld %lld", &swap_stat.total, &swap_stat.used, &swap_stat.free))!=3){ |
69 |
+ |
fclose(f); |
70 |
+ |
return NULL; |
71 |
+ |
} |
72 |
+ |
fclose(f); |
73 |
+ |
#endif |
74 |
|
|
75 |
|
return &swap_stat; |
76 |
|
|