-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/netmem.c,v 6.31 2008-04-08 14:56:47 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/netmem.c,v 6.32 2008-05-28 14:57:04 hadaq Exp $";
#define _POSIX_C_SOURCE 199309L
unsigned int buffStat;
} TheArgs;
+typedef struct TheStatsS
+{
+ unsigned long *netmemBuff[MAXINPATH];
+ unsigned long *nrOfMsgs;
+ unsigned long *recvBytesPS[MAXINPATH];
+} TheStats;
+
static jmp_buf terminateJmp;
void sigHandler(int sig)
static void usage(const char *progName)
{
syslog(LOG_ERR, "Usage: %s -i inPath [-i inPath] -m nrOfMsgs [-p priority]", progName);
- syslog (LOG_ERR, "[-b 0|1] show fill levels of buffers]");
+ syslog (LOG_ERR, "[-b] show fill levels of buffers]");
}
static void argsDump(TheArgs *my)
inPathCntFromParam = my->inPathCnt;
my->inPathCnt = 0;
- while ((i = getopt(argc, argv, "ai:m:q:p:v:b:")) != -1) {
+ while ((i = getopt(argc, argv, "ai:m:q:p:v:b")) != -1) {
switch (i) {
case 'm':
my->nrOfMsgs = atoi(optarg);
strcpy(my->verbosity, optarg);
break;
case 'b':
- my->buffStat = strtoul (optarg, NULL, 0);
+ my->buffStat = 1;
break;
default:
return -1;
printf ("Time: %s.%03ld\n", time_string, milliseconds);
}
-static void
-statsBufferDump (TheArgs * theArgs, float interval, ShmTrans **shmtr, NetTrans **my)
+static void add2Stat( TheArgs * theArgs, TheStats * my, float interval, ShmTrans **shmtr, NetTrans **nettr ) {
+
+ /* Add statistic for fill levels of buffers in percentage. */
+
+ static time_t t_0 = 0;
+ float buffSize, queueSize;
+ time_t t, dT;
+ int i;
+ unsigned long fillLevel;
+ static unsigned long lastBytesRecv[MAXINPATH];
+
+ t = time (NULL);
+ dT = t - t_0;
+
+ if( dT >= interval ) {
+ for( i=0; i<theArgs->nrOfMsgs; i++ ) {
+ buffSize = 2*theArgs->varQSize[i];
+ queueSize = HadTuQueue_size(shmtr[i]->wrQueue);
+
+ /* Add here statistic for fill levels of buffers */
+ fillLevel = (unsigned long) (100*queueSize+0.5)/buffSize;
+ (*my->netmemBuff[i]) = fillLevel;
+
+ /* Add more statistic for recv bytes per second */
+ (*my->recvBytesPS[i]) = *nettr[i]->bytesReceived - lastBytesRecv[i];
+ lastBytesRecv[i] = *nettr[i]->bytesReceived;
+
+ }
+ }
+
+ t_0 = t;
+}
+
+static void statsBufferDump (TheArgs * theArgs, float interval, ShmTrans **shmtr, NetTrans **my)
{
static time_t t0 = 0;
time_t t, dT;
/* fprintf (stderr, " dT: %.0lf interval: %.0lf", (double)dT, interval); */
- if (dT >= interval && theArgs->buffStat == 1)
+ if (dT >= interval && theArgs->buffStat)
{
if( outputNum == 1) {
int i;
- if (theArgs->isStandalone && strcmp(theArgs->verbosity, "info") == 0 && (dT = (time(NULL) - lastTime)) >= interval && theArgs->buffStat == 0) {
+ if (theArgs->isStandalone && strcmp(theArgs->verbosity, "info") == 0 && (dT = (time(NULL) - lastTime)) >= interval && !(theArgs->buffStat)) {
fputs("==============================================================================\n", stderr);
for (i = 0; i < theArgs->nrOfMsgs; i++) {
fprintf(stderr, "%17s%02d:%6s", "pktsReceived", i, unit(*my[i]->pktsReceived));
{
int i;
TheArgs theArgsS, *theArgs = &theArgsS;
+ TheStats theStatsS, *theStats = &theStatsS;
Worker *worker;
NetTrans **netTrans;
ShmTrans **shmTrans;
openlog(argv[0], LOG_PID | LOG_PERROR, LOG_LOCAL0);
setlogmask(LOG_UPTO(LOG_INFO));
-
-
argsDefault(theArgs);
argsFromParam(theArgs, argc, argv);
if (0 > argsFromCL(theArgs, argc, argv)) {
/* otherwise use variable queue size */
/* hadTuSize[i] = theArgs->varQSize[i] - HadTu_hdrSize(); */
hadTuSize[i] = 51200;
- /* This 50 kB must be bigger than a size of a message which should usually
- * be less than 32kB (UDP_packet_size - water_mark). However some HUGE messages can appear.
- * Those HUGE messages must be below hadTuSize!!! Otherwise the code will crash.
- *
+ /*
+ * This 50 kB must be bigger than a size of a message which
+ * should usually be less than 32kB (UDP_packet_size - water_mark).
+ * However some HUGE messages can appear. Those HUGE messages must
+ * be below hadTuSize!!! Otherwise the code will crash.
+ *
* 50 kB = 51200 Bytes
* 100 kB = 102400 Bytes
* 500 kB = 512000 Bytes
}
}
storeInfoStart(argv[0], time(NULL), theArgs);
+
+ /* Add statistic for fill levels of buffers etc. */
+ for( i=0; i<theArgs->nrOfMsgs; i++ ) {
+ char buf[WORKER_MAX_NAME_LEN];
+ sprintf( buf, "netmemBuff%d", i );
+ theStats->netmemBuff[i] = Worker_addStatistic( worker, buf );
+
+ sprintf( buf, "bytesReceivedPS%d", i );
+ theStats->recvBytesPS[i] = Worker_addStatistic( worker, buf );
+ }
+
+ theStats->nrOfMsgs = Worker_addStatistic( worker, "nrOfMsgs" );
+ (*theStats->nrOfMsgs) = theArgs->nrOfMsgs;
+
Worker_initEnd(worker);
if (setjmp(terminateJmp) == 0) {
while (1) {
long msgsCompleted;
- statsDump(theArgs, netTrans, 1);
- statsBufferDump (theArgs, 1, shmTrans, netTrans);
+ add2Stat( theArgs, theStats, 1, shmTrans, netTrans );
+ statsDump( theArgs, netTrans, 1 );
+ statsBufferDump( theArgs, 1, shmTrans, netTrans );
for (i = 0; i < theArgs->nrOfMsgs; i++) {
if (hadTu[i] == NULL) {
}
}
- storeInfoStop(argv[0], time(NULL), worker, theArgs);
- statsDump(theArgs, netTrans, 0);
+ storeInfoStop( argv[0], time(NULL), worker, theArgs );
+ statsDump( theArgs, netTrans, 0 );
for (i = 0; i < theArgs->nrOfMsgs; i++) {
ShmTrans_remove(shmTrans[i]);