32 |
|
#endif |
33 |
|
#ifdef LINUX |
34 |
|
#include <stdio.h> |
35 |
+ |
#include <string.h> |
36 |
|
#endif |
37 |
|
#ifdef FREEBSD |
38 |
|
#include <sys/types.h> |
80 |
|
kstat_close(kc); |
81 |
|
#endif |
82 |
|
#ifdef LINUX |
83 |
< |
if((f=fopen("/proc/stat", "r"))==NULL){ |
84 |
< |
return NULL; |
85 |
< |
} |
86 |
< |
if((line_ptr=f_read_line(f, "page"))==NULL){ |
83 |
> |
if ((f = fopen("/proc/vmstat", "r")) != NULL) { |
84 |
> |
while ((line_ptr = f_read_line(f, "")) != NULL) { |
85 |
> |
long long value; |
86 |
> |
|
87 |
> |
if (sscanf(line_ptr, "%*s %lld", &value) != 1) { |
88 |
> |
continue; |
89 |
> |
} |
90 |
> |
|
91 |
> |
if (strncmp(line_ptr, "pgpgin ", 7) == 0) { |
92 |
> |
page_stats.pages_pagein = value; |
93 |
> |
} else if (strncmp(line_ptr, "pgpgout ", 8) == 0) { |
94 |
> |
page_stats.pages_pageout = value; |
95 |
> |
} |
96 |
> |
} |
97 |
> |
|
98 |
|
fclose(f); |
99 |
+ |
} else if ((f = fopen("/proc/stat", "r")) != NULL) { |
100 |
+ |
if ((line_ptr = f_read_line(f, "page")) == NULL) { |
101 |
+ |
fclose(f); |
102 |
+ |
return NULL; |
103 |
+ |
} |
104 |
+ |
|
105 |
+ |
if (sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout) != 2) { |
106 |
+ |
return NULL; |
107 |
+ |
} |
108 |
+ |
|
109 |
+ |
fclose(f); |
110 |
+ |
} else { |
111 |
|
return NULL; |
112 |
|
} |
89 |
– |
if((sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout))!=2){ |
90 |
– |
return NULL; |
91 |
– |
} |
92 |
– |
fclose(f); |
93 |
– |
|
113 |
|
#endif |
114 |
|
#ifdef FREEBSD |
115 |
|
size = sizeof page_stats.pages_pagein; |