From 68fca63a97619599f100d2aa42dbf27fbc5a7a26 Mon Sep 17 00:00:00 2001 From: hadaq <hadaq> Date: Fri, 10 Sep 2010 14:21:09 +0000 Subject: [PATCH] CPU usage moved to cpu.c --- ebctrl/ioc/ebctrlApp/src/evtbuild.c | 52 ++++------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/ebctrl/ioc/ebctrlApp/src/evtbuild.c b/ebctrl/ioc/ebctrlApp/src/evtbuild.c index 78bcc6c..fdc9b90 100644 --- a/ebctrl/ioc/ebctrlApp/src/evtbuild.c +++ b/ebctrl/ioc/ebctrlApp/src/evtbuild.c @@ -1,8 +1,10 @@ +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <unistd.h> +#include <sys/time.h> #include <dbDefs.h> #include <registryFunction.h> @@ -28,44 +30,6 @@ static char *unit (unsigned long v) return retVal; } -static char* itoa(int val, int base){ - - static char buf[32] = {0}; - - int i = 30; - - for(; val && i ; --i, val /= base) - buf[i] = "0123456789abcdef"[val % base]; - - return &buf[i+1]; -} - -static uint32_t getCPU_usage(uint32_t pid) -{ - FILE *fp; - char ps[100]="ps -o pcpu -p "; - char cpu[100]; - - /* PID must be more than zero */ - if( ! (pid > 0) ) - return 0; - - strcat(ps, itoa(pid, 10)); - - fp=popen(ps,"r"); - - while (fgets(ps, 100, fp)!=NULL) - sprintf(cpu, "%s", ps); - - pclose(fp); - - if( strstr(cpu, "%CPU") != (char*) NULL ){ - return 0; - } - - return (uint32_t) atoi(cpu); -} - long evtbuild_init( struct genSubRecord *pgsub ) { return(0); @@ -74,7 +38,7 @@ long evtbuild_init( struct genSubRecord *pgsub ) long evtbuild_proc( struct genSubRecord *pgsub ) { - uint32_t *out[17]; + uint32_t *out[16]; unsigned long tmp; static unsigned long temp[10] = {0}; int i; @@ -95,10 +59,9 @@ long evtbuild_proc( struct genSubRecord *pgsub ) out[13] = (uint32_t *)pgsub->valn; /* number of EB machine (1 = lxhadeb01) */ out[14] = (uint32_t *)pgsub->valo; /* PID */ out[15] = (uint32_t *)pgsub->valp; /* core number */ - out[16] = (uint32_t *)pgsub->valq; /* CPU usage */ /* pgsub->vall : bytesWrittenRate in stringin record (array of char's) */ - for( i=0; i<17; i++ ) + for( i=0; i<16; i++ ) *out[i] = 0; char buf[_POSIX_PATH_MAX]; @@ -294,15 +257,12 @@ long evtbuild_proc( struct genSubRecord *pgsub ) if( Worker_getStatistic( buf, "PID", &tmp ) == -1) { *out[14] = 0; - *out[15] = 0; if(evtbuildDebug) printf("<E> evtbuild.c: Worker_getStatistic failed for PID!\n"); } else { *out[14] = (uint32_t)tmp; - - *out[15] = getCPU_usage(tmp); } /* @@ -310,13 +270,13 @@ long evtbuild_proc( struct genSubRecord *pgsub ) */ if( Worker_getStatistic( buf, "coreNr", &tmp ) == -1) { - *out[16] = 0; + *out[15] = 0; if(evtbuildDebug) printf("<E> evtbuild.c: Worker_getStatistic failed for coreNr!\n"); } else { - *out[16] = (uint32_t)tmp; + *out[15] = (uint32_t)tmp; } /* -- 2.43.0