MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraceNdbApi.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <NdbApi.hpp>
20 #include <NdbOut.hpp>
21 #include <NdbMutex.h>
22 
23 #include "TraceNdbApi.hpp"
24 
25 
26 int g_nParamTrace;
27 NdbMutex* g_pNdbMutexTrace = 0;
28 
29 
30 void TraceBegin(void)
31 {
32  if(!g_pNdbMutexTrace)
33  {
34  g_pNdbMutexTrace = NdbMutex_Create();
35  }
36  NdbMutex_Lock(g_pNdbMutexTrace);
37  g_nParamTrace = 0;
38 }
39 
40 void TraceEnd(void)
41 {
42  ndbout << endl;
43  g_nParamTrace = 0;
44  NdbMutex_Unlock(g_pNdbMutexTrace);
45 }
46 
47 void TraceMethod(const char* szMethod)
48 {
49  ndbout << "->" << szMethod << "(";
50  g_nParamTrace = 0;
51 }
52 
53 void TraceParamComma(void)
54 {
55  if(g_nParamTrace)
56  {
57  ndbout << ", ";
58  }
59  ++g_nParamTrace;
60 }
61 
62 void TraceNdb(Ndb* pNdb)
63 {
64  TraceParamComma();
65  ndbout << "((Ndb*)" << hex << (Uint32)pNdb << ")";
66 }
67 
68 void TraceNdbSchemaCon(NdbSchemaCon* pNdbSchemaCon)
69 {
70  TraceParamComma();
71  ndbout << "((NdbSchemaCon*)" << hex << (Uint32)pNdbSchemaCon << ")";
72 }
73 
74 void TraceNdbSchemaOp(NdbSchemaOp* pNdbSchemaOp)
75 {
76  TraceParamComma();
77  ndbout << "((NdbSchemaOp*)" << hex << (Uint32)pNdbSchemaOp << ")";
78 }
79 
80 void TraceNdbConnection(const NdbConnection* pNdbConnection)
81 {
82  TraceParamComma();
83  ndbout << "((NdbConnection*)" << hex << (Uint32)pNdbConnection << ")";
84 }
85 
86 void TraceNdbOperation(NdbOperation* pNdbOperation)
87 {
88  TraceParamComma();
89  ndbout << "((NdbOperation*)" << hex << (Uint32)pNdbOperation << ")";
90 }
91 
92 void TraceNdbIndexOperation(NdbIndexOperation* pNdbIndexOperation)
93 {
94  TraceParamComma();
95  ndbout << "((NdbIndexOperation*)" << hex << (Uint32)pNdbIndexOperation << ")";
96 }
97 
98 void TraceNdbRecAttr(NdbRecAttr* pNdbRecAttr)
99 {
100  TraceParamComma();
101  ndbout << "((NdbRecAttr*)" << hex << (Uint32)pNdbRecAttr << ")";
102 }
103 
104 void TraceTable(Table* pTable)
105 {
106  TraceParamComma();
107  ndbout << "((Table*)" << hex << (Uint32)pTable << ")";
108 }
109 
110 void TraceString(const char* szParam)
111 {
112  TraceParamComma();
113  ndbout << "\"" << szParam << "\"";
114 }
115 
116 void TraceInt(const int i)
117 {
118  TraceParamComma();
119  ndbout << "(int)" << dec << i;
120 }
121 
122 void TraceUint32(const Uint32 n)
123 {
124  TraceParamComma();
125  ndbout << "(Uint32)" << dec << n;
126 }
127 
128 void TraceKeyType(const KeyType aKeyType)
129 {
130  TraceParamComma();
131  switch(aKeyType)
132  {
133  case Undefined: ndbout << "Undefined"; break;
134  case NoKey: ndbout << "NoKey"; break;
135  case TupleKey: ndbout << "TupleKey"; break;
136  case TupleId: ndbout << "TupleId"; break;
137  default: ndbout << "(KeyType)" << aKeyType; break;
138  }
139 }
140 
141 void TraceExecType(const ExecType aExecType)
142 {
143  switch(aExecType)
144  {
145  case NoExecTypeDef: ndbout << "NoExecTypeDef"; break;
146  case Prepare: ndbout << "Prepare"; break;
147  case NoCommit: ndbout << "NoCommit"; break;
148  case Commit: ndbout << "Commit"; break;
149  case Rollback: ndbout << "Rollback"; break;
150  default: ndbout << "(ExecType)" << aExecType; break;
151  }
152 }
153 
154 
155 void TraceNdbError(const NdbError& err)
156 {
157  TraceParamComma();
158  ndbout << "(NdbError)" << err;
159 }
160 
161 
162 
163 void TraceVoid(void)
164 {
165  ndbout << "void";
166 }
167 
168 void TraceReturn(void)
169 {
170  ndbout << "); // return ";
171  g_nParamTrace = 0;
172 }
173 
174 
175 // TraceNdbSchemaOp
176 
177 int CTraceNdbSchemaOp::createTable(const char* aTableName)
178 {
179  int i = NdbSchemaOp::createTable(aTableName);
180  TraceBegin();
181  TraceNdbSchemaOp(this);
182  TraceMethod("createTable");
183  TraceString(aTableName);
184  TraceReturn();
185  TraceInt(i);
186  TraceEnd();
187  return i;
188 }
189 
190 int CTraceNdbSchemaOp::createAttribute(const char* aAttrName, KeyType aTupleyKey)
191 {
192  int i = NdbSchemaOp::createAttribute(aAttrName, aTupleyKey);
193  TraceBegin();
194  TraceNdbSchemaOp(this);
195  TraceMethod("createAttribute");
196  TraceString(aAttrName);
197  TraceKeyType(aTupleyKey);
198  TraceReturn();
199  TraceInt(i);
200  TraceEnd();
201  return i;
202 }
203 
204 
205 
206 // TraceNdbSchemaCon
207 
208 CTraceNdbSchemaOp* CTraceNdbSchemaCon::getNdbSchemaOp()
209 {
210  NdbSchemaOp* pNdbSchemaOp = NdbSchemaCon::getNdbSchemaOp();
211  TraceBegin();
212  TraceNdbSchemaCon(this);
213  TraceMethod("getNdbSchemaOp");
214  TraceReturn();
215  TraceNdbSchemaOp(pNdbSchemaOp);
216  TraceEnd();
217  return (CTraceNdbSchemaOp*)pNdbSchemaOp;
218 }
219 
220 int CTraceNdbSchemaCon::execute()
221 {
222  int i = NdbSchemaCon::execute();
223  TraceBegin();
224  TraceNdbSchemaCon(this);
225  TraceMethod("execute");
226  TraceReturn();
227  TraceInt(i);
228  TraceEnd();
229  return i;
230 }
231 
232 
233 
234 // TraceNdbRecAttr
235 
236 Uint32 CTraceNdbRecAttr::u_32_value()
237 {
238  Uint32 n = NdbRecAttr::u_32_value();
239  TraceBegin();
240  TraceNdbRecAttr(this);
241  TraceMethod("u_32_value");
242  TraceReturn();
243  TraceUint32(n);
244  TraceEnd();
245  return n;
246 }
247 
248 
249 
250 // TraceNdbOperation
251 
252 int CTraceNdbOperation::insertTuple()
253 {
255  TraceBegin();
256  TraceNdbOperation(this);
257  TraceMethod("insertTuple");
258  TraceReturn();
259  TraceInt(i);
260  TraceEnd();
261  return i;
262 }
263 
264 int CTraceNdbOperation::updateTuple()
265 {
267  TraceBegin();
268  TraceNdbOperation(this);
269  TraceMethod("updateTuple");
270  TraceReturn();
271  TraceInt(i);
272  TraceEnd();
273  return i;
274 }
275 
276 int CTraceNdbOperation::interpretedUpdateTuple()
277 {
279  TraceBegin();
280  TraceNdbOperation(this);
281  TraceMethod("interpretedUpdateTuple");
282  TraceReturn();
283  TraceInt(i);
284  TraceEnd();
285  return i;
286 }
287 
288 int CTraceNdbOperation::readTuple()
289 {
290  int i = NdbOperation::readTuple();
291  TraceBegin();
292  TraceNdbOperation(this);
293  TraceMethod("readTuple");
294  TraceReturn();
295  TraceInt(i);
296  TraceEnd();
297  return i;
298 }
299 
300 
301 int CTraceNdbOperation::readTupleExclusive()
302 {
304  TraceBegin();
305  TraceNdbOperation(this);
306  TraceMethod("readTupleExclusive");
307  TraceReturn();
308  TraceInt(i);
309  TraceEnd();
310  return i;
311 }
312 
313 
314 int CTraceNdbOperation::deleteTuple()
315 {
317  TraceBegin();
318  TraceNdbOperation(this);
319  TraceMethod("deleteTuple");
320  TraceReturn();
321  TraceInt(i);
322  TraceEnd();
323  return i;
324 }
325 
326 int CTraceNdbOperation::equal(const char* anAttrName, Uint32 aValue)
327 {
328  int i = NdbOperation::equal(anAttrName, aValue);
329  TraceBegin();
330  TraceNdbOperation(this);
331  TraceMethod("equal");
332  TraceString(anAttrName);
333  TraceUint32(aValue);
334  TraceReturn();
335  TraceInt(i);
336  TraceEnd();
337  return i;
338 }
339 
340 int CTraceNdbOperation::setValue(const char* anAttrName, Uint32 aValue)
341 {
342  int i = NdbOperation::setValue(anAttrName, aValue);
343  TraceBegin();
344  TraceNdbOperation(this);
345  TraceMethod("setValue");
346  TraceString(anAttrName);
347  TraceUint32(aValue);
348  TraceReturn();
349  TraceInt(i);
350  TraceEnd();
351  return i;
352 }
353 
354 int CTraceNdbOperation::incValue(const char* anAttrName, Uint32 aValue)
355 {
356  int i = NdbOperation::incValue(anAttrName, aValue);
357  TraceBegin();
358  TraceNdbOperation(this);
359  TraceMethod("incValue");
360  TraceString(anAttrName);
361  TraceUint32(aValue);
362  TraceReturn();
363  TraceInt(i);
364  TraceEnd();
365  return i;
366 }
367 
368 CTraceNdbRecAttr* CTraceNdbOperation::getValue(const char* anAttrName)
369 {
370  NdbRecAttr* pNdbRecAttr = NdbOperation::getValue(anAttrName);
371  TraceBegin();
372  TraceNdbOperation(this);
373  TraceMethod("getValue");
374  TraceString(anAttrName);
375  TraceReturn();
376  TraceNdbRecAttr(pNdbRecAttr);
377  TraceEnd();
378  return (CTraceNdbRecAttr*)pNdbRecAttr;
379 }
380 
381 
382 // TraceNdbIndexOperation
383 
384 int CTraceNdbIndexOperation::equal(const char* anAttrName, Uint32 aValue)
385 {
386  int i = NdbIndexOperation::equal(anAttrName, aValue);
387  TraceBegin();
388  TraceNdbIndexOperation(this);
389  TraceMethod("equal");
390  TraceString(anAttrName);
391  TraceUint32(aValue);
392  TraceReturn();
393  TraceInt(i);
394  TraceEnd();
395  return i;
396 }
397 
398 
399 int CTraceNdbIndexOperation::incValue(const char* anAttrName, Uint32 aValue)
400 {
401  int i = NdbIndexOperation::incValue(anAttrName, aValue);
402  TraceBegin();
403  TraceNdbIndexOperation(this);
404  TraceMethod("incValue");
405  TraceString(anAttrName);
406  TraceUint32(aValue);
407  TraceReturn();
408  TraceInt(i);
409  TraceEnd();
410  return i;
411 }
412 
413 
414 CTraceNdbRecAttr* CTraceNdbIndexOperation::getValue(const char* anAttrName)
415 {
416  NdbRecAttr* pNdbRecAttr = NdbIndexOperation::getValue(anAttrName);
417  TraceBegin();
418  TraceNdbIndexOperation(this);
419  TraceMethod("getValue");
420  TraceString(anAttrName);
421  TraceReturn();
422  TraceNdbRecAttr(pNdbRecAttr);
423  TraceEnd();
424  return (CTraceNdbRecAttr*)pNdbRecAttr;
425 }
426 
427 
428 // TraceNdbConnection
429 
430 CTraceNdbOperation* CTraceNdbConnection::getNdbOperation(const char* aTableName)
431 {
432  NdbOperation* pNdbOperation = NdbConnection::getNdbOperation(aTableName);
433  TraceBegin();
434  TraceNdbConnection(this);
435  TraceMethod("getNdbOperation");
436  TraceString(aTableName);
437  TraceReturn();
438  TraceNdbOperation(pNdbOperation);
439  TraceEnd();
440  return (CTraceNdbOperation*)pNdbOperation;
441 }
442 
443 CTraceNdbIndexOperation* CTraceNdbConnection::getNdbIndexOperation(const char* anIndexName, const char* aTableName)
444 {
445  NdbIndexOperation* pNdbIndexOperation = NdbConnection::getNdbIndexOperation(anIndexName, aTableName);
446  TraceBegin();
447  TraceNdbConnection(this);
448  TraceMethod("getNdbIndexOperation");
449  TraceString(anIndexName);
450  TraceString(aTableName);
451  TraceReturn();
452  TraceNdbIndexOperation(pNdbIndexOperation);
453  TraceEnd();
454  return (CTraceNdbIndexOperation*)pNdbIndexOperation;
455 }
456 
457 int CTraceNdbConnection::execute(ExecType aTypeOfExec)
458 {
459  int i = NdbConnection::execute(aTypeOfExec);
460  TraceBegin();
461  TraceNdbConnection(this);
462  TraceMethod("execute");
463  TraceExecType(aTypeOfExec);
464  TraceReturn();
465  TraceInt(i);
466  TraceEnd();
467  return i;
468 }
469 
470 const NdbError & CTraceNdbConnection::getNdbError(void) const
471 {
472  const NdbError& err = NdbConnection::getNdbError();
473  TraceBegin();
474  TraceNdbConnection(this);
475  TraceMethod("getNdbError");
476  TraceReturn();
477  TraceNdbError(err);
478  TraceEnd();
479  return err;
480 }
481 
482 
483 
484 // TraceNdb
485 
486 CTraceNdb::CTraceNdb(const char* aDataBase)
487 : Ndb(aDataBase)
488 {
489  TraceBegin();
490  TraceNdb(this);
491  TraceMethod("Ndb");
492  TraceString(aDataBase);
493  TraceReturn();
494  TraceVoid();
495  TraceEnd();
496 }
497 
498 CTraceNdbSchemaCon* CTraceNdb::startSchemaTransaction()
499 {
500  NdbSchemaCon* pNdbSchemaCon = Ndb::startSchemaTransaction();
501  TraceBegin();
502  TraceNdb(this);
503  TraceMethod("startSchemaTransaction");
504  TraceReturn();
505  TraceNdbSchemaCon(pNdbSchemaCon);
506  TraceEnd();
507  return (CTraceNdbSchemaCon*)pNdbSchemaCon;
508 }
509 
510 void CTraceNdb::closeSchemaTransaction(CTraceNdbSchemaCon* aSchemaCon)
511 {
512  Ndb::closeSchemaTransaction(aSchemaCon);
513  TraceBegin();
514  TraceNdb(this);
515  TraceMethod("closeSchemaTransaction");
516  TraceReturn();
517  TraceVoid();
518  TraceEnd();
519 }
520 
521 CTraceNdbConnection* CTraceNdb::startTransaction()
522 {
523  NdbConnection* pNdbConnection = Ndb::startTransaction();
524  TraceBegin();
525  TraceNdb(this);
526  TraceMethod("startTransaction");
527  TraceReturn();
528  TraceNdbConnection(pNdbConnection);
529  TraceEnd();
530  return (CTraceNdbConnection*)pNdbConnection;
531 }
532 
533 void CTraceNdb::closeTransaction(CTraceNdbConnection* aConnection)
534 {
535  Ndb::closeTransaction(aConnection);
536  TraceBegin();
537  TraceNdb(this);
538  TraceMethod("closeTransaction");
539  TraceNdbConnection(aConnection);
540  TraceReturn();
541  TraceVoid();
542  TraceEnd();
543 }
544 
545