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);
long evtbuild_proc( struct genSubRecord *pgsub )
{
- uint32_t *out[14];
+ uint32_t *out[17];
unsigned long tmp;
static unsigned long temp[10] = {0};
int i;
out[11] = (uint32_t *)pgsub->vall; /* dataMover = number of selected Data Mover */
out[12] = (uint32_t *)pgsub->valm; /* diskNr = disk number where data is being written */
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<12; i++ )
+ for( i=0; i<17; i++ )
*out[i] = 0;
+ /*
+ * *************** nrOfMsgs and status of EB ***************
+ */
+
char buf[_POSIX_PATH_MAX];
sprintf( buf, "%s%s", "daq_evtbuild", getenv("EBNUM") );
}
}
+ /*
+ * ************** bytesWritten ***************
+ */
+
if( Worker_getStatistic( buf, "bytesWritten", &tmp ) == -1) {
*out[9] = 0; /* zero data rate */
if(evtbuildDebug)
*out[1] = (int)((*out[1])/1024./1024. + 0.5);
}
+ /*
+ * ************** evtsComplete ***************
+ */
+
if( Worker_getStatistic( buf, "evtsComplete", &tmp ) == -1) {
*out[8] = 0; /* zero evtComp rate */
if(evtbuildDebug)
temp[2] = *out[2];
}
+ /*
+ * ************** evtsDiscarded ***************
+ */
+
if( Worker_getStatistic( buf, "evtsDiscarded", &tmp ) == -1) {
*out[10] = 0; /* zero evtDisc rate */
if(evtbuildDebug)
temp[3] = *out[3];
}
+ /*
+ * ************** evtsDataError ***************
+ */
+
if( Worker_getStatistic( buf, "evtsDataError", &tmp ) == -1){
if(evtbuildDebug)
printf("<E> evtbuild.c: Worker_getStatistic failed for evtsDataError!\n");
*out[4] = (uint32_t)tmp;
}
+ /*
+ * ************** evtsTagError ***************
+ */
+
if( Worker_getStatistic( buf, "evtsTagError", &tmp ) == -1){
if(evtbuildDebug)
printf("<E> evtbuild.c: Worker_getStatistic failed for evtsTagError!\n");
*out[5] = (uint32_t)tmp;
}
+ /*
+ * ************** dataMover ***************
+ */
+
if( Worker_getStatistic( buf, "dataMover", &tmp ) == -1){
if(evtbuildDebug)
printf("<E> evtbuild.c: Worker_getStatistic failed for dataMover!\n");
*out[11] = (uint32_t)tmp;
}
+ /*
+ * ************** diskNumEB ***************
+ */
if( Worker_getStatistic( buf, "diskNumEB", &tmp ) == -1){
if(evtbuildDebug)
*out[12] = (uint32_t)tmp;
}
+ /*
+ * ************** evtbuildBuff ***************
+ */
+
char ebbuf[100];
for( i=0; i<(*out[0]); i++ ) {
}
}
+ /*
+ * ************** number from hostname ***************
+ */
+
/* Get host name and extract the number from its name */
char hostname[50];
char *c_ptr;
else{
*out[13] = (uint32_t) strtoul(c_ptr, NULL, 0);
}
+
+ /*
+ * ************** PID of EB ***************
+ */
+ if( Worker_getStatistic( buf, "PID", &tmp ) == -1) {
+ *out[14] = 0;
+ if(evtbuildDebug)
+ printf("<E> evtbuild.c: Worker_getStatistic failed for PID!\n");
+ }
+ else {
+ *out[14] = (uint32_t)tmp;
+
+ *out[15] = getCPU_usage(tmp);
+ }
+
+ /*
+ * ************** core number ***************
+ */
+
+ if( Worker_getStatistic( buf, "coreNr", &tmp ) == -1) {
+ *out[16] = 0;
+ if(evtbuildDebug)
+ printf("<E> evtbuild.c: Worker_getStatistic failed for coreNr!\n");
+ }
+ else {
+ *out[16] = (uint32_t)tmp;
+ }
+
/*
* int bytedCoverted;
* sprintf( buf, "%s", unit(*out[9]));