1 |
< |
/* |
1 |
> |
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
6 |
< |
* This program is free software; you can redistribute it and/or |
7 |
< |
* modify it under the terms of the GNU General Public License |
8 |
< |
* as published by the Free Software Foundation; either version 2 |
9 |
< |
* of the License, or (at your option) any later version. |
6 |
> |
* This library is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU Lesser General Public |
8 |
> |
* License as published by the Free Software Foundation; either |
9 |
> |
* version 2.1 of the License, or (at your option) any later version. |
10 |
|
* |
11 |
< |
* This program is distributed in the hope that it will be useful, |
11 |
> |
* This library is distributed in the hope that it will be useful, |
12 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
< |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
< |
* GNU General Public License for more details. |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
> |
* Lesser General Public License for more details. |
15 |
|
* |
16 |
< |
* You should have received a copy of the GNU General Public License |
17 |
< |
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
16 |
> |
* You should have received a copy of the GNU Lesser General Public |
17 |
> |
* License along with this library; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
> |
* 02111-1307 USA |
20 |
|
*/ |
21 |
|
|
22 |
|
#ifdef HAVE_CONFIG_H |
24 |
|
#endif |
25 |
|
|
26 |
|
#include "statgrab.h" |
27 |
+ |
#include "tools.h" |
28 |
|
#include <time.h> |
29 |
|
#ifdef SOLARIS |
30 |
|
#include <kstat.h> |
31 |
|
#include <sys/sysinfo.h> |
32 |
|
#include <string.h> |
33 |
|
#endif |
34 |
< |
#ifdef LINUX |
34 |
> |
#if defined(LINUX) || defined(CYGWIN) |
35 |
|
#include <stdio.h> |
36 |
< |
#include "tools.h" |
36 |
> |
#include <string.h> |
37 |
|
#endif |
38 |
+ |
#ifdef FREEBSD |
39 |
+ |
#include <sys/types.h> |
40 |
+ |
#include <sys/sysctl.h> |
41 |
+ |
#endif |
42 |
|
|
37 |
– |
|
43 |
|
static page_stat_t page_stats; |
44 |
|
static int page_stats_uninit=1; |
45 |
|
|
49 |
|
kstat_t *ksp; |
50 |
|
cpu_stat_t cs; |
51 |
|
#endif |
52 |
< |
#ifdef LINUX |
52 |
> |
#if defined(LINUX) || defined(CYGWIN) |
53 |
|
FILE *f; |
54 |
|
char *line_ptr; |
55 |
|
#endif |
56 |
+ |
#ifdef FREEBSD |
57 |
+ |
size_t size; |
58 |
+ |
#endif |
59 |
+ |
#ifdef NETBSD |
60 |
+ |
struct uvmexp *uvm; |
61 |
+ |
#endif |
62 |
|
|
63 |
+ |
page_stats.systime = time(NULL); |
64 |
|
page_stats.pages_pagein=0; |
65 |
|
page_stats.pages_pageout=0; |
66 |
|
|
78 |
|
page_stats.pages_pageout+=(long long)cs.cpu_vminfo.pgpgout; |
79 |
|
} |
80 |
|
|
69 |
– |
page_stats.systime=time(NULL); |
70 |
– |
|
81 |
|
kstat_close(kc); |
82 |
|
#endif |
83 |
< |
#ifdef LINUX |
84 |
< |
if((f=fopen("/proc/stat", "r"))==NULL){ |
85 |
< |
return NULL; |
86 |
< |
} |
87 |
< |
if((line_ptr=f_read_line(f, "page"))==NULL){ |
83 |
> |
#if defined(LINUX) || defined(CYGWIN) |
84 |
> |
if ((f = fopen("/proc/vmstat", "r")) != NULL) { |
85 |
> |
while ((line_ptr = f_read_line(f, "")) != NULL) { |
86 |
> |
long long value; |
87 |
> |
|
88 |
> |
if (sscanf(line_ptr, "%*s %lld", &value) != 1) { |
89 |
> |
continue; |
90 |
> |
} |
91 |
> |
|
92 |
> |
if (strncmp(line_ptr, "pgpgin ", 7) == 0) { |
93 |
> |
page_stats.pages_pagein = value; |
94 |
> |
} else if (strncmp(line_ptr, "pgpgout ", 8) == 0) { |
95 |
> |
page_stats.pages_pageout = value; |
96 |
> |
} |
97 |
> |
} |
98 |
> |
|
99 |
|
fclose(f); |
100 |
+ |
} else if ((f = fopen("/proc/stat", "r")) != NULL) { |
101 |
+ |
if ((line_ptr = f_read_line(f, "page")) == NULL) { |
102 |
+ |
fclose(f); |
103 |
+ |
return NULL; |
104 |
+ |
} |
105 |
+ |
|
106 |
+ |
if (sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout) != 2) { |
107 |
+ |
fclose(f); |
108 |
+ |
return NULL; |
109 |
+ |
} |
110 |
+ |
|
111 |
+ |
fclose(f); |
112 |
+ |
} else { |
113 |
|
return NULL; |
114 |
|
} |
115 |
< |
if((sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout))!=2){ |
115 |
> |
#endif |
116 |
> |
#ifdef FREEBSD |
117 |
> |
size = sizeof page_stats.pages_pagein; |
118 |
> |
if (sysctlbyname("vm.stats.vm.v_swappgsin", &page_stats.pages_pagein, &size, NULL, 0) < 0){ |
119 |
> |
return NULL; |
120 |
> |
} |
121 |
> |
size = sizeof page_stats.pages_pageout; |
122 |
> |
if (sysctlbyname("vm.stats.vm.v_swappgsout", &page_stats.pages_pageout, &size, NULL, 0) < 0){ |
123 |
> |
return NULL; |
124 |
> |
} |
125 |
> |
#endif |
126 |
> |
#ifdef NETBSD |
127 |
> |
if ((uvm = get_uvmexp()) == NULL) { |
128 |
|
return NULL; |
129 |
|
} |
130 |
< |
page_stats.systime=time(NULL); |
131 |
< |
fclose(f); |
86 |
< |
|
130 |
> |
page_stats.pages_pagein = uvm->pgswapin; |
131 |
> |
page_stats.pages_pageout = uvm->pgswapout; |
132 |
|
#endif |
133 |
|
|
134 |
|
return &page_stats; |