Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/pauldt/projects/IDEA/IDEA-ALL/IDEA-DEV/Core/Utilities/Includes/Trace.hh

Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 //     File: $Source: /home/cvs/ISG-Repository/IDEA-DEV/Core/Utilities/Includes/Trace.hh,v $
00003 //      Tag: $Name: DR_01_11_06 $
00004 //      CVS: $Id: Trace.hh,v 1.13 2005/12/30 22:06:06 rijsman Exp $
00005 //     Info: $CVSROOT/Idea3/Copyright.txt
00006 #ifndef _H_IDEA_TRACE
00007 #define _H_IDEA_TRACE
00008 
00009 #include "Singleton.hh"
00010 #include <sstream>
00011 #include "TimeBasics.hh"
00012 #include "ThreadTools.hh"
00013 
00017 #define TRACE_LOCKING_ON 
00018    
00024 namespace IDEA 
00025 {
00033   class Trace:
00034     public Singleton<Trace>
00035   {
00036     friend class Singleton<Trace>;
00037   public:
00041     enum OutputLevel
00042       {
00043         LOW = 0, /*< Low output, low output mode only traces low output */
00044         MEDIUM, /*< Medium output, medium output traces low and medium output */
00045         HIGH, /*< High output, medium output traces low, medium and high output */
00046         DEBUG /*< Debug output, medium output traces low, medium, high and debug output */
00047       };
00048 
00052     ~Trace() {}
00056     void setStream( std::ostream* stream ) { ACE_Guard< RecursiveThreadMutex > guard( m_Mutex ); m_Stream = stream; };
00060     std::ostream& getStream() { return *m_Stream; }
00064     RecursiveThreadMutex& getMutex() { return m_Mutex; }
00068     bool isOutputLevelLow() const { return LOW == m_OutputLevel; }
00072     bool isOutputLevelMedium() const { return MEDIUM == m_OutputLevel; }
00076     bool isOutputLevelHigh() const { return HIGH == m_OutputLevel; }
00080     bool isOutputLevelDebug() const { return DEBUG == m_OutputLevel; }
00084     void setOutputLevel( OutputLevel level ) { m_OutputLevel = level; }
00085   private:
00089     Trace():
00090       m_Stream( &std::cout ),
00091       m_OutputLevel( LOW ) 
00092     {
00093     }
00094 
00095     std::ostream* m_Stream;
00096     OutputLevel m_OutputLevel;
00097     RecursiveThreadMutex m_Mutex;
00098   };
00099 
00100   std::ostream& operator<<( std::ostream& os, const Trace::OutputLevel& level );
00101   
00107   extern Time getElapsedTime();
00113   extern Time getCurrentTime();
00119   extern Time getCurrentTick();
00125   extern const std::string& getAgentName();
00126 } // namespace IDEA
00127 
00128 #ifdef TRACE_LOCKING_ON  
00129 
00132 #define LOCK_OUTPUT   \
00133   IDEA::Guard< IDEA::RecursiveThreadMutex > guard( IDEA::Trace::instance()->getMutex(), "TraceLock"); 
00134 #else
00135  #define LOCK_OUTPUT {}
00136 #endif 
00137 
00138 // There are four levels of tracing:
00139 //
00140 // - low, use LOW_TRACE(..) and LOW_TRACE_ON to explicitly turn on in the code
00141 // - medium, use MEDIUM_TRACE(...) and MEDIUM_TRACE_ON to explicitly turn on in the code
00142 // - high, use HIGH_TRACE(...) and HIGH_TRACE_ON to explicitly turn on in the code
00143 // - debug, use DEBUG_TRACE(...) and DEBUG_TRACE_ON to explicitly turn on in the code
00144 //
00145 // Then there is also the possibility to trace without a prefix (time-stamp) by invoking 
00146 //
00147 // \li LOW_TRACE_NO_TIME_STAMP(..), for low output
00148 // \li MEDIUM_TRACE_NO_TIME_STAMP(..), for medium output
00149 // \li HIGH_TRACE_NO_TIME_STAMP(..), for high output
00150 // \li DEBUG_TRACE_NO_TIME_STAMP(..), for debug output
00151 //
00152 // If output is low only low output will be traced
00153 // If output is medium, low and medium output will be traced
00154 // If output is high, low, medium and high output will be traced
00155 // If output is debug, low, medium, high and debug output will be traced
00156 
00157 #ifdef TRACE_ON
00158 
00162 #define IDEA_TRACE( msg ) \
00163  { \
00164    LOCK_OUTPUT; \
00165    IDEA::Trace::instance()->getStream() << "[ " << IDEA::getAgentName().c_str() << " " \
00166                  << IDEA::ThreadNames::instance()->getName() << " " \
00167                  << IDEA::getElapsedTime() << " " \
00168                  << IDEA::getCurrentTime() << " " \
00169                  << IDEA::getCurrentTick() << " ] " \
00170                  << msg << std::endl; \
00171   } 
00172 
00177 #define IDEA_TRACE_NO_TIME_STAMP( msg ) \
00178  { \
00179    LOCK_OUTPUT; \
00180    IDEA::Trace::instance()->getStream() << msg << std::endl; \
00181  } 
00182 
00186  #define DEBUG_TRACE_ON IDEA::Trace::instance()->setOutputLevel( IDEA::Trace::DEBUG );
00187 
00190  #define HIGH_TRACE_ON IDEA::Trace::instance()->setOutputLevel( IDEA::Trace::HIGH );
00191 
00194  #define MEDIUM_TRACE_ON IDEA::Trace::instance()->setOutputLevel( IDEA::Trace::MEDIUM );
00195 
00198  #define LOW_TRACE_ON IDEA::Trace::instance()->setOutputLevel( IDEA::Trace::LOW );
00199 
00202  #define DEBUG_TRACE( msg ) if( IDEA::Trace::instance()->isOutputLevelDebug() ) IDEA_TRACE( msg ); 
00203 
00206  #define HIGH_TRACE( msg ) if( IDEA::Trace::instance()->isOutputLevelHigh() || IDEA::Trace::instance()->isOutputLevelDebug() ) IDEA_TRACE( msg ); 
00207 
00210  #define MEDIUM_TRACE( msg ) if( !IDEA::Trace::instance()->isOutputLevelLow() ) IDEA_TRACE( msg ); 
00211 
00214  #define LOW_TRACE( msg ) IDEA_TRACE( msg )
00215 
00218  #define DEBUG_TRACE_NO_TIME_STAMP( msg ) if( IDEA::Trace::instance()->isOutputLevelDebug() ) IDEA_TRACE_NO_TIME_STAMP( msg ); 
00219 
00222  #define HIGH_TRACE_NO_TIME_STAMP( msg ) if( IDEA::Trace::instance()->isOutputLevelHigh() || IDEA::Trace::instance()->isOutputLevelDebug() ) IDEA_TRACE_NO_TIME_STAMP( msg ); 
00223 
00226  #define MEDIUM_TRACE_NO_TIME_STAMP( msg ) if( !IDEA::Trace::instance()->isOutputLevelLow() ) IDEA_TRACE_NO_TIME_STAMP( msg ); 
00227 
00230  #define LOW_TRACE_NO_TIME_STAMP( msg ) IDEA_TRACE_NO_TIME_STAMP( msg )
00231 
00236  #define DET_TRACE( msg ) MEDIUM_TRACE( msg )
00237 
00241  #define DET_TRACE_NO_TIME_STAMP( msg ) MEDIUM_TRACE_NO_TIME_STAMP( msg )
00242 
00246  #define trace( msg ) LOW_TRACE( msg )
00247 
00251  #define trace_no_time_stamp( msg ) LOW_TRACE_NO_TIME_STAMP( msg )
00252 
00253 #else  
00254  #define IDEA_TRACE( msg ) 
00255  #define IDEA_TRACE_NO_TIME_STAMP( msg ) 
00256 
00257  #define DEBUG_TRACE_ON 
00258  #define HIGH_TRACE_ON 
00259  #define MEDIUM_TRACE_ON 
00260  #define LOW_TRACE_ON 
00261 
00262  #define DEBUG_TRACE( msg )
00263  #define HIGH_TRACE( msg ) {}
00264  #define LOW_TRACE( msg ) {}
00265  #define MEDIUM_TRACE( msg ) {}
00266 
00267  #define DEBUG_TRACE_NO_TIME_STAMP( msg ) {}
00268  #define HIGH_TRACE_NO_TIME_STAMP( msg ) {}
00269  #define MEDIUM_TRACE_NO_TIME_STAMP( msg ) {}
00270  #define LOW_TRACE_NO_TIME_STAMP( msg ) {}
00271 
00272  #define DET_TRACE( msg ) {}
00273  #define DET_TRACE_NO_TIME_STAMP( msg ) {}
00274  #define trace( msg ) {}
00275  #define trace_no_time_stamp( msg ) {}
00276 
00277 #endif // TRACE_ON
00278 
00283 #endif //_H_IDEA_TRACE

Contact information
© IDEA
Generated on Fri Feb 3 17:09:41 2006 for IDEA.