50 |
|
#include <sys/sysctl.h> |
51 |
|
#include <sys/dkstat.h> |
52 |
|
#endif |
53 |
+ |
#ifdef HPUX |
54 |
+ |
#include <sys/param.h> |
55 |
+ |
#include <sys/pstat.h> |
56 |
+ |
#include <sys/dk.h> |
57 |
+ |
#endif |
58 |
|
|
59 |
|
static sg_cpu_stats cpu_now; |
60 |
|
static int cpu_now_uninit=1; |
61 |
|
|
62 |
|
sg_cpu_stats *sg_get_cpu_stats(){ |
63 |
|
|
64 |
+ |
#ifdef HPUX |
65 |
+ |
struct pst_dynamic pstat_dynamic; |
66 |
+ |
int i; |
67 |
+ |
#endif |
68 |
|
#ifdef SOLARIS |
69 |
|
kstat_ctl_t *kc; |
70 |
|
kstat_t *ksp; |
90 |
|
cpu_now.iowait=0; |
91 |
|
cpu_now.kernel=0; |
92 |
|
cpu_now.idle=0; |
93 |
< |
/* Not stored in linux or freebsd */ |
93 |
> |
/* Not stored in linux, freebsd, or hpux */ |
94 |
|
cpu_now.swap=0; |
95 |
|
cpu_now.total=0; |
96 |
|
/* Not stored in solaris */ |
97 |
|
cpu_now.nice=0; |
98 |
|
|
99 |
+ |
#ifdef HPUX |
100 |
+ |
if (pstat_getdynamic(&pstat_dynamic, sizeof(pstat_dynamic), 1, 0) == -1) { |
101 |
+ |
sg_set_error_with_errno(SG_ERROR_PSTAT, "pstat_dynamic"); |
102 |
+ |
return NULL; |
103 |
+ |
} |
104 |
+ |
cpu_now.user = pstat_dynamic.psd_cpu_time[CP_USER]; |
105 |
+ |
cpu_now.iowait = pstat_dynamic.psd_cpu_time[CP_WAIT]; |
106 |
+ |
cpu_now.kernel = pstat_dynamic.psd_cpu_time[CP_SSYS] + pstat_dynamic.psd_cpu_time[CP_SYS]; |
107 |
+ |
cpu_now.idle = pstat_dynamic.psd_cpu_time[CP_IDLE]; |
108 |
+ |
cpu_now.nice = pstat_dynamic.psd_cpu_time[CP_NICE]; |
109 |
+ |
for (i = 0; i < PST_MAX_CPUSTATES; i++) { |
110 |
+ |
cpu_now.total += pstat_dynamic.psd_cpu_time[i]; |
111 |
+ |
} |
112 |
+ |
#endif |
113 |
|
#ifdef SOLARIS |
114 |
|
if ((kc = kstat_open()) == NULL) { |
115 |
|
sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); |
133 |
|
#endif |
134 |
|
#if defined(LINUX) || defined(CYGWIN) |
135 |
|
if ((f=fopen("/proc/stat", "r" ))==NULL) { |
136 |
< |
sg_set_error(SG_ERROR_OPEN, "/proc/stat"); |
136 |
> |
sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/stat"); |
137 |
|
return NULL; |
138 |
|
} |
139 |
|
/* The very first line should be cpu */ |
155 |
|
#if defined(FREEBSD) || defined(DFBSD) |
156 |
|
size = sizeof cp_time; |
157 |
|
if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) < 0){ |
158 |
< |
sg_set_error(SG_ERROR_SYSCTLBYNAME, "kern.cp_time"); |
158 |
> |
sg_set_error_with_errno(SG_ERROR_SYSCTLBYNAME, "kern.cp_time"); |
159 |
|
return NULL; |
160 |
|
} |
161 |
|
#else |
168 |
|
size = sizeof cp_time; |
169 |
|
if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0) { |
170 |
|
#ifdef NETBSD |
171 |
< |
sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_CP_TIME"); |
171 |
> |
sg_set_error_with_errno(SG_ERROR_SYSCTL, |
172 |
> |
"CTL_KERN.KERN_CP_TIME"); |
173 |
|
#else |
174 |
< |
sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_CPTIME"); |
174 |
> |
sg_set_error_with_errno(SG_ERROR_SYSCTL, |
175 |
> |
"CTL_KERN.KERN_CPTIME"); |
176 |
|
#endif |
177 |
|
return NULL; |
178 |
|
} |