From: hadaq Date: Wed, 16 Jun 2010 14:44:15 +0000 (+0000) Subject: Debugging option encluded. Sergey. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=afbcbe3ec66dc1ce8a4c7fd9c96d97ca22002061;p=daqdata.git Debugging option encluded. Sergey. --- diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index 3565c4e..d31bd13 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -1,4 +1,4 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.108 2010-06-14 14:37:43 hadaq Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.109 2010-06-16 14:44:15 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L #define SYSLOG_NAMES @@ -40,6 +40,8 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada static RFILE *fRemote = NULL; #endif +#define MAXDEBUGEVTS 20 + #define MAXINPATH 100 #define NEVTIDS 64UL /* must be 2^n */ @@ -68,6 +70,8 @@ static time_t res_time; static int diff_time; static int trig_mismatch; +static int evtBrokenFlag = 0; + typedef struct TheArgsS { unsigned long nrOfMsgs; char outPath[PARAM_MAX_VALUE_LEN]; @@ -77,6 +81,13 @@ typedef struct TheArgsS { char *slowCtrlFiles[PARAM_MAX_ARRAY_LEN]; char slowCtrlFilesS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_NAME_LEN]; int slowCtrlFileCnt; + char *debugOpts[PARAM_MAX_ARRAY_LEN]; + char debugOptsS[PARAM_MAX_ARRAY_LEN][PARAM_MAX_NAME_LEN]; + int debugOptsCnt; + int debug_trignr; + int debug_errbit; + int debug_word; + unsigned long isStandalone; unsigned long priority; unsigned long queueSize[MAXINPATH]; @@ -127,12 +138,27 @@ typedef struct TheStatsS { unsigned long *evtId[NEVTIDS]; unsigned long *trigNr[MAXINPATH]; unsigned long *errBit[MAXINPATH]; + unsigned long *debugWord[MAXINPATH]; unsigned long *evtsRes; unsigned long *evtbuildBuff[MAXINPATH]; unsigned long *nrOfMsgs; unsigned long *runId; } TheStats; +typedef struct TheDebugS { + unsigned long *evtsBroken[MAXINPATH]; + unsigned long evtsBrokenS[MAXINPATH][MAXDEBUGEVTS]; + unsigned long evtsBrokenCnt[MAXINPATH]; + unsigned long *errBits[MAXINPATH]; + unsigned long errBitsS[MAXINPATH][MAXDEBUGEVTS]; + unsigned long errBitsCnt[MAXINPATH]; + unsigned long *debugWords[MAXINPATH]; + unsigned long debugWordsS[MAXINPATH][MAXDEBUGEVTS]; + unsigned long debugWordsCnt[MAXINPATH]; + unsigned long evtsLastBuilt[MAXINPATH]; +} TheDebug; + + static jmp_buf terminateJmp; void sigHandler(int sig) @@ -300,6 +326,22 @@ static void argsDump(TheArgs *my) syslog(LOG_DEBUG, "EB numder: %d", my->ebnum); } +static void initDebug(TheDebug * theDebug) +{ + + int i; + + for (i = 0; i < MAXINPATH; i++) { + theDebug->evtsBroken[i] = theDebug->evtsBrokenS[i]; + theDebug->errBits[i] = theDebug->errBitsS[i]; + theDebug->debugWords[i] = theDebug->debugWordsS[i]; + theDebug->evtsBrokenCnt[i] = 0; + theDebug->errBitsCnt[i] = 0; + theDebug->debugWordsCnt[i] = 0; + theDebug->evtsLastBuilt[i] = 0; + } +} + static void argsDefault(TheArgs *my) { int i; @@ -349,6 +391,16 @@ static void argsDefault(TheArgs *my) /* read path from DAQ_SETUP and define full file name */ sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", getenv("DAQ_SETUP")); sprintf(my->evtstat, "%s_evtstat.txt", getenv("DAQ_SETUP")); + + /* Debugging args */ + my->debug_trignr = 0; + my->debug_errbit = 0; + my->debug_word = 0; + + for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) { + my->debugOpts[i] = my->debugOptsS[i]; + } + my->debugOptsCnt = 0; } static int argsFromCL(TheArgs *my, int argc, char *argv[]) @@ -383,9 +435,10 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[]) {"ebnum", 1, 0, 'B'}, {"orapath", 1, 0, 'O'}, {"ignore", 0, 0, 'i'}, + {"debug", 1, 0, 'D'}, {0, 0, 0, 0} }; - i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:tz:e:n:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:", long_options, + i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:tz:e:n:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:D:", long_options, &option_index); if (i == -1) break; @@ -396,6 +449,9 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[]) case 'f': strcpy(my->slowCtrlFiles[my->slowCtrlFileCnt++], optarg); break; + case 'D': + strcpy(my->debugOpts[my->debugOptsCnt++], optarg); + break; case 'o': strcpy(my->outPath, optarg); break; @@ -571,6 +627,22 @@ static int argsCheck(TheArgs *my) return 1; } + /* Check debug options */ + int i; + + for (i = 0; i < my->debugOptsCnt; i++) { + if (strcmp(my->debugOpts[i], "trignr") == 0) { + my->debug_trignr = 1; + } else if (strcmp(my->debugOpts[i], "errbit") == 0) { + my->debug_errbit = 1; + } else if (strcmp(my->debugOpts[i], "debugword") == 0) { + my->debug_word = 1; + } else { + printf("Error: wrong argument is given in the option -D|--debug.\n"); + return 1; + } + } + return 0; } @@ -636,6 +708,143 @@ static void printTime() printf("Time: %s.%03ld\n", time_string, milliseconds); } +static int fillDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug, int i, char *evtStatus) +{ + int j; + + if (strcmp(evtStatus, "pop") == 0) { + if (theDebug->evtsBrokenCnt[i] == MAXDEBUGEVTS || + theDebug->errBitsCnt[i] == MAXDEBUGEVTS || theDebug->debugWordsCnt[i] == MAXDEBUGEVTS) + return MAXDEBUGEVTS; + + j = theDebug->evtsBrokenCnt[i]; + + theDebug->evtsBroken[i][j] = (*theStats->trigNr[i]); + theDebug->errBits[i][j] = (*theStats->errBit[i]); + theDebug->debugWords[i][j] = (*theStats->debugWord[i]); + + theDebug->evtsBrokenCnt[i]++; + theDebug->errBitsCnt[i]++; + theDebug->debugWordsCnt[i]++; + } else if (strcmp(evtStatus, "broken") == 0) { + int k; + for (k = 0; k < i; k++) { + + if (theDebug->evtsBrokenCnt[k] == MAXDEBUGEVTS || + theDebug->errBitsCnt[k] == MAXDEBUGEVTS || theDebug->debugWordsCnt[k] == MAXDEBUGEVTS) + return MAXDEBUGEVTS; + + j = theDebug->evtsBrokenCnt[k]; + + theDebug->evtsBroken[k][j] = (*theStats->trigNr[k]); + theDebug->errBits[k][j] = (*theStats->errBit[k]); + theDebug->debugWords[k][j] = (*theStats->debugWord[k]); + + theDebug->evtsBrokenCnt[k]++; + theDebug->errBitsCnt[k]++; + theDebug->debugWordsCnt[k]++; + } + } else { + printf("fillDebug: Event has unknown status!\n"); + } + + evtBrokenFlag = 1; + + return j; +} + +static void printDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug) +{ + int i; + int j; + + printf("\n"); + fputs + ("---------------------------- debug: discarded triggers ----------------------------------------------------------------\n", + stderr); + printf("%7s", "Queue"); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + printf("%9d", i); + } + printf("\n"); + + /* First print last succesfuly built event */ + if (theArgs->debug_trignr) { + printf("%7s", "trigNr"); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + printf("%9x", theDebug->evtsLastBuilt[i]); + } + printf("\n"); + } + + /* Maximum element */ + int maxEvts = 0; + for (i = 0; i < theArgs->nrOfMsgs; i++) { + if (maxEvts < theDebug->evtsBrokenCnt[i]) + maxEvts = theDebug->evtsBrokenCnt[i]; + } + + for (j = 0; j < maxEvts; j++) { + + /* Print trigger numbers */ + if (theArgs->debug_trignr) { + printf("%7s", "trigNr"); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + if (j < theDebug->evtsBrokenCnt[i]) { + printf(" %08x", theDebug->evtsBroken[i][j]); + } else { + printf("%9s", "-"); + } + } + printf("\n"); + } + + /* Print error bits */ + if (theArgs->debug_errbit) { + printf("%7s", "errBit"); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + if (j < theDebug->errBitsCnt[i]) { + printf(" %08x", theDebug->errBits[i][j]); + } else { + printf("%9s", "-"); + } + } + printf("\n"); + } + + /* Print debugging word */ + if (theArgs->debug_word) { + printf("%7s", "debug"); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + if (j < theDebug->debugWordsCnt[i] && theDebug->debugWords[i][j] != 0) { + printf(" %08x", theDebug->debugWords[i][j]); + } else { + printf("%9s", "-"); + } + } + printf("\n"); + } + } + + /* Print the last properly built line */ + if (theArgs->debug_trignr) { + printf("%7s", "trigNr"); + for (i = 0; i < theArgs->nrOfMsgs; i++) { + printf(" %08x", *theStats->trigNr[i]); + } + printf("\n"); + } + + evtBrokenFlag = 0; + + /* Set counters of broken subevts to zero */ + for (i = 0; i < MAXINPATH; i++) { + theDebug->evtsBrokenCnt[i] = 0; + theDebug->errBitsCnt[i] = 0; + theDebug->debugWordsCnt[i] = 0; + } +} + static void add2Stat(TheArgs *theArgs, TheStats *my, float interval, ShmTrans **shmtr) { /* Add statistic for fill levels of buffers in percentage. */ @@ -1643,10 +1852,10 @@ static int rfio_closeConnection(TheArgs *theArgs) /* BUGBUG bailOut not proper yet */ int main(int argc, char *argv[]) { - int i; TheArgs theArgsS, *theArgs = &theArgsS; TheStats theStatsS, *theStats = &theStatsS; + TheDebug theDebugS, *theDebug = &theDebugS; ShmTrans **shmTrans; HadTuQueue **hadTuQueue; Worker *worker; @@ -1682,6 +1891,10 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + /* Init debugging structure */ + if (theArgs->debugOptsCnt) + initDebug(theDebug); + for (i = 0; prioritynames[i].c_name != NULL && 0 != strcmp(prioritynames[i].c_name, theArgs->verbosity); i++) { } @@ -1769,12 +1982,21 @@ int main(int argc, char *argv[]) sprintf(buf, "trigNr%d", i); theStats->trigNr[i] = Worker_addStatistic(worker, buf); } + for (i = 0; i < theArgs->nrOfMsgs; i++) { char buf[WORKER_MAX_NAME_LEN]; sprintf(buf, "errBit%d", i); theStats->errBit[i] = Worker_addStatistic(worker, buf); } + if (theArgs->debugOptsCnt) { + for (i = 0; i < theArgs->nrOfMsgs; i++) { + char buf[WORKER_MAX_NAME_LEN]; + + sprintf(buf, "debugWord%d", i); + theStats->debugWord[i] = Worker_addStatistic(worker, buf); + } + } /* Add statistic for fill levels of buffers. */ for (i = 0; i < theArgs->nrOfMsgs; i++) { @@ -1795,7 +2017,7 @@ int main(int argc, char *argv[]) #endif uint32_t lastCurrTrigNr = 0; - int gap = 0; + int brokenEvtCnt = 0; currId = 0; while (setjmp(terminateJmp) == 0) { @@ -1887,6 +2109,8 @@ int main(int argc, char *argv[]) (*theStats->trigNr[i]) = SubEvt_trigNr(subEvt); (*theStats->errBit[i]) = SubEvt_errBit(subEvt); + if (theArgs->debugOptsCnt) + (*theStats->debugWord[i]) = SubEvt_debugWord(subEvt); if (i == 0) { currTrigNr = SubEvt_trigNr(subEvt) >> 8; @@ -1917,10 +2141,16 @@ int main(int argc, char *argv[]) HadTuQueue_pop(hadTuQueue[i]); step = 1; } else if (trigNr < currTrigNr) { + if (theArgs->debugOptsCnt) + brokenEvtCnt = fillDebug(theArgs, theStats, theDebug, i, "pop"); + /* BUGBUG subevt discarded, not in statistic */ HadTuQueue_pop(hadTuQueue[i]); step = 0; } else { + if (theArgs->debugOptsCnt) + brokenEvtCnt = fillDebug(theArgs, theStats, theDebug, i, "broken"); + evtIsBroken = 1; } if (HadTuQueue_empty(hadTuQueue[i])) { @@ -1931,6 +2161,15 @@ int main(int argc, char *argv[]) } } if (!evtIsBroken) { + if (theArgs->debugOptsCnt) { + if (evtBrokenFlag) { + printDebug(theArgs, theStats, theDebug); + } + int iq; + for (iq = 0; iq < theArgs->nrOfMsgs; iq++) + theDebug->evtsLastBuilt[iq] = (*theStats->trigNr[iq]); + } + (*theStats->evtsComplete)++; (*theStats->evtId[currId & (NEVTIDS - 1)])++;