Trie Implementation
[csql.git] / src / storage / Debug.cxx
blob938803552682ee99be41855a520132ffc5747ceb
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<Debug.h>
17 #include<Config.h>
19 int DebugDM_Alloc = 0;
20 int DebugDM_VarAlloc = 0;
21 int DebugDM_Lock = 0;
22 int DebugDM_Transaction = 0;
23 int DebugDM_UndoLog = 0;
24 int DebugDM_RedoLog = 0;
25 int DebugDM_Index = 0;
26 int DebugDM_HashIndex = 0;
27 int DebugDM_TreeIndex = 0;
28 int DebugDM_TrieIndex = 1;
29 int DebugDM_SystemDatabase = 0;
30 int DebugDM_Database = 0;
31 int DebugDM_Table = 0;
32 int DebugDM_Predicate = 0;
33 int DebugDM_TableIterator = 0;
34 int DebugDM_Process=0;
35 int DebugDM_Network=0;
36 int DebugDM_Gateway=0;
37 int DebugDM_Adapter=0;
38 int DebugDM_SqlLog=0;
39 int DebugDM_CacheServer=0;
40 int DebugDM_TEST=1;
41 int DebugDM_Warning=0;
42 int printStackTrace()
44 #ifdef LINUX
45 void *array[10];
46 size_t size = backtrace(array, 10);
47 backtrace_symbols_fd(array, size, 2);
48 #endif
49 return 0;
52 int printError1(DbRetVal val, char* fname, int lno, const char *format, ...)
54 va_list ap;
55 int fd = -1;
56 char tempBuffer[25];
57 struct timeval timeStamp;
58 os::gettimeofday(&timeStamp);
59 struct tm *tempTm = os::localtime(&timeStamp.tv_sec);
60 char mesgBuf[1024];
61 #if defined(SOLARIS) && defined(REMOTE_SOLARIS)
62 strftime(tempBuffer, 25, "%d/%m/%Y %H:%M:%S", (struct std::tm*) tempTm);
63 #else
64 strftime(tempBuffer, 25, "%d/%m/%Y %H:%M:%S", tempTm);
65 #endif
67 if (strncasecmp(Conf::config.getStderrFile(),"stderr", 6) == 0) fd = 2;
68 else {
69 fd = os::openFileForAppend(Conf::config.getStderrFile(), O_CREAT);
70 if (fd == -1) fd = 2;
73 snprintf(mesgBuf, MAX_TRACE_LOG_LENGTH, "%s.%6d:%5d:%10lu:%s:%d:",
74 tempBuffer, timeStamp.tv_usec, os::getpid(), os::getthrid(), fname, lno);
76 os::write(fd, mesgBuf, strlen(mesgBuf));
78 va_start(ap, format);
80 int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
81 if (err < 0) { return err; }
83 os::write(fd, mesgBuf, strlen(mesgBuf));
84 strcpy(mesgBuf,"\n");
85 os::write(fd, mesgBuf, strlen(mesgBuf));
86 //2->stderr
87 return 0;
90 int printDebug1(int module, char *fname, int lno, const char *format, ...)
92 switch(module) {
93 case DM_Alloc: { if (!DebugDM_Alloc) return 1; break; }
94 case DM_VarAlloc: { if (!DebugDM_VarAlloc) return 1; break; }
95 case DM_Lock: { if (!DebugDM_Lock) return 1; break; }
96 case DM_Transaction: { if (!DebugDM_Transaction) return 1; break; }
97 case DM_UndoLog: { if (!DebugDM_UndoLog) return 1; break; }
98 case DM_RedoLog: { if (!DebugDM_RedoLog) return 1; break; }
99 case DM_HashIndex: { if (!DebugDM_HashIndex) return 1; break; }
100 case DM_TreeIndex: { if (!DebugDM_TreeIndex) return 1; break; }
101 case DM_SystemDatabase: { if (!DebugDM_SystemDatabase) return 1; break; }
102 case DM_Database: { if (!DebugDM_Database) return 1; break; }
103 case DM_Table: { if (!DebugDM_Table) return 1; break; }
104 case DM_Iterator: { if (!DebugDM_TableIterator) return 1; break; }
105 case DM_Predicate: { if (!DebugDM_Predicate) return 1; break; }
106 case DM_Process: { if (!DebugDM_Process) return 1; break; }
107 case DM_Network: { if (!DebugDM_Network) return 1; break; }
108 case DM_Gateway: { if (!DebugDM_Gateway) return 1; break; }
109 case DM_Adapter: { if (!DebugDM_Adapter) return 1; break; }
110 case DM_SqlLog: { if (!DebugDM_SqlLog) return 1; break; }
111 case DM_CacheServer: { if (!DebugDM_CacheServer) return 1; break; }
112 case DM_TEST: { if (!DebugDM_TEST) return 1; break; }
113 case DM_Warning: { if (!DebugDM_Warning) return 1; break; }
117 va_list ap;
118 char mesgBuf[1024];
120 sprintf(mesgBuf, "D:%s:%d:%lu:%s:%d:", moduleNames[module],
121 os::getpid(), os::getthrid(), fname, lno);
122 os::write(1, mesgBuf, strlen(mesgBuf));
124 va_start(ap, format);
126 int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
127 if(err < 0) {
128 return err;
130 os::write(1, mesgBuf, strlen(mesgBuf));
131 strcpy(mesgBuf,"\n");
132 os::write(1, mesgBuf, strlen(mesgBuf));
133 //1->stdout
134 return 0;