rasdaman complete source
rmdebug.hh
Go to the documentation of this file.
1 /*
2  * This file is part of rasdaman community.
3  *
4  * Rasdaman community is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Rasdaman community 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 Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Copyright 2003 - 2010 Peter Baumann / rasdaman GmbH.
18  *
19  * For more information please see <http://www.rasdaman.org>
20  * or contact Peter Baumann via <baumann@rasdaman.com>.
21 */
22 
33 #ifndef _RMDEBUG_
34 #define _RMDEBUG_
35 
36 #ifdef __VISUALC__
37 #include <time.h>
38 #else
39 #include <sys/time.h>
40 #endif
41 
42 #include "raslib/rminit.hh"
43 #include "raslib/rm.hh"
44 
45 extern int RManDebug;
46 extern int RManBenchmark;
47 
48 #ifdef RMANDEBUG
49 
50 #define RMDBGIF( levell, module, cls, text ) \
51  if (RMDebug::debugOutput( levell, module, cls )) { text }
52 
53 #define RMDBGENTER( levell, module, cls, text ) \
54  RMCounter rmCounter(levell, module, cls); \
55  if (RMDebug::debugOutput( levell, module, cls )) { \
56  RMInit::dbgOut << "ENTER "; RMInit::dbgOut.width(18); RMInit::dbgOut.setf(ios::left, ios::adjustfield); RMInit::dbgOut << cls << " "; RMDebug::indentLine(); RMInit::dbgOut << text << endl << std::flush; \
57  }
58 
59 #define RMDBGMIDDLE( levell, module, cls, text ) \
60  if (RMDebug::debugOutput( levell, module, cls )) { \
61  RMInit::dbgOut << "MIDDLE "; RMInit::dbgOut.width(18); RMInit::dbgOut.setf(ios::left, ios::adjustfield); RMInit::dbgOut << cls << " "; RMDebug::indentLine(); RMInit::dbgOut << text << endl << std::flush; \
62  }
63 
64 #define RMDBGONCE( levell, module, cls, text ) \
65  RMCounter rmCounter(levell, module, cls); \
66  if (RMDebug::debugOutput(levell, module, cls)) \
67  { \
68  RMInit::dbgOut << "ONCE "; RMInit::dbgOut.width(18); RMInit::dbgOut.setf(ios::left, ios::adjustfield); RMInit::dbgOut << cls << " "; \
69  RMDebug::indentLine(); \
70  RMInit::dbgOut << text << endl << std::flush; \
71  }
72 
73 #define RMDBGEXIT( levell, module, cls, text ) \
74  if (RMDebug::debugOutput( levell, module, cls )) { \
75  RMInit::dbgOut << "EXIT "; RMInit::dbgOut.width(18); RMInit::dbgOut.setf(ios::left, ios::adjustfield); RMInit::dbgOut << cls << " "; RMDebug::indentLine(); RMInit::dbgOut << text << endl << std::flush; \
76  }
77 
78 #define RMDBCLASS( t1, t2, t3, t4, t5 ) RMDebug localRMDebug = RMDebug( t1, t2, t3, t4, t5 );
79 
80 #else
81 
82 // Note: some parts of the code rely on these to be terminated by a ';'!
83 #define RMDBGENTER( level, module, cls, text ) ;
84 #define RMDBGMIDDLE( level, module, cls, text ) ;
85 #define RMDBGONCE( level, module, cls, text ) ;
86 #define RMDBGEXIT( level, module, cls, text ) ;
87 #define RMDBGIF( level, module, cls, text) ;
88 
89 #define RMDBCLASS( t1, t2, t3, t4, t5 ) ;
90 #endif
91 
92 // generate benchmark code only when RMANBENCHMARK is set
93 #ifdef RMANBENCHMARK
94 #define RMTIMER(class, func) RMTimer localRMTimer = RMTimer(class, func);
95 #else
96 #define RMTIMER(class, func)
97 #endif
98 
99 //@ManMemo: Module: {\bf raslib}.
100 
101 /*@Doc:
102 RMDebug is not strictly part of RasLib. It is a class used for
103 generating debug output if compiling with RMANDEBUG defined. One way
104 of using it is to put the following at the beginning of a function:
105 
106 {\tt RMDebug localRMDebug = RMDebug("className", "functionName",
107 "moduleName", __FILE__, __LINE__");}
108 
109 This can be patched in automatically by a modified funchead.pl script.
110 
111 {\bf Functionality}
112 
113 Debug output printing class name, function name, module name, file
114 name and line number given as parameters to the constructor is
115 created, whenever the constructor is called. The destructor
116 outputs class name and function name. If the static members {\tt
117 debugModules} or {\tt debugClasses} are set, then only modules
118 which are mentioned in the array of strings {\tt debugModules} or
119 classes which are mentioned {\tt debugClasses} give debug output.
120 {\tt debugModules} and {\tt debugClasses} can either be read from
121 files named "rmdbmodules" and "rmdbclasses" or from the environment
122 variables RMDBGMODULES and RMDBGCLASSES. The environment variables
123 override the files. The contents of the files / variables are the
124 names of the modules / classes separated by whitespace (space,
125 newlines, ...). In the case of the modules each modulename may
126 be followed by ",<dbgLevel>" to set the debug level for that
127 module explizitly, otherwise the default is used.
128 
129 {\bf Interdependencies}
130 
131 If only certain modules or classes are to be debugged, RMDebug
132 has to be initialized in {\Ref RMInit}. This is done by reading
133 the files {\tt rmdbmodules} and {\tt rmdbclasses}. The files
134 should contain names of modules resp. classes to be debugged, each
135 (including the last one!) followed by end of line. */
136 
145 class RMDebug : public RM_Class
146 {
147 public:
149  RMDebug(const char* newClass, const char* newFunc, const char* newModule,
150  const char* newFile, int newLine);
152  RMDebug(int newLevel, const char* newClass, const char* newFun, int newModuleNum,
153  const char* newFile, int newLine);
155  ~RMDebug(void);
156 
158  static int initRMDebug(void);
159 
161  static inline int getModuleDebugLevel(int modNum)
162  {
163  return allModuleLevels[modNum];
164  }
166  static inline const char* getModuleName(int modNum)
167  {
168  return allModuleNames[modNum];
169  }
171  static inline void indentLine(void)
172  {
173  for (int i=0; i<level; i++) RMInit::dbgOut << " ";
174  }
175 
178  static int debugOutput(int dbgLevel, int modNum, const char* className);
179 
181  enum
182  {
210  } RMDebugModules;
211  /*@ManMemo level of function calls (incremented by constructor,
212  decremented by destrctor. */
213  static int level;
214 
215 private:
217  int checkDebug(void);
219  static char* loadTextFile(const char* name);
220  /*@Doc:
221  If {\tt debugModules} or {\tt debugClasses} is set, checks
222  if myModule or myClass is in the corresponding array.
223  */
224 
226  const char* myClass;
228  const char* myFunc;
230  const char* myModule;
232  const char* myFile;
234  int myLine;
236  int myModuleNum;
238  int myDebugLevel;
240  int myDebugOn;
242  static int numDebugModules;
244  static char** debugModules;
246  static char* debugModulesText;
248  static int numDebugClasses;
250  static char** debugClasses;
252  static char* debugClassesText;
254  static int* transDebugModules;
256  static const char* allModuleNames[];
258  static int allModuleLevels[];
259 };
260 
262 
298 class RMTimer : public RM_Class
299 {
300 public:
302  inline RMTimer(const char* newClass, const char* newFunc,
303  int newBmLevel = 0);
309  inline ~RMTimer();
312  inline void setOutput(int newOutput);
317  inline void pause();
320  inline void resume();
322  inline void start();
326  inline void stop();
332  inline int getTime();
334 
335 private:
337  const char* myClass;
339  const char* myFunc;
341  int output;
343  int bmLevel;
344  // reference parameter for gettimeofday().
345 #ifdef __VISUALC__
346  time_t acttime;
347 #else
348  timeval acttime;
349 #endif
350  long accuTime;
353  unsigned short running;
354  // reference parameter for gettimeofday, not used.
355  static struct timezone dummy;
357  long oldsec;
359  long oldusec;
361  inline void fetchTime();
362 };
364 
373 class RMCounter : public RM_Class
374 {
375 public:
377  RMCounter(int levell, int module, const char* cls);
379  ~RMCounter();
380 private:
381  bool doStuff;
382 };
383 
384 #include "raslib/rmdebug.icc"
385 
386 
387 #endif
static std::ostream dbgOut
output stream for debug information
Definition: rminit.hh:103
void start()
resets timer.
RMDebug(const char *newClass, const char *newFunc, const char *newModule, const char *newFile, int newLine)
constructor, initializes members and prints message.
Definition: rmdebug.hh:195
Definition: rmdebug.hh:189
Definition: rmdebug.hh:200
static const char * getModuleName(int modNum)
get the name of a module by its number
Definition: rmdebug.hh:166
~RMDebug(void)
destructor, prints message.
Definition: rmdebug.hh:186
RMTimer(const char *newClass, const char *newFunc, int newBmLevel=0)
constructor, initializes members and starts timer.
Definition: rmdebug.hh:203
Definition: rmdebug.hh:202
~RMCounter()
destructor, decrements indent level.
static int initRMDebug(void)
for initializing modules and classes to debug.
int RManDebug
Definition: rmdebug.hh:194
Definition: rmdebug.hh:208
Definition: rmdebug.hh:207
Definition: rmdebug.hh:193
int getTime()
delivers current time count.
Definition: rm.hh:36
Definition: rmdebug.hh:205
Definition: rmdebug.hh:145
static void indentLine(void)
indent by the amount specified by level
Definition: rmdebug.hh:171
Definition: rmdebug.hh:197
~RMTimer()
destructor, calls stop().
Definition: rmdebug.hh:183
Definition: rmdebug.hh:185
Definition: rmdebug.hh:206
RMCounter(int levell, int module, const char *cls)
constructor, increments indent level if the class should be debugged.
enum RMDebug::@48 RMDebugModules
all modules for debugging
static int debugOutput(int dbgLevel, int modNum, const char *className)
static int level
Definition: rmdebug.hh:213
void stop()
prints time spent if output is TRUE.
Definition: rmdebug.hh:198
Definition: rmdebug.hh:199
void setOutput(int newOutput)
switch output on RMInit::bmOut on and off.
Definition: rmdebug.hh:190
Definition: rmdebug.hh:204
Module: { raslib}.
Definition: rmdebug.hh:298
Definition: rmdebug.hh:187
Module: { raslib}.
Definition: rmdebug.hh:373
Definition: rmdebug.hh:191
Definition: rmdebug.hh:184
int RManBenchmark
Definition: rmdebug.hh:196
Definition: rmdebug.hh:201
void pause()
pauses timer.
Definition: rmdebug.hh:209
void resume()
resumes timer.
Definition: rmdebug.hh:188
static int getModuleDebugLevel(int modNum)
get the debug level of a module by its number
Definition: rmdebug.hh:161
Definition: rmdebug.hh:192