Add error checking for the load metrics and adds a header and define which
was probably needed (but wasn't there before).

Someone with access to an AIX system could verify if the <sys/proc.h> is
really needed for SBITS as indicated in the documentation and if running in an
old version of AIX if the #if defined is needed.

Signed-off-by: Carlo Marcelo Arenas Belon <[EMAIL PROTECTED]>
---
 trunk/monitor-core/libmetrics/aix/metrics.c |   32 +++++++++++++++++++++------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/trunk/monitor-core/libmetrics/aix/metrics.c 
b/trunk/monitor-core/libmetrics/aix/metrics.c
index a4ab28b..2d37579 100644
--- a/trunk/monitor-core/libmetrics/aix/metrics.c
+++ b/trunk/monitor-core/libmetrics/aix/metrics.c
@@ -39,6 +39,7 @@
 #include <odmi.h>
 #include <cf.h>
 #include <sys/utsname.h>
+#include <sys/proc.h>
 
 #include <libperfstat.h>
 
@@ -71,7 +72,15 @@ struct product {
         char *supersedes;        /* [512] offset: 0xf4 ( 244) */
 };
 
-
+#if defined(_AIX43)
+#ifndef SBITS
+/*
+ * For multiplication of fractions that are stored as integers, including
+ * p_pctcpu.  Not allowed to do floating point arithmetic in the kernel.
+ */
+#define SBITS   16
+#endif
+#endif
 
 #define MAX_CPUS  64
 
@@ -437,9 +446,12 @@ g_val_t
 load_one_func ( void )
 {
    g_val_t val;
+   perfstat_cpu_total_t c;
    
-   perfstat_cpu_total(NULL,  &cpu_total_buffer, sizeof(perfstat_cpu_total_t), 
1);
-   val.f =(1.0*cpu_total_buffer.loadavg[0])/(1<<SBITS) ;
+   if (perfstat_cpu_total(NULL,  &c, sizeof(perfstat_cpu_total_t), 1) == -1)
+      val.f = 0.0;
+   else
+      val.f = (float)c.loadavg[0]/(float)(1<<SBITS);
    return val;
 }
 
@@ -447,9 +459,12 @@ g_val_t
 load_five_func ( void )
 {  
    g_val_t val;
+   perfstat_cpu_total_t c;
 
-   perfstat_cpu_total(NULL,  &cpu_total_buffer, sizeof(perfstat_cpu_total_t), 
1);
-   val.f =(1.0*cpu_total_buffer.loadavg[1])/(1<<SBITS) ;
+   if (perfstat_cpu_total(NULL,  &c, sizeof(perfstat_cpu_total_t), 1) == -1)
+      val.f = 0.0;
+   else
+      val.f = (float)c.loadavg[1]/(float)(1<<SBITS);
    return val;
 }
 
@@ -457,9 +472,12 @@ g_val_t
 load_fifteen_func ( void )
 {
    g_val_t val;
+   perfstat_cpu_total_t c;
 
-   perfstat_cpu_total(NULL,  &cpu_total_buffer, sizeof(perfstat_cpu_total_t), 
1);
-   val.f =(1.0*cpu_total_buffer.loadavg[2])/(1<<SBITS)*1.0 ;
+   if (perfstat_cpu_total(NULL, &c, sizeof(perfstat_cpu_total_t), 1) == -1)
+      val.f = 0.0;
+   else
+      val.f = (float)c.loadavg[2]/(float)(1<<SBITS);
 
    return val;
 }
-- 
1.5.3.7


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ganglia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-developers

Reply via email to