ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/cpu_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/cpu_stats.c (file contents):
Revision 1.10 by tdb, Sun Aug 24 20:24:09 2003 UTC vs.
Revision 1.15 by tdb, Tue Nov 11 10:27:04 2003 UTC

# Line 29 | Line 29
29   #include <sys/sysinfo.h>
30   #include <string.h>
31   #endif
32 < #ifdef LINUX
32 > #if defined(LINUX) || defined(CYGWIN)
33   #include <stdio.h>
34   #endif
35   #ifdef FREEBSD
36   #include <sys/sysctl.h>
37   #include <sys/dkstat.h>
38   #endif
39 + #ifdef NETBSD
40 + #include <sys/types.h>
41 + #include <sys/param.h>
42 + #include <sys/sysctl.h>
43 + #include <sys/sched.h>
44 + #endif
45  
46   static cpu_states_t cpu_now;
47   static int cpu_now_uninit=1;
# Line 47 | Line 53 | cpu_states_t *get_cpu_totals(){
53          kstat_t *ksp;
54          cpu_stat_t cs;
55   #endif
56 < #ifdef LINUX
56 > #if defined(LINUX) || defined(CYGWIN)
57          FILE *f;
58   #endif
59 < #ifdef FREEBSD
59 > #ifdef ALLBSD
60 > #ifndef FREEBSD
61 >        int mib[2];
62 > #endif
63 > #ifdef NETBSD
64 >        u_int64_t cp_time[CPUSTATES];
65 > #else
66          long cp_time[CPUSTATES];
67 + #endif
68          size_t size;
69   #endif
70          
# Line 86 | Line 99 | cpu_states_t *get_cpu_totals(){
99          
100          kstat_close(kc);
101   #endif
102 < #ifdef LINUX
102 > #if defined(LINUX) || defined(CYGWIN)
103          if ((f=fopen("/proc/stat", "r" ))==NULL) {
104                  return NULL;
105          }
# Line 104 | Line 117 | cpu_states_t *get_cpu_totals(){
117  
118          cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle;
119   #endif
120 + #ifdef ALLBSD
121   #ifdef FREEBSD
122 <        if (sysctlbyname("kern.cp_time", NULL, &size, NULL, NULL) < 0){
122 >        size = sizeof cp_time;
123 >        if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0){
124                  return NULL;
110        }
111        if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, NULL) < 0){
112                return NULL;
125          }
126 + #else
127 +        mib[0] = CTL_KERN;
128 +        mib[1] = KERN_CP_TIME;
129 +        size = sizeof cp_time;
130 +        if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0) {
131 +                return NULL;
132 +        }
133 + #endif
134  
135          cpu_now.user=cp_time[CP_USER];
136          cpu_now.nice=cp_time[CP_NICE];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines