18 #include <ndb_global.h>
20 #include "SignalLoggerManager.hpp"
21 #include <LongSignal.hpp>
22 #include <GlobalSignalNumbers.h>
23 #include <DebuggerNames.hpp>
30 NDB_TICKS t = NdbTick_CurrentMillisecond();
31 uint s = (t / 1000) % 3600;
34 sprintf(buf,
"%u.%03u", s, ms);
38 SignalLoggerManager::SignalLoggerManager()
40 for (
int i = 0;
i < NO_OF_BLOCKS;
i++){
45 m_logDistributed =
false;
49 const char* p = NdbEnv_GetEnv(
"NDB_SIGNAL_LOG_MUTEX", (
char*)0, 0);
50 if (p != 0 && strchr(
"1Y", p[0]) != 0)
51 m_mutex = NdbMutex_Create();
54 SignalLoggerManager::~SignalLoggerManager()
56 if(outputStream != 0){
62 NdbMutex_Destroy(m_mutex);
70 if(outputStream != 0){
74 FILE * out = outputStream;
75 outputStream = output;
86 SignalLoggerManager::flushSignalLog()
93 SignalLoggerManager::setTrace(
unsigned long trace)
99 SignalLoggerManager::getTrace()
const
105 SignalLoggerManager::setOwnNodeId(
int nodeId){
106 m_ownNodeId = nodeId;
110 SignalLoggerManager::setLogDistributed(
bool val){
111 m_logDistributed = val;
115 getParameter(
char *blocks[NO_OF_BLOCKS],
const char * par,
const char * line)
117 const char * loc = strstr(line, par);
125 char * copy = strdup(loc);
129 int len = strcspn(tmp,
", ;:\0");
133 if(* (tmp + len) !=
',')
136 blocks[found] = strdup(tmp);
153 char * blocks[NO_OF_BLOCKS];
154 const int count = getParameter(blocks,
"BLOCK=", params);
157 if((count == 1 && !strcmp(blocks[0],
"ALL")) ||
160 for (
int number = 0; number < NO_OF_BLOCKS; ++number){
161 cnt +=
log(SLM_ON, MIN_BLOCK_NO + number, logMode);
164 for (
int i = 0;
i < count; ++
i){
165 BlockNumber number = getBlockNo(blocks[
i]);
166 cnt +=
log(SLM_ON, number, logMode);
169 for(
int i = 0;
i<count;
i++){
180 const BlockNumber bno2 = bno-MIN_BLOCK_NO;
181 assert(bno2<NO_OF_BLOCKS);
184 logModes[bno2] |= logMode;
188 logModes[bno2] &= (~logMode);
192 logModes[bno2] ^= logMode;
200 SignalLoggerManager::logOn(
bool allBlocks, BlockNumber bno, LogMode logMode)
203 return log(SLM_ON, bno, logMode);
206 for(
unsigned int i = MIN_BLOCK_NO;
i <= MAX_BLOCK_NO;
i++)
207 cnt +=
log(SLM_ON,
i, logMode);
212 SignalLoggerManager::logOff(
bool allBlocks, BlockNumber bno, LogMode logMode)
215 return log(SLM_OFF, bno, logMode);
218 for(
unsigned int i = MIN_BLOCK_NO;
i <= MAX_BLOCK_NO;
i++)
219 cnt +=
log(SLM_OFF,
i, logMode);
225 SignalLoggerManager::logToggle(
bool allBlocks, BlockNumber bno, LogMode logMode)
228 return log(SLM_TOGGLE, bno, logMode);
231 for(
unsigned int i = MIN_BLOCK_NO;
i <= MAX_BLOCK_NO;
i++)
232 cnt +=
log(SLM_TOGGLE,
i, logMode);
239 const Uint32 * theData, Uint32 node)
241 Uint32 trace = sh.theTrace;
242 Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
243 Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
245 if(outputStream != 0 &&
246 (traceId == 0 || traceId == trace) &&
247 (logMatch(senderBlockNo, LogOut) || logMatch(receiverBlockNo, LogIn))){
249 const char* inOutStr = prio == 0 ?
"In" :
"Out";
251 fprintf(outputStream,
"---- Direct --- Signal --- %s - %s ----\n", inOutStr, mytime());
253 fprintf(outputStream,
"---- Direct --- Signal --- %s ----------------\n", inOutStr);
267 const Uint32 * theData, Uint32 node,
270 Uint32 trace = sh.theTrace;
272 Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
273 Uint32 senderNode = refToNode(sh.theSendersBlockRef);
275 if(outputStream != 0 &&
276 (traceId == 0 || traceId == trace) &&
277 (logMatch(receiverBlockNo, LogOut) ||
278 (m_logDistributed && m_ownNodeId != senderNode))){
281 fprintf(outputStream,
"---- Received - Signal - %s ----\n", mytime());
283 fprintf(outputStream,
"---- Received - Signal ----------------\n");
288 for (
unsigned i = 0;
i < secs;
i++)
296 const Uint32 * theData, Uint32 node,
299 Uint32 trace = sh.theTrace;
301 Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
302 Uint32 senderNode = refToNode(sh.theSendersBlockRef);
304 if(outputStream != 0 &&
305 (traceId == 0 || traceId == trace) &&
306 (logMatch(receiverBlockNo, LogOut) ||
307 (m_logDistributed && m_ownNodeId != senderNode))){
310 fprintf(outputStream,
"---- Received - Signal - %s ----\n", mytime());
312 fprintf(outputStream,
"---- Received - Signal ----------------\n");
317 for (
unsigned i = 0;
i < secs;
i++)
329 const Uint32 * theData, Uint32 node,
332 Uint32 trace = sh.theTrace;
333 Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
336 if(outputStream != 0 &&
337 (traceId == 0 || traceId == trace) &&
338 (logMatch(senderBlockNo, LogOut) ||
339 (m_logDistributed && m_ownNodeId != node))){
342 fprintf(outputStream,
"---- Send ----- Signal - %s ----\n", mytime());
344 fprintf(outputStream,
"---- Send ----- Signal ----------------\n");
349 for (
unsigned i = 0;
i < secs;
i++)
360 const Uint32 * theData, Uint32 node,
363 Uint32 trace = sh.theTrace;
364 Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
367 if(outputStream != 0 &&
368 (traceId == 0 || traceId == trace) &&
369 (logMatch(senderBlockNo, LogOut) ||
370 (m_logDistributed && m_ownNodeId != node))){
373 fprintf(outputStream,
"---- Send ----- Signal - %s ----\n", mytime());
375 fprintf(outputStream,
"---- Send ----- Signal ----------------\n");
380 for (
unsigned i = 0;
i < secs;
i++)
389 const Uint32 * theData, Uint32 node,
392 Uint32 trace = sh.theTrace;
393 Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
396 if(outputStream != 0 &&
397 (traceId == 0 || traceId == trace) &&
398 (logMatch(senderBlockNo, LogOut) ||
399 (m_logDistributed && m_ownNodeId != node))){
402 fprintf(outputStream,
"---- Send ----- Signal - %s ----\n", mytime());
404 fprintf(outputStream,
"---- Send ----- Signal ----------------\n");
409 for (
unsigned i = 0;
i < secs;
i++)
418 const Uint32 * theData, Uint32 node,
421 Uint32 trace = sh.theTrace;
422 Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
425 if(outputStream != 0 &&
426 (traceId == 0 || traceId == trace) &&
427 logMatch(senderBlockNo, LogOut)){
430 fprintf(outputStream,
431 "---- Send ----- Signal (%d ms) %s\n",
435 fprintf(outputStream,
"---- Send delay Signal (%d ms) ----------\n",
436 delayInMilliSeconds);
441 for (
unsigned i = 0;
i < secs;
i++)
454 const BlockNumber bno2 = bno - MIN_BLOCK_NO;
455 assert(bno2<NO_OF_BLOCKS);
457 if(outputStream != 0 &&
458 logModes[bno2] != LogOff){
462 fprintf(outputStream,
"%s: ", getBlockName(bno,
"API"));
463 vfprintf(outputStream, msg, ap);
464 fprintf(outputStream,
"\n");
471 isSysBlock(BlockNumber
block, Uint32 gsn)
478 case GSN_CONNECT_REP:
479 case GSN_DISCONNECT_REP:
482 case GSN_STOP_FOR_CRASH:
489 isApiBlock(BlockNumber block)
491 return block >= 0x8000 || block == 4002 || block == 2047;
499 bool printReceiversSignalId)
501 const char*
const dummy_block_name =
"UUNET";
503 bool receiverIsApi = isApiBlock(sh.theReceiversBlockNumber);
504 Uint32 receiverBlockNo;
505 Uint32 receiverInstanceNo;
506 if (!receiverIsApi) {
507 receiverBlockNo = blockToMain(sh.theReceiversBlockNumber);
508 receiverInstanceNo = blockToInstance(sh.theReceiversBlockNumber);
510 receiverBlockNo = sh.theReceiversBlockNumber;
511 receiverInstanceNo = 0;
513 Uint32 receiverProcessor = node;
515 Uint32 gsn = sh.theVerId_signalNumber;
517 Uint32 sbref = sh.theSendersBlockRef;
518 bool senderIsSys = isSysBlock(refToBlock(sbref), gsn);
519 bool senderIsApi = isApiBlock(refToBlock(sbref));
520 Uint32 senderBlockNo;
521 Uint32 senderInstanceNo;
522 if (!senderIsSys && !senderIsApi) {
523 senderBlockNo = refToMain(sbref);
524 senderInstanceNo = refToInstance(sbref);
526 senderBlockNo = refToBlock(sbref);
527 senderInstanceNo = 0;
529 Uint32 senderProcessor = refToNode(sbref);
531 Uint32 length = sh.theLength;
532 Uint32 trace = sh.theTrace;
533 Uint32 rSigId = sh.theSignalId;
534 Uint32 sSigId = sh.theSendersSignalId;
536 const char * signalName = getSignalName(gsn);
537 const char * rBlockName =
538 receiverIsApi ?
"API" :
539 getBlockName(receiverBlockNo, dummy_block_name);
540 const char * sBlockName =
541 senderIsSys ?
"SYS" :
542 senderIsApi ?
"API" :
543 getBlockName(senderBlockNo, dummy_block_name);
545 char rInstanceText[20];
546 char sInstanceText[20];
547 rInstanceText[0] = 0;
548 sInstanceText[0] = 0;
549 if (receiverInstanceNo != 0)
550 sprintf(rInstanceText,
"/%u", (uint)receiverInstanceNo);
551 if (senderInstanceNo != 0)
552 sprintf(sInstanceText,
"/%u", (uint)senderInstanceNo);
554 if (printReceiversSignalId)
556 "r.bn: %d%s \"%s\", r.proc: %d, r.sigId: %d gsn: %d \"%s\" prio: %d\n"
557 ,receiverBlockNo, rInstanceText, rBlockName, receiverProcessor,
558 rSigId, gsn, signalName, prio);
561 "r.bn: %d%s \"%s\", r.proc: %d, gsn: %d \"%s\" prio: %d\n",
562 receiverBlockNo, rInstanceText, rBlockName, receiverProcessor,
563 gsn, signalName, prio);
566 "s.bn: %d%s \"%s\", s.proc: %d, s.sigId: %d length: %d trace: %d "
567 "#sec: %d fragInf: %d\n",
568 senderBlockNo, sInstanceText, sBlockName, senderProcessor,
569 sSigId, length, trace, sh.m_noOfSections, sh.m_fragmentInfo);
578 const Uint32 * signalData)
580 Uint32 len = sh.theLength;
581 SignalDataPrintFunction printFunction =
582 findPrintFunction(sh.theVerId_signalNumber);
585 if(printFunction != 0){
586 ok = (* printFunction)(output, signalData, len, sh.theReceiversBlockNumber);
591 " H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x\n",
592 signalData[0], signalData[1], signalData[2], signalData[3],
593 signalData[4], signalData[5], signalData[6]);
598 for(Uint32
i = 0;
i<len;
i++)
599 fprintf(output,
" H\'%.8x", signalData[
i]);
600 fprintf(output,
"\n");
611 fprintf(output,
"SECTION %u type=linear", i);
613 fprintf(output,
" *** invalid ***\n");
616 const Uint32 len = ptr[
i].sz;
617 const Uint32 * data = ptr[
i].p;
619 fprintf(output,
" size=%u\n", (
unsigned)len);
633 fprintf(output,
"SECTION %u type=generic", i);
635 fprintf(output,
" *** invalid ***\n");
638 const Uint32 len = ptr[
i].sz;
641 fprintf(output,
" size=%u\n", (
unsigned)len);
643 const Uint32* data= ptr[
i].sectionIter->getNextWords(chunksz);
656 const char*
const hex =
"0123456789abcdef";
657 if (pos > 0 && pos % 7 == 0)
662 for (
int i = 7;
i >= 0;
i--)
663 putc(hex[(data >> (
i << 2)) & 0xf], output);