22 |
|
#include "config.h" |
23 |
|
#endif |
24 |
|
|
25 |
– |
#include <stdio.h> |
25 |
|
#include "statgrab.h" |
26 |
|
#ifdef SOLARIS |
27 |
|
#include <unistd.h> |
28 |
|
#include <kstat.h> |
29 |
|
#endif |
30 |
+ |
#ifdef LINUX |
31 |
+ |
#include <stdio.h> |
32 |
+ |
#include <string.h> |
33 |
+ |
#include "tools.h" |
34 |
+ |
#endif |
35 |
|
|
36 |
|
mem_stat_t *get_memory_stats(){ |
37 |
|
|
44 |
|
long totalmem; |
45 |
|
int pagesize; |
46 |
|
#endif |
47 |
+ |
#ifdef LINUX |
48 |
+ |
char *line_ptr; |
49 |
+ |
FILE *f; |
50 |
+ |
#endif |
51 |
|
|
52 |
|
#ifdef SOLARIS |
53 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
75 |
|
mem_stat.total = (long long)totalmem * (long long)pagesize; |
76 |
|
mem_stat.free = ((long long)kn->value.ul) * (long long)pagesize; |
77 |
|
mem_stat.used = mem_stat.total - mem_stat.free; |
78 |
+ |
#endif |
79 |
+ |
|
80 |
+ |
#ifdef LINUX |
81 |
+ |
f=fopen("/proc/meminfo", "r"); |
82 |
+ |
if(f==NULL){ |
83 |
+ |
return NULL; |
84 |
+ |
} |
85 |
+ |
|
86 |
+ |
if((line_ptr=f_read_line(f, "Mem:"))==NULL){ |
87 |
+ |
fclose(f); |
88 |
+ |
return NULL; |
89 |
+ |
} |
90 |
+ |
|
91 |
+ |
fclose(f); |
92 |
+ |
|
93 |
+ |
/* Linux actually stores this as a unsigned long long, but |
94 |
+ |
* our structures are just long longs. This shouldn't be a |
95 |
+ |
* problem for sometime yet :) |
96 |
+ |
*/ |
97 |
+ |
if((sscanf(line_ptr,"Mem: %lld %lld %lld %*d %*d %lld", \ |
98 |
+ |
&mem_stat.total, \ |
99 |
+ |
&mem_stat.used, \ |
100 |
+ |
&mem_stat.free, \ |
101 |
+ |
&mem_stat.cache))!=4){ |
102 |
+ |
return NULL; |
103 |
+ |
} |
104 |
+ |
|
105 |
|
#endif |
106 |
|
|
107 |
|
return &mem_stat; |