(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.16 and 1.40

version 1.16, 2002/08/27 17:42:27 version 1.40, 2006/11/10 18:14:58
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 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.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec 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 21 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)  
 //  
 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@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/System.h> #include <Pegasus/Common/System.h>
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
Line 56 
Line 58 
 const char Tracer::_METHOD_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_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 72 
Line 76 
 const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21; const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21;
  
 // 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 = 21;
   
   // Initialize public indicator of trace state
   Boolean Tracer::_traceOn = false;
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // Tracer constructor // Tracer constructor
Line 80 
Line 87 
 // Single Instance of Tracer is maintained for each process. // Single Instance of Tracer is maintained for each process.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer::Tracer() Tracer::Tracer()
       : _traceComponentMask(new Boolean[_NUM_COMPONENTS]),
         _traceLevelMask(0),
         _traceHandler(new TraceFileHandler())
 { {
     // Initialize Trace File Handler  
     _traceHandler=new TraceFileHandler();  
     _traceLevelMask=0;  
     _traceComponentMask=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 96 
Line 101 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer::~Tracer() Tracer::~Tracer()
 { {
     delete []_traceComponentMask;  
     delete _traceHandler;  
     delete _tracerInstance;     delete _tracerInstance;
 } }
  
Line 150 
Line 153 
             // 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:%u:%s:%u]: ",                 "[%d:%s:%s:%u]: ",
                System::getPID(),                System::getPID(),
                Uint32(pegasus_thread_self()),                 Threads::id().buffer,
                fileName,                fileName,
                lineNum);                lineNum);
  
Line 238 
Line 241 
     {     {
         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 263 
Line 266 
     {     {
         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 275 
Line 278 
 void Tracer::_traceCIMException( void Tracer::_traceCIMException(
     const Uint32 traceComponent,     const Uint32 traceComponent,
     const Uint32 traceLevel,     const Uint32 traceLevel,
     CIMException cimException)      const CIMException& cimException)
 { {
     if ( traceLevel == LEVEL1 )     if ( traceLevel == LEVEL1 )
     {     {
Line 318 
Line 321 
         // 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:%u:%s:%u]: ",             "[%d:%s:%s:%u]: ",
            System::getPID(),            System::getPID(),
            Uint32(pegasus_thread_self()),             Threads::id().buffer,
            fileName,            fileName,
            lineNum);            lineNum);
   
         _trace(traceComponent,message,fmt,argList);         _trace(traceComponent,message,fmt,argList);
  
         va_end(argList);         va_end(argList);
Line 355 
Line 360 
         // 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:%u:%s:%u]: ",             "[%d:%s:%s:%u]: ",
            System::getPID(),            System::getPID(),
            Uint32(pegasus_thread_self()),             Threads::id().buffer,
            fileName,            fileName,
            lineNum);            lineNum);
   
         _trace(traceComponent,message,fmt,argList);         _trace(traceComponent,message,fmt,argList);
         va_end(argList);         va_end(argList);
  
Line 373 
Line 380 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Checks if trace is enabled for the given component and level //Checks if trace is enabled for the given component and level
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::_isTraceEnabled(const Uint32 traceComponent,  Boolean Tracer::_isTraceEnabled(
       const Uint32 traceComponent,
     const Uint32 traceLevel)     const Uint32 traceLevel)
 { {
     Tracer* instance = _getInstance();     Tracer* instance = _getInstance();
Line 381 
Line 389 
     {     {
         return false;         return false;
     }     }
     return ((instance->_traceComponentMask[traceComponent]) &&      return (((instance->_traceComponentMask.get())[traceComponent]) &&
             (traceLevel  & instance->_traceLevelMask));             (traceLevel  & instance->_traceLevelMask));
 } }
  
Line 398 
Line 406 
  
     // 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);
     }     }
     else     else
Line 427 
Line 440 
         // 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[2 * _STRLEN_MAX_PID_TID + 6];
         sprintf(tmpBuffer, "[%u:%u]: ", System::getPID(),          sprintf(tmpBuffer, "[%u:%s]: ",
                 Uint32(pegasus_thread_self()));              System::getPID(), Threads::id().buffer);
           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;
     }     }
  
     // 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;
 } }
  
Line 446 
Line 463 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::isValidFileName(const char* filePath) Boolean Tracer::isValidFileName(const char* filePath)
 { {
     return (_getInstance()->_traceHandler->isValidFilePath(filePath));      String moduleName = _getInstance()->_moduleName;
       if (moduleName == String::EMPTY)
       {
           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::isValidComponents(const String traceComponents)  Boolean Tracer::isValidComponents(const String& traceComponents)
 { {
     String invalidComponents;     String invalidComponents;
     return isValidComponents(traceComponents, invalidComponents);     return isValidComponents(traceComponents, invalidComponents);
 } }
  
 Boolean Tracer::isValidComponents( Boolean Tracer::isValidComponents(
     const String traceComponents, String& invalidComponents)      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 528 
Line 556 
         // trace components is empty, it is a valid value so return true         // trace components is empty, it is a valid value so return true
         return _SUCCESS;         return _SUCCESS;
     }     }
   
     if ( invalidComponents != String::EMPTY )     if ( invalidComponents != String::EMPTY )
     {     {
         retCode = false;         retCode = false;
Line 541 
Line 570 
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
   //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 553 
Line 590 
 } }
  
 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
 // interfaces. If defined the interfaces map to empty functions  // interfaces. This section defines the trace functions IF the remove
   // trace flag is NOT set.  If it is set, they are defined as empty functions
   // in the header file.
  
 #ifndef PEGASUS_REMOVE_TRACE #ifndef PEGASUS_REMOVE_TRACE
  
Line 562 
Line 601 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Uint32 Tracer::setTraceFile(const char* traceFile) Uint32 Tracer::setTraceFile(const char* traceFile)
 { {
     return (_getInstance()->_traceHandler->setFileName (traceFile));      if (*traceFile == 0)
       {
           return 1;
       }
   
       String moduleName = _getInstance()->_moduleName;
       if (moduleName == String::EMPTY)
       {
           return _getInstance()->_traceHandler->setFileName(traceFile);
       }
       else
       {
           String extendedTraceFile = String(traceFile) + "." + moduleName;
           return _getInstance()->_traceHandler->setFileName(
               extendedTraceFile.getCString());
       }
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 600 
Line 654 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // 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 613 
Line 667 
         // Check if ALL is specified         // Check if ALL is specified
         if (String::equalNoCase(componentStr,"ALL"))         if (String::equalNoCase(componentStr,"ALL"))
         {         {
             for (index=0; index < _NUM_COMPONENTS;              for (index = 0; index < _NUM_COMPONENTS; index++)
                     _getInstance()->_traceComponentMask[index++] = true);              {
                   (_getInstance()->_traceComponentMask.get())[index] = true;
               }
               _traceOn = true;
             return ;             return ;
         }         }
  
         // initialise ComponentMask array to False          // initialize ComponentMask array to False
         for (index = 0;index < _NUM_COMPONENTS;          for (index = 0; index < _NUM_COMPONENTS; index++)
                 _getInstance()->_traceComponentMask[index++] = false);          {
               (_getInstance()->_traceComponentMask.get())[index] = false;
           }
           _traceOn = false;
  
         // Append _COMPONENT_SEPARATOR to the end of the traceComponents         // Append _COMPONENT_SEPARATOR to the end of the traceComponents
         componentStr.append(_COMPONENT_SEPARATOR);         componentStr.append(_COMPONENT_SEPARATOR);
Line 639 
Line 699 
                 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 = true;
  
                     // Found component, break from the loop                     // Found component, break from the loop
                     break;                     break;
Line 657 
Line 718 
     else     else
     {     {
         // initialise ComponentMask array to False         // initialise ComponentMask array to False
         for (Uint32 index = 0;index < _NUM_COMPONENTS;          for (Uint32 index = 0;index < _NUM_COMPONENTS; index++)
                  _getInstance()->_traceComponentMask[index++] = false);          {
               (_getInstance()->_traceComponentMask.get())[index] = false;
           }
           _traceOn = 0;
     }     }
     return ;     return ;
 } }
  
 #endif  void Tracer::traceEnter(
       TracerToken& token,
       Uint32 traceComponent,
       const char* method)
   {
       if (_traceOn)
       {
           token.component = traceComponent;
           token.method = method;
   
           _traceEnter(
               "unknown", 0, traceComponent, "%s %s", _METHOD_ENTER_MSG, method);
       }
   }
   
   void Tracer::traceExit(TracerToken& token)
   {
       if (_traceOn)
           _traceExit(
               "unknown",0, token.component, "%s %s",
               _METHOD_EXIT_MSG, token.method);
   }
   
   void Tracer::traceEnter(
       TracerToken& token,
       const char* file,
       size_t line,
       Uint32 traceComponent,
       const char* method)
   {
       if (_traceOn)
       {
           token.component = traceComponent;
           token.method = method;
   
           _traceEnter(
               file, line, traceComponent, "%s %s", _METHOD_ENTER_MSG, method);
       }
   }
   
   void Tracer::traceExit(
       TracerToken& token,
       const char* file,
       size_t line)
   {
       if (_traceOn)
           _traceExit(
               file, line, token.component, "%s %s",
               _METHOD_EXIT_MSG, token.method);
   }
   
   void Tracer::traceBuffer(
       const Uint32 traceComponent,
       const Uint32 traceLevel,
       const char*  data,
       const Uint32 size)
   {
       if (_traceOn)
           _traceBuffer(traceComponent, traceLevel, data, size);
   }
   
   void Tracer::traceBuffer(
       const char*  fileName,
       const Uint32 lineNum,
       const Uint32 traceComponent,
       const Uint32 traceLevel,
       const char*  data,
       const Uint32 size)
   {
       if (_traceOn)
       {
           _traceBuffer(
               fileName, lineNum, traceComponent, traceLevel, data, size);
       }
   }
   
   void Tracer::trace(
       const Uint32 traceComponent,
       const Uint32 traceLevel,
       const char *fmt,
       ...)
   {
       if (_traceOn)
       {
           va_list argList;
   
           va_start(argList,fmt);
           _trace(traceComponent,traceLevel,fmt,argList);
           va_end(argList);
       }
   }
   
   void Tracer::trace(
       const char* fileName,
       const Uint32 lineNum,
       const Uint32 traceComponent,
       const Uint32 traceLevel,
       const char* fmt,
       ...)
   {
       if (_traceOn)
       {
           va_list argList;
   
           va_start(argList,fmt);
           _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList);
           va_end(argList);
       }
   }
   
   void Tracer::trace(
       const char* fileName,
       const Uint32 lineNum,
       const Uint32 traceComponent,
       const Uint32 traceLevel,
       const String& traceString)
   {
       if (_traceOn)
       {
           _traceString(
               fileName, lineNum, traceComponent, traceLevel, traceString);
       }
   }
   
   void Tracer::traceCIMException(
       const Uint32 traceComponent,
       const Uint32 traceLevel,
       const CIMException& cimException)
   {
       if (_traceOn)
       {
           _traceCIMException(traceComponent, traceLevel, cimException);
       }
   }
   
   void Tracer::trace(
       const Uint32 traceComponent,
       const Uint32 level,
       const String& string)
   {
       trace("unknown", 0, traceComponent, level, string);
   }
   
   #endif /* !PEGASUS_REMOVE_TRACE */
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.16  
changed lines
  Added in v.1.40

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2