(file) Return to Tracer.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/Tracer.cpp between version 1.7 and 1.31

version 1.7, 2002/03/14 19:52:23 version 1.31, 2005/11/21 08:37:44
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2005////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // The Open Group, Tivoli Systems  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 24 
Line 30 
 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com) // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
 // //
 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com) // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
   //              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
   //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
   //              Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2498
   //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/Destroyer.h>  
 #include <Pegasus/Common/Thread.h> #include <Pegasus/Common/Thread.h>
 #include <Pegasus/Common/IPC.h> #include <Pegasus/Common/IPC.h>
 #include <Pegasus/Common/System.h> #include <Pegasus/Common/System.h>
Line 50 
Line 59 
 // Set the return codes // Set the return codes
 const Boolean Tracer::_SUCCESS = 1; const Boolean Tracer::_SUCCESS = 1;
 const Boolean Tracer::_FAILURE = 0; const Boolean Tracer::_FAILURE = 0;
 String  Tracer::_EMPTY_STRING = String::EMPTY;  
  
 // Set the Enter and Exit messages // Set the Enter and Exit messages
 const char Tracer::_FUNC_ENTER_MSG[] = "Entering method";  const char Tracer::_METHOD_ENTER_MSG[] = "Entering method";
 const char Tracer::_FUNC_EXIT_MSG[]  = "Exiting method";  const char Tracer::_METHOD_EXIT_MSG[]  = "Exiting method";
  
 // Set Log messages // Set Log messages
 const char Tracer::_LOG_MSG[] = "LEVEL1 may only be used with trace macros PEG_FUNC_ENTER/PEG_FUNC_EXIT or PEG_METHOD_ENTER/PEG_METHOD_EXIT.";  const char Tracer::_LOG_MSG[] = "LEVEL1 may only be used with trace macros PEG_METHOD_ENTER/PEG_METHOD_EXIT.";
  
 // Initialize singleton instance of Tracer // Initialize singleton instance of Tracer
 Tracer* Tracer::_tracerInstance = 0; Tracer* Tracer::_tracerInstance = 0;
Line 75 
Line 83 
 // Set the max PID and Thread ID Length // Set the max PID and Thread ID Length
 const Uint32 Tracer::_STRLEN_MAX_PID_TID = 20; const Uint32 Tracer::_STRLEN_MAX_PID_TID = 20;
  
   // Initialize public indicator of trace state
   Uint32 Tracer::_traceOn=0;
   
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // Tracer constructor // Tracer constructor
 // Constructor is private to preclude construction of Tracer objects // Constructor is private to preclude construction of Tracer objects
Line 83 
Line 94 
 Tracer::Tracer() Tracer::Tracer()
 { {
     // Initialize Trace File Handler     // Initialize Trace File Handler
     _traceHandler=new TraceFileHandler();      _traceHandler.reset(new TraceFileHandler());
     _traceLevelMask=0;     _traceLevelMask=0;
     _traceComponentMask=new Boolean[_NUM_COMPONENTS];      _traceComponentMask.reset(new Boolean[_NUM_COMPONENTS]);
  
     // Initialize ComponentMask array to false     // Initialize ComponentMask array to false
     for (Uint32 index=0;index < _NUM_COMPONENTS;     for (Uint32 index=0;index < _NUM_COMPONENTS;
         _traceComponentMask[index++]=false);          (_traceComponentMask.get())[index++]=false);
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 97 
Line 108 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer::~Tracer() Tracer::~Tracer()
 { {
     delete []_traceComponentMask;  
     delete _traceHandler;  
     delete _tracerInstance;     delete _tracerInstance;
 } }
  
Line 114 
Line 123 
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         // ATTN: Setting the Log file type to DEBUG_LOG          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
         // May need to change to an appropriate log file type  
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);  
     }     }
     else     else
     {     {
Line 142 
Line 149 
  
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
     }     }
     else     else
     {     {
Line 153 
Line 160 
             // Needs to be updated if additional info is added             // Needs to be updated if additional info is added
             //             //
             message = new char[ strlen(fileName) +             message = new char[ strlen(fileName) +
                 _STRLEN_MAX_UNSIGNED_INT + _STRLEN_MAX_PID_TID ];                  _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
             sprintf(             sprintf(
                message,                message,
                "[%d:%d:%s:%d]: ",  #if defined(PEGASUS_OS_VMS)
                  //
                  // pegasus_thread_self returns long-long-unsigned.
                  //
                  "[%d:%llu:%s:%u]: ",
   //               "[%x:%llx:%s:%u]: ",
                System::getPID(),                System::getPID(),
                pegasus_thread_self(),                pegasus_thread_self(),
   #else
                  "[%d:%u:%s:%u]: ",
                  System::getPID(),
                  Uint32(pegasus_thread_self()),
   #endif
                fileName,                fileName,
                lineNum);                lineNum);
  
Line 179 
Line 196 
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
     }     }
     else     else
     {     {
Line 208 
Line 225 
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
     }     }
     else     else
     {     {
Line 235 
Line 252 
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
     }     }
     else     else
     {     {
         if (_isTraceEnabled(traceComponent,traceLevel))         if (_isTraceEnabled(traceComponent,traceLevel))
         {         {
             ArrayDestroyer<char> traceMsg(traceString.allocateCString());              trace(traceComponent,traceLevel,"%s",
             trace(traceComponent,traceLevel,"%s",traceMsg.getPointer());                         (const char *)traceString.getCString());
         }         }
     }     }
 } }
Line 260 
Line 277 
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
     }     }
     else     else
     {     {
         if ( _isTraceEnabled( traceComponent, traceLevel ) )         if ( _isTraceEnabled( traceComponent, traceLevel ) )
         {         {
             ArrayDestroyer<char> traceMsg(traceString.allocateCString());              trace(fileName,lineNum,traceComponent,traceLevel,"%s",
             trace(fileName,lineNum,traceComponent,traceLevel,"%s",traceMsg.getPointer());                       (const char *)traceString.getCString());
         }         }
     }     }
 } }
Line 282 
Line 299 
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0", _LOG_MSG);          trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
     }     }
     else     else
     {     {
         if ( _isTraceEnabled( traceComponent, traceLevel ) )         if ( _isTraceEnabled( traceComponent, traceLevel ) )
         {         {
             // get the CIMException trace message string             // get the CIMException trace message string
             String traceMsg = cimException.getTraceMessage();              String traceMsg =
                   TraceableCIMException(cimException).getTraceDescription();
  
             // trace the string             // trace the string
             _traceString(traceComponent, traceLevel, traceMsg);             _traceString(traceComponent, traceLevel, traceMsg);
Line 320 
Line 338 
         // Needs to be updated if additional info is added         // Needs to be updated if additional info is added
         //         //
         message = new char[ strlen(fileName) +         message = new char[ strlen(fileName) +
             _STRLEN_MAX_UNSIGNED_INT + _STRLEN_MAX_PID_TID ];                              _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
   
   #if defined(PEGASUS_OS_VMS)
           //
           // pegasus_thread_self returns long-long-unsigned.
           //
         sprintf(         sprintf(
            message,            message,
            "[%d:%d:%s:%d]: ",             "[%d:%llu:%s:%u]: ",
            System::getPID(),            System::getPID(),
            pegasus_thread_self(),            pegasus_thread_self(),
            fileName,            fileName,
            lineNum);            lineNum);
   #else
           sprintf(
              message,
              "[%d:%u:%s:%u]: ",
              System::getPID(),
              Uint32(pegasus_thread_self()),
              fileName,
              lineNum);
   #endif
         _trace(traceComponent,message,fmt,argList);         _trace(traceComponent,message,fmt,argList);
  
         va_end(argList);         va_end(argList);
Line 357 
Line 389 
         // Needs to be updated if additional info is added         // Needs to be updated if additional info is added
         //         //
         message = new char[ strlen(fileName) +         message = new char[ strlen(fileName) +
             _STRLEN_MAX_UNSIGNED_INT + _STRLEN_MAX_PID_TID ];                              _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
   
   #if defined(PEGASUS_OS_VMS)
           //
           // pegasus_thread_self returns long-long-unsigned.
           //
         sprintf(         sprintf(
            message,            message,
            "[%d:%d:%s:%d]: ",             "[%d:%llu:%s:%u]: ",
            System::getPID(),            System::getPID(),
            pegasus_thread_self(),            pegasus_thread_self(),
            fileName,            fileName,
            lineNum);            lineNum);
   #else
           sprintf(
              message,
              "[%d:%u:%s:%u]: ",
              System::getPID(),
              Uint32(pegasus_thread_self()),
              fileName,
              lineNum);
   #endif
         _trace(traceComponent,message,fmt,argList);         _trace(traceComponent,message,fmt,argList);
         va_end(argList);         va_end(argList);
  
Line 383 
Line 429 
     {     {
         return false;         return false;
     }     }
     return ((instance->_traceComponentMask[traceComponent]) &&      return (((instance->_traceComponentMask.get())[traceComponent]) &&
             (traceLevel  & instance->_traceLevelMask));             (traceLevel  & instance->_traceLevelMask));
 } }
  
Line 400 
Line 446 
  
     // Get the current system time and prepend to message     // Get the current system time and prepend to message
     String currentTime = System::getCurrentASCIITime();     String currentTime = System::getCurrentASCIITime();
     ArrayDestroyer<char> timeStamp(currentTime.allocateCString());      CString timeStamp = currentTime.getCString();
  
     //     //
     // Allocate messageHeader.     // Allocate messageHeader.
     // Needs to be updated if additional info is added     // Needs to be updated if additional info is added
     //     //
     msgHeader = new char [strlen(message)  
         + strlen(TRACE_COMPONENT_LIST[traceComponent])  
         + strlen(timeStamp.getPointer()) + _STRLEN_MAX_PID_TID];  
  
     // Construct the message header     // Construct the message header
     // The message header is in the following format     // The message header is in the following format
     // timestamp: <component name> [file name:line number]     // timestamp: <component name> [file name:line number]
     if (strcmp(message,"") != 0)      if (*message != '\0')
     {     {
         sprintf(msgHeader,"%s: %s %s",timeStamp.getPointer(),         // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used in this format string
          msgHeader = new char [strlen(message)
                                + strlen(TRACE_COMPONENT_LIST[traceComponent])
                                + strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];
   
           sprintf(msgHeader,"%s: %s %s",(const char*)timeStamp,
             TRACE_COMPONENT_LIST[traceComponent] ,message);             TRACE_COMPONENT_LIST[traceComponent] ,message);
           //delete [] msgHeader;
     }     }
     else     else
     {     {
Line 429 
Line 480 
         // Allocate messageHeader.         // Allocate messageHeader.
         // Needs to be updated if additional info is added         // Needs to be updated if additional info is added
         //         //
         tmpBuffer = new char[_STRLEN_MAX_PID_TID];          tmpBuffer = new char[_STRLEN_MAX_PID_TID + 6];
         sprintf(tmpBuffer,"[%d:%d]: ",System::getPID(),pegasus_thread_self());  #if defined(PEGASUS_OS_VMS)
           //
           // pegasus_thread_self returns long-long-unsigned.
           //
           sprintf(tmpBuffer, "[%u:%llu]: ", System::getPID(),
                   pegasus_thread_self());
   #else
           sprintf(tmpBuffer, "[%u:%u]: ", System::getPID(),
                   Uint32(pegasus_thread_self()));
   #endif
           msgHeader = new char [ strlen(timeStamp) + strlen(TRACE_COMPONENT_LIST[traceComponent]) +
                                  strlen(tmpBuffer) + 1  + 5 ];
  
         sprintf(msgHeader,"%s: %s %s ",timeStamp.getPointer(),          sprintf(msgHeader,"%s: %s %s ",(const char*)timeStamp,
             TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );             TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );
         delete []tmpBuffer;         delete []tmpBuffer;
           //delete [] msgHeader;
   
     }     }
  
     // Call trace file handler to write message     // Call trace file handler to write message
     _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);     _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);
   
     delete []msgHeader;     delete []msgHeader;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Validate the trace file //Validate the trace file
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::isValid(const char* filePath)  Boolean Tracer::isValidFileName(const char* filePath)
   {
       String moduleName = _getInstance()->_moduleName;
       if (moduleName == String::EMPTY)
 { {
     return (_getInstance()->_traceHandler->isValidFilePath(filePath));     return (_getInstance()->_traceHandler->isValidFilePath(filePath));
 } }
       else
       {
           String extendedFilePath = String(filePath) + "." + moduleName;
           return (_getInstance()->_traceHandler->isValidFilePath(
               extendedFilePath.getCString()));
       }
   }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Validate the trace components //Validate the trace components
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::isValid(  Boolean Tracer::isValidComponents(const String& traceComponents)
                      const String traceComponents, String& invalidComponents)  {
       String invalidComponents;
       return isValidComponents(traceComponents, invalidComponents);
   }
   
   Boolean Tracer::isValidComponents(
       const String& traceComponents, String& invalidComponents)
 { {
     // Validate the trace components and modify the traceComponents argument     // Validate the trace components and modify the traceComponents argument
     // to reflect the invalid components     // to reflect the invalid components
Line 478 
Line 559 
         }         }
  
         // Append _COMPONENT_SEPARATOR to the end of the traceComponents         // Append _COMPONENT_SEPARATOR to the end of the traceComponents
         componentStr += _COMPONENT_SEPARATOR;          componentStr.append(_COMPONENT_SEPARATOR);
  
         while (componentStr != String::EMPTY)         while (componentStr != String::EMPTY)
         {         {
Line 513 
Line 594 
  
             if ( !validComponent )             if ( !validComponent )
             {             {
                 invalidComponents += componentName;                  invalidComponents.append(componentName);
                 invalidComponents += _COMPONENT_SEPARATOR;                  invalidComponents.append(_COMPONENT_SEPARATOR);
             }             }
         }         }
     }     }
Line 536 
Line 617 
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
   //Set the name of the module being traced
   ////////////////////////////////////////////////////////////////////////////////
   void Tracer::setModuleName(const String& moduleName)
   {
       _getInstance()->_moduleName = moduleName;
   }
   
   ////////////////////////////////////////////////////////////////////////////////
 //Returns the Singleton instance of the Tracer //Returns the Singleton instance of the Tracer
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer* Tracer::_getInstance() Tracer* Tracer::_getInstance()
Line 557 
Line 646 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Uint32 Tracer::setTraceFile(const char* traceFile) Uint32 Tracer::setTraceFile(const char* traceFile)
 { {
       if (*traceFile == 0)
       {
           return 1;
       }
   
       String moduleName = _getInstance()->_moduleName;
       if (moduleName == String::EMPTY)
       {
     return (_getInstance()->_traceHandler->setFileName (traceFile));     return (_getInstance()->_traceHandler->setFileName (traceFile));
 } }
       else
       {
           String extendedTraceFile = String(traceFile) + "." + moduleName;
           return (_getInstance()->_traceHandler->setFileName(
               extendedTraceFile.getCString()));
       }
   }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Set the trace level //Set the trace level
Line 595 
Line 699 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // Set components to be traced. // Set components to be traced.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::setTraceComponents( const String traceComponents )  void Tracer::setTraceComponents(const String& traceComponents)
 { {
     Uint32 position          = 0;     Uint32 position          = 0;
     Uint32 index             = 0;     Uint32 index             = 0;
Line 609 
Line 713 
         if (String::equalNoCase(componentStr,"ALL"))         if (String::equalNoCase(componentStr,"ALL"))
         {         {
             for (index=0; index < _NUM_COMPONENTS;             for (index=0; index < _NUM_COMPONENTS;
                     _getInstance()->_traceComponentMask[index++] = true);                      (_getInstance()->_traceComponentMask.get())[index++] = true);
               _traceOn = 1;
             return ;             return ;
         }         }
  
         // initialise ComponentMask array to False         // initialise ComponentMask array to False
         for (index = 0;index < _NUM_COMPONENTS;         for (index = 0;index < _NUM_COMPONENTS;
                 _getInstance()->_traceComponentMask[index++] = false);                (_getInstance()->_traceComponentMask.get())[index++] = false);
           _traceOn = 0;
  
         // Append _COMPONENT_SEPARATOR to the end of the traceComponents         // Append _COMPONENT_SEPARATOR to the end of the traceComponents
         componentStr += _COMPONENT_SEPARATOR;          componentStr.append(_COMPONENT_SEPARATOR);
  
         while (componentStr != String::EMPTY)         while (componentStr != String::EMPTY)
         {         {
Line 634 
Line 740 
                 if (String::equalNoCase(                 if (String::equalNoCase(
                        componentName,TRACE_COMPONENT_LIST[index]))                        componentName,TRACE_COMPONENT_LIST[index]))
                 {                 {
                     _getInstance()->_traceComponentMask[index]=true;                      (_getInstance()->_traceComponentMask.get())[index]=true;
                       _traceOn = 1;
  
                     // Found component, break from the loop                     // Found component, break from the loop
                     break;                     break;
Line 653 
Line 760 
     {     {
         // initialise ComponentMask array to False         // initialise ComponentMask array to False
         for (Uint32 index = 0;index < _NUM_COMPONENTS;         for (Uint32 index = 0;index < _NUM_COMPONENTS;
                  _getInstance()->_traceComponentMask[index++] = false);                   (_getInstance()->_traceComponentMask.get())[index++] = false);
           _traceOn = 0;
     }     }
     return ;     return ;
 } }


Legend:
Removed from v.1.7  
changed lines
  Added in v.1.31

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2