1 |
|
/* |
2 |
< |
* i-scream central monitoring system |
2 |
> |
* i-scream libstatgrab |
3 |
|
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
34 |
|
#if defined(LINUX) || defined(CYGWIN) |
35 |
|
#include <stdio.h> |
36 |
|
#endif |
37 |
< |
#ifdef FREEBSD |
37 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
38 |
|
#include <sys/sysctl.h> |
39 |
|
#include <sys/dkstat.h> |
40 |
|
#endif |
50 |
|
#include <sys/dkstat.h> |
51 |
|
#endif |
52 |
|
|
53 |
< |
static cpu_states_t cpu_now; |
53 |
> |
static sg_cpu_stats cpu_now; |
54 |
|
static int cpu_now_uninit=1; |
55 |
|
|
56 |
< |
cpu_states_t *get_cpu_totals(){ |
56 |
> |
sg_cpu_stats *sg_get_cpu_stats(){ |
57 |
|
|
58 |
|
#ifdef SOLARIS |
59 |
|
kstat_ctl_t *kc; |
64 |
|
FILE *f; |
65 |
|
#endif |
66 |
|
#ifdef ALLBSD |
67 |
< |
#ifndef FREEBSD |
67 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
68 |
|
int mib[2]; |
69 |
|
#endif |
70 |
|
#ifdef NETBSD |
125 |
|
cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle; |
126 |
|
#endif |
127 |
|
#ifdef ALLBSD |
128 |
< |
#ifdef FREEBSD |
128 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
129 |
|
size = sizeof cp_time; |
130 |
|
if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0){ |
131 |
|
return NULL; |
159 |
|
return &cpu_now; |
160 |
|
} |
161 |
|
|
162 |
< |
cpu_states_t *get_cpu_diff(){ |
163 |
< |
static cpu_states_t cpu_diff; |
164 |
< |
cpu_states_t cpu_then, *cpu_tmp; |
162 |
> |
sg_cpu_stats *sg_get_cpu_stats_diff(){ |
163 |
> |
static sg_cpu_stats cpu_diff; |
164 |
> |
sg_cpu_stats cpu_then, *cpu_tmp; |
165 |
|
|
166 |
|
if (cpu_now_uninit){ |
167 |
< |
if((cpu_tmp=get_cpu_totals())==NULL){ |
168 |
< |
/* Should get_cpu_totals fail */ |
167 |
> |
if((cpu_tmp=sg_get_cpu_stats())==NULL){ |
168 |
> |
/* Should sg_get_cpu_stats fail */ |
169 |
|
return NULL; |
170 |
|
} |
171 |
|
return cpu_tmp; |
181 |
|
cpu_then.total=cpu_now.total; |
182 |
|
cpu_then.systime=cpu_now.systime; |
183 |
|
|
184 |
< |
if((cpu_tmp=get_cpu_totals())==NULL){ |
184 |
> |
if((cpu_tmp=sg_get_cpu_stats())==NULL){ |
185 |
|
return NULL; |
186 |
|
} |
187 |
|
|
197 |
|
return &cpu_diff; |
198 |
|
} |
199 |
|
|
200 |
< |
cpu_percent_t *cpu_percent_usage(){ |
201 |
< |
static cpu_percent_t cpu_usage; |
202 |
< |
cpu_states_t *cs_ptr; |
200 |
> |
sg_cpu_percents *sg_get_cpu_percents(){ |
201 |
> |
static sg_cpu_percents cpu_usage; |
202 |
> |
sg_cpu_stats *cs_ptr; |
203 |
|
|
204 |
< |
cs_ptr=get_cpu_diff(); |
204 |
> |
cs_ptr=sg_get_cpu_stats_diff(); |
205 |
|
if(cs_ptr==NULL){ |
206 |
|
return NULL; |
207 |
|
} |