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.25 by tdb, Mon Nov 1 18:30:17 2004 UTC vs.
Revision 1.26 by tdb, Sat Sep 24 13:29:22 2005 UTC

# Line 55 | Line 55
55   #include <sys/pstat.h>
56   #include <sys/dk.h>
57   #endif
58 + #ifdef WIN32
59 + #include <pdh.h>
60 + #include "win32.h"
61 + #endif
62  
63   static sg_cpu_stats cpu_now;
64   static int cpu_now_uninit=1;
# Line 90 | Line 94 | sg_cpu_stats *sg_get_cpu_stats(){
94          cpu_now.iowait=0;
95          cpu_now.kernel=0;
96          cpu_now.idle=0;
97 <        /* Not stored in linux, freebsd, or hpux */
97 >        /* Not stored in linux, freebsd, hpux or windows */
98          cpu_now.swap=0;
99          cpu_now.total=0;
100 <        /* Not stored in solaris */
100 >        /* Not stored in solaris or windows */
101          cpu_now.nice=0;
102  
103   #ifdef HPUX
# Line 186 | Line 190 | sg_cpu_stats *sg_get_cpu_stats(){
190          cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle;
191  
192   #endif
193 + #ifdef WIN32
194 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Win32");
195 +        return NULL;
196 + #endif
197  
198          cpu_now.systime=time(NULL);
199          cpu_now_uninit=0;
# Line 234 | Line 242 | sg_cpu_stats *sg_get_cpu_stats_diff(){
242  
243   sg_cpu_percents *sg_get_cpu_percents(){
244          static sg_cpu_percents cpu_usage;
245 + #ifndef WIN32
246          sg_cpu_stats *cs_ptr;
247  
248          cs_ptr=sg_get_cpu_stats_diff();
# Line 248 | Line 257 | sg_cpu_percents *sg_get_cpu_percents(){
257          cpu_usage.swap = ((float)cs_ptr->swap / (float)cs_ptr->total)*100;
258          cpu_usage.nice = ((float)cs_ptr->nice / (float)cs_ptr->total)*100;
259          cpu_usage.time_taken = cs_ptr->systime;
260 + #else
261 +        double result;
262  
263 <        return &cpu_usage;
263 >        if(read_counter_double(SG_WIN32_PROC_USER, &result)) {
264 >                sg_set_error(SG_ERROR_PDHREAD, PDH_USER);
265 >                return NULL;
266 >        }
267 >        cpu_usage.user = (float)result;
268 >        if(read_counter_double(SG_WIN32_PROC_PRIV, &result)) {
269 >                sg_set_error(SG_ERROR_PDHREAD, PDH_PRIV);
270 >                return NULL;
271 >        }
272 >        cpu_usage.kernel = (float)result;
273 >        if(read_counter_double(SG_WIN32_PROC_IDLE, &result)) {
274 >                sg_set_error(SG_ERROR_PDHREAD, PDH_IDLE);
275 >                return NULL;
276 >        }
277 >        /* win2000 does not have an idle counter, but does have %activity
278 >         * so convert it to idle */
279 >        cpu_usage.idle = 100 - (float)result;
280 >        if(read_counter_double(SG_WIN32_PROC_INT, &result)) {
281 >                sg_set_error(SG_ERROR_PDHREAD, PDH_INTER);
282 >                return NULL;
283 >        }
284 >        cpu_usage.iowait = (float)result;
285 > #endif
286  
287 +        return &cpu_usage;
288   }
289  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines