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

Diff for /pegasus/src/Pegasus/Common/TraceMemoryHandler.cpp between version 1.8 and 1.9

version 1.8, 2008/09/18 07:50:07 version 1.9, 2008/09/18 08:01:37
Line 52 
Line 52 
 # endif # endif
 #endif #endif
  
 //#define DBG(output) output  
 #define DBG(output)  
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //  Constructs TraceMemoryHandler with a default buffer size  
 ////////////////////////////////////////////////////////////////////////////////  
 TraceMemoryHandler::TraceMemoryHandler()  
 {  
     Uint32 traceAreaSize = PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB * 1024;  
   
     _initialize(traceAreaSize);  
 }  
   
 ////////////////////////////////////////////////////////////////////////////////  
 //  Constructs TraceMemoryHandler with a custom buffer size //  Constructs TraceMemoryHandler with a custom buffer size
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 TraceMemoryHandler::TraceMemoryHandler( Uint32 bufferSize )  TraceMemoryHandler::TraceMemoryHandler():
       _overflowBuffer(0),
       _overflowBufferSize(0),
       _traceArea(0),
       _leftBytesInBuffer(0),
       _inUseCounter(0),
       _lockCounter(1),
       _dying(false),
       _contentionCount(0),
       _numberOfLocksObtained(0),
       _traceFileName(0)
 { {
     Uint32 traceAreaSize = bufferSize * 1024;  
  
     _initialize(traceAreaSize);  
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //  Private method to (re-)initialize the memory buffer //  Private method to (re-)initialize the memory buffer
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void TraceMemoryHandler::_initialize( Uint32 traceAreaSize )  void TraceMemoryHandler::_initializeTraceArea()
 { {
     _dying = false;      if (_traceArea)
     _inUseCounter = 0;      {
     _lockCounter  = 1;          delete _traceArea;
     _contentionCount = 0;      }
     _numberOfLocksObtained = 0;  
     _traceFileName = 0;  
   
  
     _overflowBuffer = 0;      // get the memory buffer size from the tracer instance.
     _overflowBufferSize = 0;      Uint32 traceAreaSize =
           Tracer::_getInstance()->_traceMemoryBufferSize * 1024;
  
     _traceArea = (struct traceArea_t*) new char[traceAreaSize];     _traceArea = (struct traceArea_t*) new char[traceAreaSize];
  
Line 264 
Line 259 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void TraceMemoryHandler::dumpTraceBuffer(const char* filename) void TraceMemoryHandler::dumpTraceBuffer(const char* filename)
 { {
       if (!filename)
       {
           // if the file name is empty/NULL pointer do nothing
           return;
       }
   #ifdef PEGASUS_DEBUG
     cerr << "Number of lock contentions is <"<< _contentionCount.get()     cerr << "Number of lock contentions is <"<< _contentionCount.get()
          << ">" << endl;          << ">" << endl;
     cerr << "Number of obtained locks is <"<< _numberOfLocksObtained     cerr << "Number of obtained locks is <"<< _numberOfLocksObtained
          << ">" << endl;          << ">" << endl;
   #endif
  
     ofstream ofile(filename,ios::app&ios::out);     ofstream ofile(filename,ios::app&ios::out);
     if( ofile.good() )     if( ofile.good() )
Line 340 
Line 342 
         return;         return;
     }     }
  
   
       // If the trace memory is not initialized.
       if(!_traceArea)
       {
           _initializeTraceArea();
       }
   
     Uint32 msgStart =  _traceArea->nextPos;     Uint32 msgStart =  _traceArea->nextPos;
     // Handle the static part of the message     // Handle the static part of the message
     _appendSimpleMessage(message, msgLen);     _appendSimpleMessage(message, msgLen);
Line 522 
Line 531 
         return;         return;
     }     }
  
       // If the trace memory is not initialized.
       if(!_traceArea)
       {
           _initializeTraceArea();
       }
   
     // We include the terminating 0 in the message for easier handling     // We include the terminating 0 in the message for easier handling
     msgLen++;     msgLen++;
  
Line 537 
Line 552 
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //  Checks if a given message file is usable  
 ////////////////////////////////////////////////////////////////////////////////  
 Boolean TraceMemoryHandler::isValidMessageDestination(const char* traceFileName)  
 {  
     TraceFileHandler traceFileHandler;  
   
     return traceFileHandler.isValidMessageDestination( traceFileName );  
 }  
   
   
 ////////////////////////////////////////////////////////////////////////////////  
 //  Sets the message file in case we need to flush out the trace  
 ////////////////////////////////////////////////////////////////////////////////  
 Uint32 TraceMemoryHandler::setMessageDestination(const char* destination)  
 {  
     delete[] _traceFileName;  
   
     _traceFileName = new char[strlen(destination)+1];  
     strcpy(_traceFileName, destination);  
   
     return 0;  
 }  
   
 ////////////////////////////////////////////////////////////////////////////////  
 //  Flushes the trace //  Flushes the trace
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void TraceMemoryHandler::flushTrace() void TraceMemoryHandler::flushTrace()
 { {
     dumpTraceBuffer(_traceFileName);      dumpTraceBuffer((const char*)Tracer::_getInstance()
                             ->_traceFile.getCString());
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2