Timeprobe.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Timeprobe.h
00006  *
00007  *  Timeprobe.h,v 4.47 2005/11/24 09:48:55 ossama Exp
00008  *
00009  *  @author Irfan Pyarali
00010  *
00011  * If users want to use time probes, the ACE_COMPILE_TIMEPROBES
00012  * flag must be defined when compiling ACE.  This can be achieved
00013  * by doing one of the following:
00014  *
00015  * . Use make probe = 1, if you are using the make utility.
00016  *
00017  * . Define ACE_COMPILE_TIMEPROBES in config.h
00018  *
00019  * . Define ACE_COMPILE_TIMEPROBES in the VC project file.
00020  *
00021  * . Other regular methods will also work.
00022  *
00023  * It is not necessary to define ACE_COMPILE_TIMEPROBES when using
00024  * time probes, you simply need ACE_ENABLE_TIMEPROBES.  You can use
00025  * the ACE_TIMEPROBE_* macros to program the time probes, and use
00026  * the ACE_ENABLE_TIMEPROBE to enable the time probes.  If you
00027  * define ACE_ENABLE_TIMEPROBE in your code, but forget to compile
00028  * ACE with ACE_COMPILE_TIMEPROBES, you will end up with linker
00029  * errors.
00030  *
00031  * Remember that ACE_COMPILE_TIMEPROBES means that the ACE library
00032  * will contain code for time probes.  This is only useful when
00033  * compiling ACE. ACE_ENABLE_TIMEPROBES means that the
00034  * ACE_TIMEPROBE_* macros should spring to life.
00035  */
00036 //=============================================================================
00037 
00038 #ifndef ACE_TIMEPROBE_H
00039 #define ACE_TIMEPROBE_H
00040 #include /**/ "ace/pre.h"
00041 
00042 #include "ace/ACE_export.h"
00043 #include "ace/Malloc_Allocator.h"
00044 
00045 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00046 # pragma once
00047 #endif /* ACE_LACKS_PRAGMA_ONCE */
00048 
00049 /* Enable ACE Timeprobes */
00050 #if defined (ACE_ENABLE_TIMEPROBES)
00051   #if !defined (ACE_COMPILE_TIMEPROBES)
00052     #define ACE_COMPILE_TIMEPROBES
00053   #endif /* ACE_COMPILE_TIMEPROBES */
00054 #endif /* ACE_ENABLE_TIMEPROBES */
00055 
00056 #if defined (ACE_COMPILE_TIMEPROBES)
00057 
00058 #include "ace/OS_NS_time.h"
00059 #include "ace/OS_NS_Thread.h"
00060 
00061 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00062 
00063 /**
00064  * @class ACE_Event_Descriptions
00065  *
00066  * @brief Event Descriptions.
00067  */
00068 class ACE_Export ACE_Event_Descriptions
00069 {
00070 public:
00071   /// Event descriptions
00072   const char **descriptions_;
00073 
00074   /// Minimum id of this description set
00075   u_long minimum_id_;
00076 
00077   /// Comparison
00078   bool operator== (const ACE_Event_Descriptions &rhs) const;
00079 };
00080 
00081 /**
00082  * @class ACE_timeprobe_t
00083  *
00084  * @brief Time probe record.
00085  */
00086 class ACE_Export ACE_timeprobe_t
00087 {
00088 public:
00089   /// Events are record as strings or numbers.
00090   union event
00091   {
00092     u_long event_number_;
00093     const char *event_description_;
00094   };
00095 
00096   /// Type of event.
00097   enum event_type
00098   {
00099     NUMBER,
00100     STRING
00101   };
00102 
00103   /// Event.
00104   event event_;
00105 
00106   /// Type of event.
00107   event_type event_type_;
00108 
00109   /// Timestamp.
00110   ACE_hrtime_t time_;
00111 
00112   /// Id of thread posting the time probe.
00113   ACE_thread_t thread_;
00114 };
00115 
00116 ACE_END_VERSIONED_NAMESPACE_DECL
00117 
00118 #if defined (__ACE_INLINE__)
00119 #include "ace/Timeprobe.inl"
00120 #endif /* __ACE_INLINE__ */
00121 
00122 #include "ace/Synch_Traits.h"
00123 #include "ace/Null_Mutex.h"
00124 #include "ace/Singleton.h"
00125 #include "ace/Timeprobe_T.h"
00126 
00127 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00128 
00129 // If ACE_MT_TIMEPROBES is defined, use a Thread_Mutex to lock the
00130 // internal state of ACE_Timerprobe.  This allows multiple threads to
00131 // use the same ACE_Timerprobe.
00132 #  if defined (ACE_MT_TIMEPROBES)
00133 typedef ACE_SYNCH_MUTEX ACE_TIMEPROBE_MUTEX;
00134 #  else /* ACE_MT_TIMEPROBES */
00135 typedef ACE_SYNCH_NULL_MUTEX ACE_TIMEPROBE_MUTEX;
00136 #  endif /* ACE_MT_TIMEPROBES */
00137 
00138 typedef ACE_New_Allocator ACE_TIMEPROBE_ALLOCATOR;
00139 
00140 typedef ACE_Timeprobe_Ex<ACE_TIMEPROBE_MUTEX, ACE_TIMEPROBE_ALLOCATOR>
00141         ACE_TIMEPROBE_WITH_LOCKING;
00142 
00143 // If ACE_TSS_TIMEPROBES is defined, store the ACE_Timeprobe singleton
00144 // in thread specific storage.  This allows multiple threads to use
00145 // their own instance of ACE_Timerprobe, without interfering with each
00146 // other.
00147 
00148 #  if defined (ACE_TSS_TIMEPROBES)
00149 #    define ACE_TIMEPROBE_SINGLETON_TYPE ACE_TSS_Singleton
00150 #    define ACE_TIMEPROBE_SINGLETON_LOCK_TYPE ACE_SYNCH_NULL_MUTEX
00151 #  else /* ACE_TSS_TIMEPROBES */
00152 #    define ACE_TIMEPROBE_SINGLETON_TYPE ACE_Singleton
00153 #    define ACE_TIMEPROBE_SINGLETON_LOCK_TYPE ACE_SYNCH_MUTEX
00154 #  endif /* ACE_TSS_TIMEPROBES */
00155 
00156 ACE_SINGLETON_DECLARE (ACE_TIMEPROBE_SINGLETON_TYPE, \
00157                        ACE_TIMEPROBE_WITH_LOCKING,   \
00158                        ACE_TIMEPROBE_SINGLETON_LOCK_TYPE)
00159 
00160 typedef ACE_TIMEPROBE_SINGLETON_TYPE<ACE_TIMEPROBE_WITH_LOCKING, ACE_TIMEPROBE_SINGLETON_LOCK_TYPE>
00161         ACE_TIMEPROBE_SINGLETON;
00162 
00163 ACE_END_VERSIONED_NAMESPACE_DECL
00164 
00165 #endif /* ACE_COMPILE_TIMEPROBES */
00166 
00167 // If ACE_ENABLE_TIMEPROBES is defined, the macros below will
00168 // work. Otherwise, they just vanish.  Using this macro, you can
00169 // control which files/libraries are probed.
00170 #if defined (ACE_ENABLE_TIMEPROBES) && defined (ACE_COMPILE_TIMEPROBES)
00171 
00172 #  define ACE_TIMEPROBE_RESET ACE_TIMEPROBE_SINGLETON::instance ()->reset ()
00173 
00174 #  define ACE_TIMEPROBE(id) ACE_TIMEPROBE_SINGLETON::instance ()->timeprobe (id)
00175 
00176 #  define ACE_TIMEPROBE_PRINT ACE_TIMEPROBE_SINGLETON::instance ()->print_times ()
00177 
00178 #  define ACE_TIMEPROBE_PRINT_ABSOLUTE ACE_TIMEPROBE_SINGLETON::instance ()->print_absolute_times ()
00179 
00180 #  define ACE_TIMEPROBE_EVENT_DESCRIPTIONS(descriptions, minimum_id) \
00181 static int ace_timeprobe_##descriptions##_return = \
00182   ACE_TIMEPROBE_SINGLETON::instance ()->event_descriptions \
00183     (descriptions, minimum_id)
00184 
00185 #  define ACE_FUNCTION_TIMEPROBE(X) \
00186   ACE_Function_Timeprobe<ACE_TIMEPROBE_WITH_LOCKING> function_timeprobe \
00187     (*ACE_TIMEPROBE_SINGLETON::instance (), X)
00188 
00189 #else /* ACE_ENABLE_TIMEPROBES && ACE_COMPILE_TIMEPROBES */
00190 
00191 #  define ACE_TIMEPROBE_RESET
00192 #  define ACE_TIMEPROBE(id)
00193 #  define ACE_TIMEPROBE_PRINT
00194 #  define ACE_TIMEPROBE_PRINT_ABSOLUTE
00195 #  define ACE_TIMEPROBE_EVENT_DESCRIPTIONS(descriptions, minimum_id)
00196 #  define ACE_FUNCTION_TIMEPROBE(X)
00197 
00198 #endif /* ACE_ENABLE_TIMEPROBES && ACE_COMPILE_TIMEPROBES */
00199 #include /**/ "ace/post.h"
00200 #endif /* ACE_TIMEPROBE_H */

Generated on Thu Nov 9 09:42:07 2006 for ACE by doxygen 1.3.6