/* * This file is part of rasdaman community. * * Rasdaman community is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Rasdaman community is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with rasdaman community. If not, see . * * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / rasdaman GmbH. * * For more information please see * or contact Peter Baumann via . / /** * SOURCE: rmdebug.cc * * MODULE: raslib * CLASS: * * COMMENTS: * */ static const char rcsid[] = "@(#)raslib, RMDebug: $Header: /home/rasdev/CVS-repository/rasdaman/raslib/rmdebug.cc,v 1.33 2005/12/02 14:51:55 rasdev Exp $"; #include using namespace std; #include // fopen, getc #include #include #include #include #include "raslib/rmdebug.hh" #include "raslib/odmgtypes.hh" int RManDebug = 0; // debug level (0-4), 0 means no debug info at all int RManBenchmark = 4; // benchmark level (0-4) // initialization of static variables for RMDebug int RMDebug::level = 0; int RMDebug::numDebugModules = 0; char** RMDebug::debugModules = 0; char* RMDebug::debugModulesText = 0; int* RMDebug::transDebugModules = 0; int RMDebug::numDebugClasses = 0; char** RMDebug::debugClasses = 0; char* RMDebug::debugClassesText = 0; // all module names const char* RMDebug::allModuleNames[] = { "adminif", "applications", "blobif", "cachetamgr", "catalogif", "catalogmgr", "clientcomm", "conversion", "compression", "httpserver", "indexif", "indexmgr", "insertutils", "mddif", "mddmgr", "qlparser", "rasdl", "raslib", "rasodmg", "rasql", "server", "servercomm", "storageif", "storagemgr", "tools", "tilemgr", "utilities" }; int RMDebug::allModuleLevels[RMDebug::module_number]; // initialization of static variable for RMTimer #ifndef __VISUALC__ struct timezone RMTimer::dummy; #endif RMDebug::RMDebug(const char* newClass, const char* newFunc, const char* newModule, const char* newFile, int newLine) : myClass(newClass), myFunc(newFunc), myModule(newModule), myFile(newFile), myLine(newLine), myModuleNum(-1), myDebugLevel(2) { myDebugOn = checkDebug(); int useLevel = -1; if (myModuleNum >= 0) useLevel = allModuleLevels[myModuleNum]; if (useLevel < 0) useLevel = RManDebug; myDebugOn = myDebugOn && (useLevel >= myDebugLevel); if( myDebugOn ) { indentLine(); // output, when entering function RMInit::dbgOut << "D: " << myClass << "::" << myFunc << " entered " << "(" << myModule << ", " << myFile << ": " << myLine << ")." << endl; // indentation level++; } } RMDebug::RMDebug(int newLevel, const char* newClass, const char* newFunc, int newModuleNum, const char* newFile, int newLine) : myClass(newClass), myFunc(newFunc), myModule(NULL), myFile(newFile), myLine(newLine), myModuleNum(newModuleNum), myDebugLevel(newLevel) { myDebugOn = checkDebug() && (allModuleLevels[newModuleNum] >= myDebugLevel); if ( myDebugOn ) { indentLine(); // output when entering function RMInit::dbgOut << "D: " << myClass << "::" << myFunc << " entered " << "(" << allModuleNames[myModuleNum] << ", " << myFile << ": " << myLine << ")." << endl; // indentation level++; } } RMDebug::~RMDebug(void) { if( myDebugOn ) { // indentation level--; indentLine(); // output, when exiting function RMInit::dbgOut << "D: " << myClass << "::" << myFunc << " exited." << endl; } } char* RMDebug::loadTextFile(const char* name) { std::ifstream f; f.open(name); if (f.is_open()) { char* result; f.seekg(0, std::ios::end); std::streampos end = f.tellg(); r_Long resLen=(r_Long)end + 1; result = new char[resLen]; memset(result, 0, resLen); f.seekg(0, std::ios::beg); f.read(result, end); f.close(); result[resLen] = '\0'; return result; } return NULL; } int RMDebug::initRMDebug(void) { int errmod=0; int errclass=0; int j; const char* enVar; char* myPtr; // init all debug levels to global debug level for (j=0; j= 0) allModuleLevels[transDebugModules[j]] = modLevel; j++; } for (j=0; j 0) { if(myModuleNum >= 0) { if (allModuleLevels[myModuleNum] == 0) return 0; } else { // check if module is mentioned for(i = 0; i < numDebugModules; i++) { if(strcmp(debugModules[i], myModule) == 0) { myModuleNum = transDebugModules[i]; break; } } if (i >= numDebugModules) return 0; } } if((numDebugClasses > 0) && (myClass != NULL)) { // check if class is mentioned for(i = 0; i < numDebugClasses; i++) if(strcmp(debugClasses[i], myClass) == 0) break; if (i >= numDebugClasses) return 0; } } return 1; } int RMDebug::debugOutput(int dbgLevel, int modNum, const char* className) { int retval = 0; if ((numDebugModules == 0) && (numDebugClasses == 0)) { retval = (RManDebug >= dbgLevel); } else { if (numDebugModules > 0) { retval = (allModuleLevels[modNum] >= dbgLevel); } else { if ((numDebugClasses > 0) && (className != NULL)) { int i; for (i=0; i= numDebugClasses) retval = 0; else retval = 1; } else { //nothing to do } } } return retval; } RMCounter::RMCounter(int levell, int module, const char* cls) : doStuff(false) { if (RMDebug::debugOutput( levell, module, cls )) { //RMInit::dbgOut << "RMCounter() " << RMDebug::level << " "; doStuff = true; RMDebug::level++; //RMInit::dbgOut << RMDebug::level << endl; } } RMCounter::~RMCounter() { if (doStuff == true) { //RMInit::dbgOut << "~RMCounter() " << RMDebug::level << " "; RMDebug::level--; //RMInit::dbgOut << RMDebug::level << endl; } }