Replace process metrics with a MUCH more simplified version and obsoletes a
big chunk of code looking for threads and processes.
If there is any regression in this series is here.
Signed-off-by: Carlo Marcelo Arenas Belon <[EMAIL PROTECTED]>
---
trunk/monitor-core/libmetrics/aix/metrics.c | 93 +++++++++++----------------
1 files changed, 38 insertions(+), 55 deletions(-)
diff --git a/trunk/monitor-core/libmetrics/aix/metrics.c
b/trunk/monitor-core/libmetrics/aix/metrics.c
index 1758375..91a150e 100644
--- a/trunk/monitor-core/libmetrics/aix/metrics.c
+++ b/trunk/monitor-core/libmetrics/aix/metrics.c
@@ -503,7 +503,7 @@ cpu_num_func ( void )
return val;
}
-#define MAXPROCS 20
+#define MAXPROCS 1000000
/*
** Theese Missing prototypes have caused me an afternoon of real grief !!!
*/
@@ -552,72 +552,55 @@ int count_threads(pid_t pid) {
return nth;
}
-/*
-** count_procs() computes the number of processes as shown in "ps -A".
-** Pass 0 as flag if you want to get a list of all processes.
-** Pass 1 if you want to get a list of all processes with
-** runnable threads.
-*/
-int count_procs(int flag) {
-
- struct procentry64 ProcessBuffer[MAXPROCS];
- pid_t IndexPointer = 0;
- int np = 0;
- int stat_val;
- int i;
-
- while ((stat_val = getprocs64(
- &ProcessBuffer[0],
- sizeof(struct procentry64),
- NULL,
- sizeof(struct fdsinfo64),
- &IndexPointer,
- MAXPROCS )) > 0 )
-
- {
- for ( i=0; i<stat_val; i++) {
- if(flag != 0) {
- /*fprintf(stderr,"i=%d pid=%d state=%x flags=%x flags2=%x
thcount=%d\n",i,
-
ProcessBuffer[i].pi_pid,ProcessBuffer[i].pi_state,
-
ProcessBuffer[i].pi_flags,ProcessBuffer[i].pi_flags2,
- ProcessBuffer[i].pi_thcount);*/
- np += count_threads(ProcessBuffer[i].pi_pid);
- }
- else {
- np++;
- }
- }
- if (stat_val < MAXPROCS) break;
- }
-
-/*
-** Reduce by one to make proc_run more Linux "compliant".
-*/
- if ((flag != 0) && (np > 0)) np--;
-
- return np;
-}
-
-
g_val_t
proc_total_func ( void )
{
- g_val_t foo;
+ pid_t IndexPointer;
+ int n;
+ g_val_t val;
- foo.uint32 = count_procs(0);
+ IndexPointer = (pid_t)0;
+ n = getprocs( NULL, 0, NULL, 0, &IndexPointer, MAXPROCS );
+
+ if (n < 0) n = 0;
+ val.uint32 = n;
- return foo;
+ return val;
}
-
g_val_t
proc_run_func( void )
{
- g_val_t val;
+ g_val_t val;
+ perfstat_cpu_total_t c;
+ static u_longlong_t last_runque = 0;
+ static double last_time = 0.0;
+ double now, delta_t, runnable;
+ struct timeval timeValue;
+ struct timezone timeZone;
- val.uint32 = count_procs(1);
+ gettimeofday( &timeValue, &timeZone );
+
+ now = (double) (timeValue.tv_sec - boottime) + (timeValue.tv_usec /
1000000.0);
+
+ if (perfstat_cpu_total( NULL, &c, sizeof( perfstat_cpu_total_t ), 1 ) == -1)
+ runnable = 0.0;
+ else {
+ delta_t = now - last_time;
+
+ if (delta_t != 0.0)
+ runnable = (double) (c.runque - last_runque + 0.5) / delta_t;
+ else
+ runnable = 0.0;
+
+ last_runque = c.runque;
+ }
+
+ last_time = now;
+
+ val.uint32 = (unsigned int) runnable;
- return val;
+ return val;
}
g_val_t
--
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