#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <stdint.h>
+#include <unistd.h>
#include <dbDefs.h>
#include <registryFunction.h>
return(0);
}
+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 netmem_proc( struct genSubRecord *pgsub )
{
- uint32_t *out[8];
+ uint32_t *out[11];
unsigned long tmp;
int i;
out[5] = (uint32_t *)pgsub->valf; /* msgsDis = messages discarded */
out[6] = (uint32_t *)pgsub->valg; /* bytercv = bytes received */
out[7] = (uint32_t *)pgsub->valh; /* byteRRate = bytes received rate */
+ out[8] = (uint32_t *)pgsub->vali; /* PID */
+ out[9] = (uint32_t *)pgsub->valj; /* core number */
+ out[10] = (uint32_t *)pgsub->valk; /* CPU usage */
- for( i=0; i<8; i++ )
+ for( i=0; i<11; i++ )
*out[i] = 0;
char bufmem[_POSIX_PATH_MAX];
sprintf( bufmem, "%s%s", "daq_netmem", getenv("EBNUM") );
+
+ /*
+ * *************** nrOfMsgs ***************
+ */
+
if( Worker_getStatistic( bufmem, "nrOfMsgs", &tmp ) == -1) {
+ *out[0] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for nrOfMsgs!\n");
}
printf("<D> netmem.c: Worker_getStatistic::nrOfMsgs = %lu\n", tmp);
}
+ /*
+ * *************** netmemBuff ***************
+ */
+
char buf[100];
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "netmemBuff", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[1] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * *************** pktsReceived ***************
+ */
+
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "pktsReceived", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[2] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * *************** msgsReceived ***************
+ */
+
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "msgsReceived", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[3] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * *************** pktsDiscarded ***************
+ */
+
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "pktsDiscarded", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[4] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * *************** msgsDiscarded ***************
+ */
+
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "msgsDiscarded", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[5] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * *************** bytesReceived ***************
+ */
+
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "bytesReceived", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[6] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * *************** bytesReceivedRate ***************
+ */
+
for( i=0; i<(*out[0]); i++ ) {
sprintf( buf, "%s%d", "bytesReceivedRate", i );
if( Worker_getStatistic( bufmem, buf, &tmp ) == -1) {
+ *out[7] = 0;
+
if(netmemDebug)
printf("<E> netmem.c: Worker_getStatistic failed for %s!\n", buf);
}
}
}
+ /*
+ * ************** PID of netmem ***************
+ */
+
+ if( Worker_getStatistic( bufmem, "PID", &tmp ) == -1) {
+ *out[8] = 0;
+ *out[9] = 0;
+
+ if(netmemDebug)
+ printf("<E> netmem.c: Worker_getStatistic failed for PID!\n");
+ }
+ else {
+ *out[8] = (uint32_t)tmp;
+
+ *out[9] = getCPU_usage(tmp);
+ }
+
+ /*
+ * ************** core number ***************
+ */
+
+ if( Worker_getStatistic( bufmem, "coreNr", &tmp ) == -1) {
+ *out[10] = 0;
+
+ if(netmemDebug)
+ printf("<E> netmem.c: Worker_getStatistic failed for coreNr!\n");
+ }
+ else {
+ *out[10] = (uint32_t)tmp;
+ }
return(0);
}