fifo debug with color done

This commit is contained in:
Dhanya Maliakal 2015-03-05 15:21:12 +01:00
parent 5682a6b458
commit 2f82469531
4 changed files with 124 additions and 48 deletions

View File

@ -0,0 +1,59 @@
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define BG_RED "\x1b[41m"
#define BG_GREEN "\x1b[42m"
#define BG_YELLOW "\x1b[43m"
#define BG_BLUE "\x1b[44m"
#define BG_MAGENTA "\x1b[45m"
#define BG_CYAN "\x1b[46m"
#define RESET "\x1b[0m"
#define BOLD "\x1b[1m"
#define cprintf(code, format, ...) printf(code format RESET, ##__VA_ARGS__)
/*
Code examples
example 1 (a snippet):
#ifdef MARTIN
cprintf(BLUE, "LL Write - Len: %2d - If: %X - Data: ",buffer_len, ll->ll_fifo_base);
for (i=0; i < buffer_len/4; i++)
cprintf(BLUE, "%.8X ",*(((unsigned *) buffer)+i));
printf("\n");
#endif
#ifdef MARTIN
cprintf(CYAN, "LL Read - If: %X - Data: ",ll->ll_fifo_base);
#endif
example 2:
int main()
{
int i=1;
printf("Normal %i\n", i);
cprintf(RED, "Red\n");
cprintf(GREEN, "Green\n");
cprintf(YELLOW, "Yellow\n");
cprintf(BLUE, "Blue\n");
cprintf(MAGENTA, "Mangenta %i\n", i);
cprintf(CYAN, "Cyan %i\n", i);
cprintf(BOLD, "White %i\n", i);
cprintf(RED BOLD, "Red %i\n", i);
cprintf(GREEN BOLD, "Green\n");
cprintf(YELLOW BOLD, "Yellow\n");
cprintf(BLUE BOLD, "Blue\n");
cprintf(MAGENTA BOLD, "Mangenta %i\n", i);
cprintf(CYAN BOLD, "Cyan %i\n", i);
}
*/

View File

@ -8,7 +8,7 @@
#endif #endif
#include <stdint.h> #include <stdint.h>
#include "ansi.h"
typedef double double32_t; typedef double double32_t;
typedef float float32_t; typedef float float32_t;

View File

@ -374,12 +374,12 @@ int32_t UDPBaseImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEBUG) <
setupFifoStructure(); setupFifoStructure();
if(createListeningThreads() == FAIL){ if(createListeningThreads() == FAIL){
cout << "ERROR: Could not create listening thread" << endl; cprintf(BG_RED,"ERROR: Could not create listening thread\n");
exit (-1); exit (-1);
} }
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cprintf(BG_RED,"ERROR: Could not create writer threads\n");
exit (-1); exit (-1);
} }
@ -475,7 +475,7 @@ int UDPBaseImplementation::enableDataCompression(bool enable){ FILE_LOG(logDEBUG
numWriterThreads = 1; numWriterThreads = 1;
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cprintf(BG_RED,"ERROR: Could not create writer threads\n");
return FAIL; return FAIL;
} }
setThreadPriorities(); setThreadPriorities();
@ -763,7 +763,7 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << "
iret = udpSocket[i]->getErrorStatus(); iret = udpSocket[i]->getErrorStatus();
if(iret){ if(iret){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Could not create UDP socket on port " << server_port[i] << " error:" << iret << endl; cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n",server_port[i], iret);
#endif #endif
return FAIL; return FAIL;
} }

View File

@ -322,12 +322,12 @@ int UDPStandardImplementation::setDetectorType(detectorType det){ FILE_LOG(logD
setupFifoStructure(); setupFifoStructure();
if(createListeningThreads() == FAIL){ if(createListeningThreads() == FAIL){
cout << "ERROR: Could not create listening thread" << endl; cprintf(BG_RED,"ERROR: Could not create listening thread\n");
exit (-1); exit (-1);
} }
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cprintf(BG_RED,"ERROR: Could not create writer threads\n");
exit (-1); exit (-1);
} }
@ -585,12 +585,12 @@ int32_t UDPStandardImplementation::setDynamicRange(int32_t dr){ FILE_LOG(logDEB
setupFifoStructure(); setupFifoStructure();
if(createListeningThreads() == FAIL){ if(createListeningThreads() == FAIL){
cout << "ERROR: Could not create listening thread" << endl; cprintf(BG_RED,"ERROR: Could not create listening thread\n");
exit (-1); exit (-1);
} }
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cprintf(BG_RED,"ERROR: Could not create writer threads\n");
exit (-1); exit (-1);
} }
@ -691,7 +691,7 @@ int UDPStandardImplementation::enableDataCompression(bool enable){ FILE_LOG(log
numWriterThreads = 1; numWriterThreads = 1;
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cprintf(BG_RED,"ERROR: Could not create writer threads\n");
return FAIL; return FAIL;
} }
setThreadPriorities(); setThreadPriorities();
@ -830,6 +830,9 @@ void UDPStandardImplementation::setupFifoStructure(){
if(fifoFree[i]){ if(fifoFree[i]){
while(!fifoFree[i]->isEmpty()) while(!fifoFree[i]->isEmpty())
fifoFree[i]->pop(buffer[i]); fifoFree[i]->pop(buffer[i]);
#ifdef FIFO_DEBUG
//cprintf(GREEN,"%d fifostructure popped from fifofree %x\n", i, (void*)(buffer[i]));
#endif
delete fifoFree[i]; delete fifoFree[i];
} }
if(fifo[i]) delete fifo[i]; if(fifo[i]) delete fifo[i];
@ -849,6 +852,9 @@ void UDPStandardImplementation::setupFifoStructure(){
//push the addresses into freed fifoFree and writingFifoFree //push the addresses into freed fifoFree and writingFifoFree
while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { while (buffer[i]<(mem0[i]+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) {
fifoFree[i]->push(buffer[i]); fifoFree[i]->push(buffer[i]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d fifostructure free pushed into fifofree %x\n", i, (void*)(buffer[i]));
#endif
buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS); buffer[i]+=(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS);
} }
} }
@ -1017,7 +1023,7 @@ int UDPStandardImplementation::createUDPSockets(){
cout << "UDP port opened at port " << port[i] << endl; cout << "UDP port opened at port " << port[i] << endl;
else{ else{
#ifdef VERBOSE #ifdef VERBOSE
cout << "Could not create UDP socket on port " << port[i] << " error:" << iret << endl; cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret);
#endif #endif
return FAIL; return FAIL;
} }
@ -1349,11 +1355,11 @@ int UDPStandardImplementation::createNewFile(){
//open file //open file
if(!overwrite){ if(!overwrite){
if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){
cout << "Error: Could not create new file " << savefilename << endl; cprintf(BG_RED,"Error: Could not create new file %s\n",savefilename);
return FAIL; return FAIL;
} }
}else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ }else if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){
cout << "Error: Could not create file " << savefilename << endl; cprintf(BG_RED,"Error: Could not create file %s\n",savefilename);
return FAIL; return FAIL;
} }
//setting buffer //setting buffer
@ -1650,8 +1656,8 @@ int UDPStandardImplementation::startListening(){
#endif #endif
//pop //pop
fifoFree[ithread]->pop(buffer[ithread]); fifoFree[ithread]->pop(buffer[ithread]);
#ifdef VERYDEBUG #ifdef FIFO_DEBUG
cout << ithread << " *** popped from fifo free" << (void*)buffer[ithread] << endl; cprintf(GREEN,"%d listener popped from fifofree %x\n", ithread, (void*)(buffer[ithread]));
#endif #endif
@ -1687,9 +1693,9 @@ int UDPStandardImplementation::startListening(){
expected = maxBufferSize - carryonBufferSize; expected = maxBufferSize - carryonBufferSize;
} }
#ifdef VERYDEBUG //#ifdef VERDEBUG
cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl; cout << ithread << " *** rc:" << dec << rc << ". expected:" << dec << expected << endl;
#endif //#endif
/* /*
//start indices for each start of scan/acquisition - eiger does it before //start indices for each start of scan/acquisition - eiger does it before
@ -1796,8 +1802,9 @@ int UDPStandardImplementation::startListening(){
cout<<dec<<ithread<<" listener going to push fifo:"<<(void*)(buffer[ithread])<<endl; cout<<dec<<ithread<<" listener going to push fifo:"<<(void*)(buffer[ithread])<<endl;
#endif #endif
while(!fifo[ithread]->push(buffer[ithread])); while(!fifo[ithread]->push(buffer[ithread]));
#ifdef VERYDEBUG #ifdef FIFO_DEBUG
if(!ithread) cout << ithread << " *** pushed into listening fifo" << endl; //if(!ithread)
cprintf(RED, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread]));
#endif #endif
} }
@ -1877,29 +1884,27 @@ int UDPStandardImplementation::startWriting(){
cout << "writer gonna pop from fifo:" << i << endl; cout << "writer gonna pop from fifo:" << i << endl;
#endif #endif
fifo[i]->pop(wbuf[i]); fifo[i]->pop(wbuf[i]);
#ifdef FIFO_DEBUG
cprintf(MAGENTA,"%d writer poped from fifo %x\n", ithread, (void*)(wbuf[i]));
#endif
numpackets = (uint16_t)(*((uint16_t*)wbuf[i])); numpackets = (uint16_t)(*((uint16_t*)wbuf[i]));
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl; cout << i << " numpackets:" << dec << numpackets << "for fifo :"<< i << endl;
#endif #endif
} }
#ifdef VERYDEBUG
cout << ithread << " numpackets:" << dec << numpackets << endl;
cout << ithread << " *** writer popped from fifo " << (void*) wbuf[0]<< endl;
cout << ithread << " *** writer popped from fifo " << (void*) wbuf[1]<< endl;
#endif
//last dummy packet //last dummy packet
if(numpackets == 0xFFFF){ if(numpackets == 0xFFFF){
#ifdef VERYDEBUG //#ifdef VERYDEBUG
cout << "**LAST dummy packet" << endl; cout << "**LAST dummy packet" << endl;
#endif //#endif
stopWriting(ithread,wbuf); stopWriting(ithread,wbuf);
continue; continue;
} }
#ifdef VERYDEBUG //#ifdef VERYDEBUG
else cout <<"**NOT a dummy packet"<<endl; else cout <<"**NOT a dummy packet"<<endl;
#endif //#endif
@ -1955,8 +1960,8 @@ int UDPStandardImplementation::startWriting(){
#endif #endif
for(i=0;i<numListeningThreads;++i){ for(i=0;i<numListeningThreads;++i){
while(!fifoFree[i]->push(wbuf[i])); while(!fifoFree[i]->push(wbuf[i]));
#ifdef VERYDEBUG #ifdef FIFO_DEBUG
cout << ithread << ":" << i << " fifo freed:" << (void*)wbuf[i] << endl; cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener %d\n",ithread, (void*)(wbuf[i]),i);
#endif #endif
} }
@ -1971,8 +1976,8 @@ int UDPStandardImplementation::startWriting(){
#endif #endif
}//else cout << "unfinished buffersize" << endl; }//else cout << "unfinished buffersize" << endl;
while(!fifoFree[0]->push(wbuf[0])); while(!fifoFree[0]->push(wbuf[0]));
#ifdef VERYVERBOSE #ifdef FIFO_DEBUG
cout<<"buf freed:"<<(void*)wbuf[0]<<endl; cprintf(BLUE,"%d writer freed pushed into fifofree %x for listener 0\n",ithread, (void*)(wbuf[0]));
#endif #endif
} }
} }
@ -2097,6 +2102,9 @@ int i;
if(status != TRANSMITTING){ if(status != TRANSMITTING){
cout << ithread << " *** shoule never be here********* status not transmitting***********************"<<endl;/**/ cout << ithread << " *** shoule never be here********* status not transmitting***********************"<<endl;/**/
fifoFree[ithread]->push(buffer[ithread]); fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener not txm free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread]));
#endif
exit(-1); exit(-1);
} }
@ -2108,6 +2116,9 @@ int i;
cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl; cout << ithread << " Start of detector: Received test frame of 266240 bytes." << endl;
cout << ithread << "Discarding incomplete frame" << endl; cout << ithread << "Discarding incomplete frame" << endl;
fifoFree[ithread]->push(buffer[ithread]); fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread]));
#endif
} }
//eiger (complete frames) + other detectors //eiger (complete frames) + other detectors
else{ else{
@ -2119,8 +2130,8 @@ int i;
(*((uint16_t*)(buffer[ithread]))) = pc; (*((uint16_t*)(buffer[ithread]))) = pc;
totalListeningFrameCount[ithread] += pc; totalListeningFrameCount[ithread] += pc;
while(!fifo[ithread]->push(buffer[ithread])); while(!fifo[ithread]->push(buffer[ithread]));
#ifdef VERYDEBUG #ifdef FIFO_DEBUG
cout << ithread << " *** last lbuf1:" << (void*)buffer[ithread] << endl; cprintf(RED,"%d listener last buffer pushed into fifo %x\n", ithread,(void*)(buffer[ithread]));
#endif #endif
} }
} }
@ -2128,6 +2139,9 @@ int i;
else{ else{
cout << ithread << "Discarding empty frame" << endl; cout << ithread << "Discarding empty frame" << endl;
fifoFree[ithread]->push(buffer[ithread]); fifoFree[ithread]->push(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread]));
#endif
} }
@ -2135,13 +2149,16 @@ int i;
//push dummy buffer to all writer threads //push dummy buffer to all writer threads
for(i=0;i<numWriterThreads;++i){ for(i=0;i<numWriterThreads;++i){
fifoFree[ithread]->pop(buffer[ithread]); fifoFree[ithread]->pop(buffer[ithread]);
#ifdef FIFO_DEBUG
cprintf(GREEN,"%d listener popped dummy buffer from fifofree %x\n", ithread,(void*)(buffer[ithread]));
#endif
(*((uint16_t*)(buffer[ithread]))) = 0xFFFF; (*((uint16_t*)(buffer[ithread]))) = 0xFFFF;
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << ithread << " going to push in dummy buffer:" << (void*)buffer[ithread] << " with num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl; cout << ithread << " dummy buffer num packets:"<< (*((uint16_t*)(buffer[ithread]))) << endl;
#endif #endif
while(!fifo[ithread]->push(buffer[ithread])); while(!fifo[ithread]->push(buffer[ithread]));
#ifdef VERYDEBUG #ifdef FIFO_DEBUG
cout << ithread << " pushed in dummy buffer:" << (void*)buffer[ithread] << endl; cprintf(RED,"%d listener pushed dummy buffer into fifo %x\n", ithread,(void*)(buffer[ithread]));
#endif #endif
} }
@ -2195,8 +2212,8 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
//free fifo //free fifo
for(i=0;i<numListeningThreads;++i){ for(i=0;i<numListeningThreads;++i){
while(!fifoFree[i]->push(wbuffer[i])); while(!fifoFree[i]->push(wbuffer[i]));
#ifdef VERYDEBUG #ifdef FIFO_DEBUG
cout << ithread << ":" << i<< " fifo freed:" << (void*)wbuffer[i] << endl; cprintf(BLUE,"%d writer free dummy pushed into fifofree %x for listener %d\n", ithread,(void*)(wbuffer[i]),i);
#endif #endif
} }
@ -2233,9 +2250,10 @@ void UDPStandardImplementation::stopWriting(int ithread, char* wbuffer[]){
status = RUN_FINISHED; status = RUN_FINISHED;
pthread_mutex_unlock(&(status_mutex)); pthread_mutex_unlock(&(status_mutex));
//report //report
cout << "Status: Run Finished" << endl;
cout << "Total Packets Caught:" << dec << totalPacketsCaught << endl; cprintf(GREEN, "Status: Run Finished\n");
cout << "Total Frames Caught:"<< dec << (totalPacketsCaught/packetsPerFrame) << endl; cprintf(GREEN, "Total Packets Caught:%d\n", totalPacketsCaught);
cprintf(GREEN, "Total Frames Caught:%d\n",(totalPacketsCaught/packetsPerFrame));
//acquisition end //acquisition end
if (acquisitionFinishedCallBack) if (acquisitionFinishedCallBack)
acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished); acquisitionFinishedCallBack((totalPacketsCaught/packetsPerFrame), pAcquisitionFinished);
@ -2442,16 +2460,15 @@ void UDPStandardImplementation::handleDataCompression(int ithread, char* wbuffer
remainingsize -= ((buff + ndata) - data); remainingsize -= ((buff + ndata) - data);
data = buff + ndata; data = buff + ndata;
if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) ) if(data > (wbuffer[0] + HEADER_SIZE_NUM_TOT_PACKETS + npackets * onePacketSize) )
cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<<endl; cprintf(BG_RED,"ERROR SHOULD NOT COME HERE, Error 142536!\n");
} }
while(!fifoFree[0]->push(wbuffer[0])); while(!fifoFree[0]->push(wbuffer[0]));
#ifdef VERYVERBOSE #ifdef FIFO_DEBUG
cout<<"buf freed:"<<(void*)wbuffer[0]<<endl; cprintf(BLUE,"%d writer compression free pushed into fifofree %x for listerner 0\n", ithread, (void*)(wbuffer[0]));
#endif #endif
} }
@ -2511,12 +2528,12 @@ int UDPStandardImplementation::enableTenGiga(int enable){
setupFifoStructure(); setupFifoStructure();
if(createListeningThreads() == FAIL){ if(createListeningThreads() == FAIL){
cout << "ERROR: Could not create listening thread" << endl; cprintf(BG_RED,"ERROR: Could not create listening thread\n");
exit (-1); exit (-1);
} }
if(createWriterThreads() == FAIL){ if(createWriterThreads() == FAIL){
cout << "ERROR: Could not create writer threads" << endl; cprintf(BG_RED,"ERROR: Could not create writer threads\n");
exit (-1); exit (-1);
} }