Timeprobe_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Timeprobe_T.h
00006  *
00007  *  Timeprobe_T.h,v 4.26 2005/10/28 23:55:10 ossama Exp
00008  *
00009  *  @author Irfan Pyarali
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef ACE_TIMEPROBE_T_H
00015 #define ACE_TIMEPROBE_T_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/config-all.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if defined (ACE_COMPILE_TIMEPROBES)
00025 
00026 #include "ace/Unbounded_Set.h"
00027 
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 /**
00031  * @class ACE_Timeprobe_Ex
00032  *
00033  * @brief This class is used to instrument code.  This is accomplished
00034  * by inserting time probes at different location in the code.
00035  * ACE_Timeprobe then measures the time difference between two
00036  * time probes.
00037  *
00038  * This class provides a lightweight implementation for
00039  * measuring the time required to execute code between two time
00040  * probes.  When a time probe executes, it records the time, the
00041  * id of the calling thread, and an event description.  The
00042  * event description can either be an unsigned long or a string
00043  * (char *). If string are used, care must be taken cause only
00044  * pointer copies are done and the string data is *not* copied.
00045  * The recorded time probes can then be printed by calling
00046  * <print_times>.  If you have used unsigned longs as event
00047  * descriptions in any of your time probes, you must have
00048  * provided an event description table that maps the unsigned
00049  * longs to readable strings.  This map is a simple array of
00050  * strings, and the event number is used as the index into the
00051  * array when looking for the event description.  If you have
00052  * only used strings for the event description, this map is not
00053  * necessary.
00054  * Multiple maps can also be used to chunk up the time probes.
00055  * Each one can be added by calling <event_descriptions>.
00056  * Different tables are used internally by consulting the
00057  * minimum_id for each table.  It is up to the user to make sure
00058  * that multiple tables do not share the same event id range.
00059  */
00060 template <class ACE_LOCK, class ALLOCATOR>
00061 class ACE_Timeprobe_Ex
00062 {
00063 public:
00064 
00065   /// Self
00066   typedef ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR>
00067           SELF;
00068 
00069   /**
00070    * ACE_Timeprobe
00071    */
00072   typedef ACE_Timeprobe_Ex <ACE_LOCK, ACE_Allocator> ACE_Timeprobe;
00073 
00074 
00075   /// We can hold multiple event description tables.
00076   typedef ACE_Unbounded_Set<ACE_Event_Descriptions>
00077           EVENT_DESCRIPTIONS;
00078 
00079   /// Create Timeprobes with @a size slots
00080   ACE_Timeprobe_Ex (u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
00081 
00082   /// Create Timeprobes with @a size slots
00083   ACE_Timeprobe_Ex (ALLOCATOR *allocator,
00084                  u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
00085   /// Destructor.
00086   ~ACE_Timeprobe_Ex (void);
00087 
00088   /// Record a time. @a event is used to describe this time probe.
00089   void timeprobe (u_long event);
00090 
00091   /// Record a time. @a id is used to describe this time probe.
00092   void timeprobe (const char *id);
00093 
00094   /// Record event descriptions.
00095   int event_descriptions (const char **descriptions,
00096                           u_long minimum_id);
00097 
00098   /// Print the time probes.
00099   void print_times (void);
00100 
00101   /// Print the time probes.
00102   void print_absolute_times (void);
00103 
00104   /// Reset the slots.  All old time probes will be lost.
00105   void reset (void);
00106 
00107   void increase_size (u_long size);
00108 
00109   /// Not implemented (stupid MSVC won't let it be protected).
00110   ACE_Timeprobe_Ex (const ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR> &);
00111 
00112   // = (Somewhat private) Accessors
00113 
00114   /// Event Descriptions
00115   ACE_Unbounded_Set<ACE_Event_Descriptions> &event_descriptions (void);
00116 
00117   /// Sorted Event Descriptions.
00118   ACE_Unbounded_Set<ACE_Event_Descriptions> &sorted_event_descriptions (void);
00119 
00120   /// Find description of event <i>
00121   const char *find_description_i (u_long i);
00122 
00123   /// Sort event descriptions
00124   void sort_event_descriptions_i (void);
00125 
00126   /// Time probe slots
00127   ACE_timeprobe_t *timeprobes (void);
00128 
00129   /// Synchronization variable.
00130   ACE_LOCK &lock (void);
00131 
00132   /// Max size of timestamp table
00133   u_long max_size (void);
00134 
00135   /// Current size of timestamp table
00136   u_long current_size (void);
00137 
00138 protected:
00139 
00140   /// Obtain an allocator pointer.  If there is no allocator stored in
00141   /// the instance, the singleton allocator in the current process is used.
00142   ALLOCATOR * allocator (void);
00143 
00144   /// Event Descriptions
00145   EVENT_DESCRIPTIONS event_descriptions_;
00146 
00147   /// Sorted Event Descriptions.
00148   EVENT_DESCRIPTIONS sorted_event_descriptions_;
00149 
00150   /// Time probe slots
00151   ACE_timeprobe_t *timeprobes_;
00152 
00153   /// Synchronization variable.
00154   ACE_LOCK lock_;
00155 
00156   /// Max size of timestamp table
00157   u_long max_size_;
00158 
00159   /// Current size of timestamp table
00160   u_long current_size_;
00161 
00162   /// Flag indicating the report buffer has filled up, and is now
00163   /// acting as a ring-buffer using modulus arithmetic: this saves the
00164   /// max_size_ most recent time stamps and loses earlier ones until
00165   /// drained.
00166   u_short report_buffer_full_;
00167 
00168 
00169 private:
00170    ALLOCATOR *   allocator_;
00171 };
00172 
00173 // template <class ACE_LOCK>
00174 // class ACE_Timeprobe : public ACE_Timeprobe_Ex <ACE_LOCK, ACE_Allocator>
00175 // {
00176 // public:
00177 //   // Initialize a ACE_Timeprobe with default size
00178 //   ACE_Timeprobe (ACE_Allocator *allocator = ACE_Allocator::instance());
00179 
00180 //   /// Create Timeprobes with <size> slots
00181 //   ACE_Timeprobe (ACE_Allocator *allocator = ACE_Allocator::instance(),
00182 //                  u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
00183 // };
00184 
00185 /**
00186  * @class ACE_Function_Timeprobe
00187  *
00188  * @brief Auto pointer like time probes. It will record <event> on
00189  * construction and <event + 1> on destruction.
00190  */
00191 template <class Timeprobe>
00192 class ACE_Function_Timeprobe
00193 {
00194 public:
00195   /// Constructor.
00196   ACE_Function_Timeprobe (Timeprobe &timeprobe,
00197                           u_long event);
00198 
00199   /// Destructor.
00200   ~ACE_Function_Timeprobe (void);
00201 
00202 protected:
00203   /// Reference to timeprobe.
00204   Timeprobe &timeprobe_;
00205 
00206   /// Event.
00207   u_long event_;
00208 };
00209 
00210 ACE_END_VERSIONED_NAMESPACE_DECL
00211 
00212 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00213 #include "ace/Timeprobe_T.cpp"
00214 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00215 
00216 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00217 #pragma implementation ("Timeprobe_T.cpp")
00218 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00219 
00220 #endif /* ACE_COMPILE_TIMEPROBES */
00221 #include /**/ "ace/post.h"
00222 #endif /* ACE_TIMEPROBE_T_H */

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