#include <epicsExport.h>
#include <genSubRecord.h>
#include <stringinRecord.h>
+#include <sys/stat.h>
#include "worker.h"
unsigned long cwctime; /* wall clock time for core CPU usage */
} TheStat;
-static void initStat(TheStat *my)
+/*static void initStat(TheStat *my)*/
+void initStat(TheStat *my)
{
my->utime = 0;
my->stime = 0;
my->cwctime = 0;
}
-static void initProcStat(TheStat *my)
+/*static */
+void initProcStat(TheStat *my)
{
my->utime = 0;
my->stime = 0;
my->pwctime = 0;
}
-static void parseCpuStat( TheStat *theStat, uint32_t coreNr )
+/*static*/
+void parseCpuStat( TheStat *theStat, uint32_t coreNr )
{
int fd;
char filename[24];
}
}
-static int parseProcStat( TheStat *theStat, pid_t pid )
+/*static*/
+int parseProcStat( TheStat *theStat, pid_t pid )
{
int fd;
char filename[24];
struct stat statBufS, *statBuf = &statBufS;
snprintf (dir, sizeof(dir), "/proc/%d", (int) pid);
-
+ if(cpuDebug)
+ printf("<E> cpu.c: parseProcStat directory %s before stat - pid=%d\n",dir, (int) pid);
stat(dir, statBuf);
/* Return if the process is gone */
gettimeofday(&wctime, NULL);
/* Convert to micro seconds */
theStat->pwctime = (int) 1000. * (double)wctime.tv_sec + (double)wctime.tv_usec / 1000000.0;
+ if(cpuDebug)
+ printf("<E> cpu.c: parseProcStat sees no directory %s!\n",dir);
return 0;
}
return 0;
}
-static int getProcCpuUsage(TheStat *theStat, TheStat *theStat_old)
+/*static*/
+int getProcCpuUsage(TheStat *theStat, TheStat *theStat_old)
{
- int procCPU = 100 * ((theStat->utime + theStat->stime +
- theStat->cutime + theStat->cstime) -
- (theStat_old->utime + theStat_old->stime +
- theStat_old->cutime + theStat_old->cstime)) /
- (theStat->pwctime - theStat_old->pwctime);
+ int procCPU=0;
+ double deltaT=theStat->pwctime - theStat_old->pwctime;
+ if(cpuDebug)
+ printf("<E> cpu.c: getProcCpuUsage - delta T=%e us!\n",deltaT);
+ if(deltaT>0)
+ {
+
+
+
+ procCPU= 100 * ((theStat->utime + theStat->stime +
+ theStat->cutime + theStat->cstime) -
+ (theStat_old->utime + theStat_old->stime +
+ theStat_old->cutime + theStat_old->cstime)) /
+ deltaT;
+
+
+ }
+ else
+ {
+
+ if(cpuDebug)
+ printf("<E> cpu.c: Worker_getProcCpuUsage with zero delta T !\n");
+ }
+ if(cpuDebug)
+ printf("<E> cpu.c:procCPU:%d utime:%ld oldutime:%ld , stime:%ld oldstime:%ld , cutime%ld oldcutime:%ld, cstime:%ld oldcstime:%ld !\n",
+ procCPU, theStat->utime, theStat_old->utime, theStat->stime, theStat_old->stime, theStat->cutime, theStat_old->cutime,
+ theStat->cstime, theStat_old->cstime);
+
return procCPU;
}
-static int getCoreCpuUsage(TheStat *theStat, TheStat * theStat_old)
+/*static*/
+int getCoreCpuUsage(TheStat *theStat, TheStat * theStat_old)
{
- int coreCPU = 100 * (theStat->cputime - theStat_old->cputime) /
- (theStat->cwctime - theStat_old->cwctime);
-
+ int coreCPU=0;
+ double deltaT=theStat->cwctime - theStat_old->cwctime;
+ if(deltaT>0)
+ {
+ coreCPU = 100 * (theStat->cputime - theStat_old->cputime) /
+ deltaT;
+ }
+ else
+ {
+ if(cpuDebug)
+ printf("<E> cpu.c: Worker_getCoreCpuUsage with zero delta T !\n");
+
+
+ }
return coreCPU;
}
}
else {
eb_pid = (uint32_t)tmp;
+ if(cpuDebug)
+ printf("<E> cpu.c: Worker_getStatistic has evtbuild PID %d\n", eb_pid);
}
/* Get core number of evtbuild */
}
else {
nm_pid = (uint32_t)tmp;
+ if(cpuDebug)
+ printf("<E> cpu.c: Worker_getStatistic has netmem PID %d\n", nm_pid);
}
/* Get core number of evtbuild */