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-2003 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 |
32 |
|
#ifdef LINUX |
33 |
|
#include <stdio.h> |
34 |
|
#endif |
35 |
+ |
#ifdef FREEBSD |
36 |
+ |
#include <sys/sysctl.h> |
37 |
+ |
#include <sys/dkstat.h> |
38 |
+ |
#endif |
39 |
|
|
40 |
|
static cpu_states_t cpu_now; |
41 |
|
static int cpu_now_uninit=1; |
50 |
|
#ifdef LINUX |
51 |
|
FILE *f; |
52 |
|
#endif |
53 |
+ |
#ifdef FREEBSD |
54 |
+ |
long cp_time[CPUSTATES]; |
55 |
+ |
size_t size; |
56 |
+ |
#endif |
57 |
|
|
58 |
|
cpu_now.user=0; |
59 |
< |
/* Not stored in linux */ |
59 |
> |
/* Not stored in linux or freebsd */ |
60 |
|
cpu_now.iowait=0; |
61 |
|
cpu_now.kernel=0; |
62 |
|
cpu_now.idle=0; |
63 |
< |
/* Not stored in linux */ |
63 |
> |
/* Not stored in linux or freebsd */ |
64 |
|
cpu_now.swap=0; |
65 |
|
cpu_now.total=0; |
66 |
|
/* Not stored in solaris */ |
103 |
|
fclose(f); |
104 |
|
|
105 |
|
cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle; |
106 |
+ |
#endif |
107 |
+ |
#ifdef FREEBSD |
108 |
+ |
if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0){ |
109 |
+ |
return NULL; |
110 |
+ |
} |
111 |
+ |
|
112 |
+ |
cpu_now.user=cp_time[CP_USER]; |
113 |
+ |
cpu_now.nice=cp_time[CP_NICE]; |
114 |
+ |
cpu_now.kernel=cp_time[CP_SYS]; |
115 |
+ |
cpu_now.idle=cp_time[CP_IDLE]; |
116 |
+ |
|
117 |
+ |
cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle; |
118 |
+ |
|
119 |
|
#endif |
120 |
|
|
121 |
|
cpu_now.systime=time(NULL); |