1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <ndb_global.h>
18
#include "SignalLoggerManager.hpp"
19
#include <LongSignal.hpp>
21
#include <DebuggerNames.hpp>
23
SignalLoggerManager::SignalLoggerManager()
25
for (int i = 0; i < NO_OF_BLOCKS; i++){
30
m_logDistributed = false;
33
SignalLoggerManager::~SignalLoggerManager()
35
if(outputStream != 0){
43
SignalLoggerManager::setOutputStream(FILE * output)
45
if(outputStream != 0){
49
FILE * out = outputStream;
50
outputStream = output;
55
SignalLoggerManager::getOutputStream() const
61
SignalLoggerManager::flushSignalLog()
68
SignalLoggerManager::setTrace(unsigned long trace)
74
SignalLoggerManager::getTrace() const
80
SignalLoggerManager::setOwnNodeId(int nodeId){
85
SignalLoggerManager::setLogDistributed(bool val){
86
m_logDistributed = val;
90
getParameter(char *blocks[NO_OF_BLOCKS], const char * par, const char * line)
92
const char * loc = strstr(line, par);
100
char * copy = strdup(loc);
104
int len = strcspn(tmp, ", ;:\0");
108
if(* (tmp + len) != ',')
111
blocks[found] = strdup(tmp);
126
SignalLoggerManager::log(LogMode logMode, const char * params)
128
char * blocks[NO_OF_BLOCKS];
129
const int count = getParameter(blocks, "BLOCK=", params);
132
if((count == 1 && !strcmp(blocks[0], "ALL")) ||
135
for (int number = 0; number < NO_OF_BLOCKS; ++number){
136
cnt += log(SLM_ON, number, logMode);
139
for (int i = 0; i < count; ++i){
140
BlockNumber number = getBlockNo(blocks[i]);
141
cnt += log(SLM_ON, number, logMode);
144
for(int i = 0; i<count; i++){
152
SignalLoggerManager::log(int cmd, BlockNumber bno, LogMode logMode)
154
// Normalise blocknumber for use in logModes array
155
const BlockNumber bno2 = bno-MIN_BLOCK_NO;
156
assert(bno2<NO_OF_BLOCKS);
159
logModes[bno2] |= logMode;
163
logModes[bno2] &= (~logMode);
167
logModes[bno2] ^= logMode;
175
SignalLoggerManager::logOn(bool allBlocks, BlockNumber bno, LogMode logMode)
178
return log(SLM_ON, bno, logMode);
181
for(unsigned int i = MIN_BLOCK_NO; i <= MAX_BLOCK_NO; i++)
182
cnt += log(SLM_ON, i, logMode);
187
SignalLoggerManager::logOff(bool allBlocks, BlockNumber bno, LogMode logMode)
190
return log(SLM_OFF, bno, logMode);
193
for(unsigned int i = MIN_BLOCK_NO; i <= MAX_BLOCK_NO; i++)
194
cnt += log(SLM_OFF, i, logMode);
200
SignalLoggerManager::logToggle(bool allBlocks, BlockNumber bno, LogMode logMode)
203
return log(SLM_TOGGLE, bno, logMode);
206
for(unsigned int i = MIN_BLOCK_NO; i <= MAX_BLOCK_NO; i++)
207
cnt += log(SLM_TOGGLE, i, logMode);
212
SignalLoggerManager::executeDirect(const SignalHeader& sh,
213
Uint8 prio, // in-out flag
214
const Uint32 * theData, Uint32 node)
216
Uint32 trace = sh.theTrace;
217
Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
218
Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
220
if(outputStream != 0 &&
221
(traceId == 0 || traceId == trace) &&
222
(logMatch(senderBlockNo, LogOut) || logMatch(receiverBlockNo, LogIn))){
223
const char* inOutStr = prio == 0 ? "In" : "Out";
225
fprintf(outputStream, "---- Direct --- Signal --- %s - %d ----\n", inOutStr, time(0));
227
fprintf(outputStream, "---- Direct --- Signal --- %s ----------------\n", inOutStr);
229
// XXX pass in/out to print* function somehow
230
printSignalHeader(outputStream, sh, 0, node, true);
231
printSignalData(outputStream, sh, theData);
239
SignalLoggerManager::executeSignal(const SignalHeader& sh, Uint8 prio,
240
const Uint32 * theData, Uint32 node,
241
const SegmentedSectionPtr ptr[3], Uint32 secs)
243
Uint32 trace = sh.theTrace;
244
//Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
245
Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
246
Uint32 senderNode = refToNode(sh.theSendersBlockRef);
248
if(outputStream != 0 &&
249
(traceId == 0 || traceId == trace) &&
250
(logMatch(receiverBlockNo, LogOut) ||
251
(m_logDistributed && m_ownNodeId != senderNode))){
253
fprintf(outputStream, "---- Received - Signal - %d ----\n", time(0));
255
fprintf(outputStream, "---- Received - Signal ----------------\n");
258
printSignalHeader(outputStream, sh, prio, node, true);
259
printSignalData(outputStream, sh, theData);
260
for (unsigned i = 0; i < secs; i++)
261
printSegmentedSection(outputStream, sh, ptr, i);
266
SignalLoggerManager::executeSignal(const SignalHeader& sh, Uint8 prio,
267
const Uint32 * theData, Uint32 node,
268
const LinearSectionPtr ptr[3], Uint32 secs)
270
Uint32 trace = sh.theTrace;
271
//Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
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))){
280
fprintf(outputStream, "---- Received - Signal - %d ----\n", time(0));
282
fprintf(outputStream, "---- Received - Signal ----------------\n");
285
printSignalHeader(outputStream, sh, prio, node, true);
286
printSignalData(outputStream, sh, theData);
287
for (unsigned i = 0; i < secs; i++)
288
printLinearSection(outputStream, sh, ptr, i);
296
SignalLoggerManager::sendSignal(const SignalHeader& sh,
298
const Uint32 * theData, Uint32 node,
299
const LinearSectionPtr ptr[3], Uint32 secs)
301
Uint32 trace = sh.theTrace;
302
Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
303
//Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
305
if(outputStream != 0 &&
306
(traceId == 0 || traceId == trace) &&
307
(logMatch(senderBlockNo, LogOut) ||
308
(m_logDistributed && m_ownNodeId != node))){
310
fprintf(outputStream, "---- Send ----- Signal - %d ----\n", time(0));
312
fprintf(outputStream, "---- Send ----- Signal ----------------\n");
315
printSignalHeader(outputStream, sh, prio, node, false);
316
printSignalData(outputStream, sh, theData);
317
for (unsigned i = 0; i < secs; i++)
318
printLinearSection(outputStream, sh, ptr, i);
326
SignalLoggerManager::sendSignal(const SignalHeader& sh, Uint8 prio,
327
const Uint32 * theData, Uint32 node,
328
const SegmentedSectionPtr ptr[3], Uint32 secs)
330
Uint32 trace = sh.theTrace;
331
Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
332
//Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
334
if(outputStream != 0 &&
335
(traceId == 0 || traceId == trace) &&
336
(logMatch(senderBlockNo, LogOut) ||
337
(m_logDistributed && m_ownNodeId != node))){
339
fprintf(outputStream, "---- Send ----- Signal - %d ----\n", time(0));
341
fprintf(outputStream, "---- Send ----- Signal ----------------\n");
344
printSignalHeader(outputStream, sh, prio, node, false);
345
printSignalData(outputStream, sh, theData);
346
for (unsigned i = 0; i < secs; i++)
347
printSegmentedSection(outputStream, sh, ptr, i);
352
SignalLoggerManager::sendSignalWithDelay(Uint32 delayInMilliSeconds,
353
const SignalHeader & sh, Uint8 prio,
354
const Uint32 * theData, Uint32 node,
355
const SegmentedSectionPtr ptr[3], Uint32 secs)
357
Uint32 trace = sh.theTrace;
358
Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
359
//Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
361
if(outputStream != 0 &&
362
(traceId == 0 || traceId == trace) &&
363
logMatch(senderBlockNo, LogOut)){
365
fprintf(outputStream,
366
"---- Send ----- Signal (%d ms) %d\n",
370
fprintf(outputStream, "---- Send delay Signal (%d ms) ----------\n",
371
delayInMilliSeconds);
374
printSignalHeader(outputStream, sh, prio, node, false);
375
printSignalData(outputStream, sh, theData);
376
for (unsigned i = 0; i < secs; i++)
377
printSegmentedSection(outputStream, sh, ptr, i);
382
* Generic messages in the signal log
385
SignalLoggerManager::log(BlockNumber bno, const char * msg, ...)
387
// Normalise blocknumber for use in logModes array
388
const BlockNumber bno2 = bno - MIN_BLOCK_NO;
389
assert(bno2<NO_OF_BLOCKS);
391
if(outputStream != 0 &&
392
logModes[bno2] != LogOff){
395
fprintf(outputStream, "%s: ", getBlockName(bno, "API"));
396
vfprintf(outputStream, msg, ap);
397
fprintf(outputStream, "\n");
404
SignalLoggerManager::printSignalHeader(FILE * output,
405
const SignalHeader & sh,
408
bool printReceiversSignalId)
410
Uint32 receiverBlockNo = sh.theReceiversBlockNumber;
411
Uint32 receiverProcessor = node;
412
Uint32 gsn = sh.theVerId_signalNumber;
413
Uint32 senderBlockNo = refToBlock(sh.theSendersBlockRef);
414
Uint32 senderProcessor = refToNode(sh.theSendersBlockRef);
415
Uint32 length = sh.theLength;
416
Uint32 trace = sh.theTrace;
417
Uint32 rSigId = sh.theSignalId;
418
Uint32 sSigId = sh.theSendersSignalId;
420
const char * signalName = getSignalName(gsn);
421
const char * rBlockName = getBlockName(receiverBlockNo, "API");
422
const char * sBlockName = getBlockName(senderBlockNo, "API");
424
if(printReceiversSignalId)
426
"r.bn: %d \"%s\", r.proc: %d, r.sigId: %d gsn: %d \"%s\" prio: %d\n"
427
,receiverBlockNo, rBlockName, receiverProcessor, rSigId,
428
gsn, signalName, prio);
431
"r.bn: %d \"%s\", r.proc: %d, gsn: %d \"%s\" prio: %d\n",
432
receiverBlockNo, rBlockName, receiverProcessor, gsn,
436
"s.bn: %d \"%s\", s.proc: %d, s.sigId: %d length: %d trace: %d "
437
"#sec: %d fragInf: %d\n",
438
senderBlockNo, sBlockName, senderProcessor, sSigId, length, trace,
439
sh.m_noOfSections, sh.m_fragmentInfo);
443
SignalLoggerManager::printSignalData(FILE * output,
444
const SignalHeader & sh,
445
const Uint32 * signalData)
447
Uint32 len = sh.theLength;
448
SignalDataPrintFunction printFunction =
449
findPrintFunction(sh.theVerId_signalNumber);
451
bool ok = false; // done with printing
452
if(printFunction != 0){
453
ok = (* printFunction)(output, signalData, len, sh.theReceiversBlockNumber);
458
" H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x H\'%.8x\n",
459
signalData[0], signalData[1], signalData[2], signalData[3],
460
signalData[4], signalData[5], signalData[6]);
465
for(Uint32 i = 0; i<len; i++)
466
fprintf(output, " H\'%.8x", signalData[i]);
467
fprintf(output, "\n");
473
SignalLoggerManager::printLinearSection(FILE * output,
474
const SignalHeader & sh,
475
const LinearSectionPtr ptr[3],
478
fprintf(output, "SECTION %u type=linear", i);
480
fprintf(output, " *** invalid ***\n");
483
const Uint32 len = ptr[i].sz;
484
const Uint32 * data = ptr[i].p;
486
fprintf(output, " size=%u\n", (unsigned)len);
488
printDataWord(output, pos, data[pos]);
495
SignalLoggerManager::printDataWord(FILE * output, Uint32 & pos, const Uint32 data)
497
const char* const hex = "0123456789abcdef";
498
if (pos > 0 && pos % 7 == 0)
503
for (int i = 7; i >= 0; i--)
504
putc(hex[(data >> (i << 2)) & 0xf], output);