Metrics_Cache_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file Metrics_Cache_T.h
00006  *
00007  * Metrics_Cache_T.h,v 4.6 2005/10/28 16:14:53 ossama Exp
00008  *
00009  * @author Chris Gill <cdgill@cse.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef ACE_METRICS_CACHE_T_H
00015 #define ACE_METRICS_CACHE_T_H
00016 
00017 #include "ace/config-all.h"
00018 
00019 // helpful macro definitions
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/Timeprobe.h"
00027 #include "ace/Timeprobe_T.h"
00028 
00029 // Defaults for initializing timeprobes and timeprobe arays.
00030 #define METRICS_MIN_TIMEPROBE_TABLE_SIZE 256 * 4
00031 #define METRICS_MAX_TIMEPROBE_TABLE_SIZE 256 * 256
00032 #define METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE METRICS_MIN_TIMEPROBE_TABLE_SIZE
00033 #define METRICS_DEFAULT_TIMEPROBE_COUNT 6
00034 
00035 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00036 
00037 /**
00038  * @class ACE_Metrics_Timeprobe
00039  *
00040  * @brief This class implements a timeprobe for use in a Metrics framework.
00041  *
00042  * This class provides a probe for specific thread and method call
00043  * metrics timing points.
00044  */
00045 template <class ACE_LOCK, class ALLOCATOR>
00046 class ACE_Metrics_Timeprobe :
00047   public ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR>
00048   {
00049 public:
00050 
00051   typedef ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>
00052           ACE_METRICS_TIMEPROBE_TYPE;
00053 
00054   typedef ACE_timeprobe_t ACE_METRICS_TIMEPROBE_DATA_TYPE;
00055   typedef ACE_METRICS_TIMEPROBE_TYPE* ACE_METRICS_TIMEPROBE_BASED_PTR_TYPE;
00056   typedef char* ACE_METRICS_NAME_BASED_PTR_TYPE;
00057 
00058   // Enumerated timeprobe event types.
00059   enum event_id
00060   {
00061     WORK_START = 0,
00062     WORK_STOP = 1,
00063     WORK_SUSPEND = 2,
00064     WORK_RESUME = 3
00065   };
00066 
00067   // Default constructor: plugs in the above event descriptions.
00068   ACE_Metrics_Timeprobe (u_int id = 0,
00069                          const char *name = 0,
00070                          u_long size = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE);
00071 
00072   // Constructor with allocator: plugs in the above event descriptions.
00073   ACE_Metrics_Timeprobe (ALLOCATOR *allocatorPtr,
00074                          u_int id = 0,
00075                          const char *name = 0,
00076                          u_long size = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE);
00077 
00078   // Destructor.
00079   virtual ~ACE_Metrics_Timeprobe ();
00080 
00081   // Returns true if a timeprobe event matches the passed id.
00082   int is_event (const ACE_METRICS_TIMEPROBE_DATA_TYPE &t,
00083                 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::event_id id);
00084 
00085   // Accessor and mutator for probe name.
00086   const char * probe_name (void);
00087   void probe_name (char * name);
00088 
00089   // Accessor for probe id.
00090   u_int probe_id (void);
00091 
00092   // Mutator for probe id.
00093   void probe_id (u_int id);
00094 
00095   // Flush the ACE metrics timeprobe into shared memory.
00096   void flush_ACE_Metrics_Timeprobe ();
00097 
00098 protected:
00099 
00100   // Identifier for the timeprobe.
00101   u_int id_;
00102 
00103   // Name of the timeprobe.
00104   char* name_;
00105 
00106 private:
00107 
00108   // Declare but do not define.
00109   ACE_Metrics_Timeprobe (const ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> &);
00110   void operator =(const ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> &);
00111 };
00112 
00113 /**
00114  * @class ACE_Metrics_Cache
00115  *
00116  * @brief This class implements a cache for metrics timeprobe data.
00117  *
00118  *   This class allows probes to be recorded into a single cache that
00119  *   monitors and other higher level metrics classes can query.
00120  */
00121 template <class ACE_LOCK, class ALLOCATOR>
00122 class ACE_Metrics_Cache
00123 {
00124 public:
00125 
00126   typedef ACE_Metrics_Cache <ACE_LOCK, ALLOCATOR> ACE_METRICS_CACHE_TYPE;
00127 
00128   // Default constructor.
00129   ACE_Metrics_Cache (u_long table_size
00130                        = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE,
00131                      u_long number_of_probes
00132                        = METRICS_DEFAULT_TIMEPROBE_COUNT,
00133                      ALLOCATOR * allocatorPtr = (ALLOCATOR*)ALLOCATOR::instance());
00134 
00135   // Destructor.
00136   ~ACE_Metrics_Cache ();
00137 
00138   // = Dispatching metrics.
00139 
00140   // Report start, stop, suspend, and resume times of a dispatch
00141   // enqueue: stores data metrics on the supplier side.
00142   void report_enqueue_start (u_long i);
00143   void report_enqueue_stop (u_long i);
00144   void report_enqueue_suspend (u_long i);
00145   void report_enqueue_resume (u_long i);
00146 
00147   // Report start, stop, suspend, and resume times of a dispatch
00148   // dequeue: stores data metrics on the supplier side..
00149   void report_dequeue_start (u_long i);
00150   void report_dequeue_stop (u_long i);
00151   void report_dequeue_suspend (u_long i);
00152   void report_dequeue_resume (u_long i);
00153 
00154   // Reset the metrics data on the consumer side.
00155   void reset_base_statistics ();
00156 
00157   // Flips the supplier and consumer sides.
00158   void flip_supplier_and_consumer ();
00159 
00160   // Flush the ACE metrics cache into shared memory.
00161   void flush_ACE_Metrics_Cache ();
00162 
00163   // Set the enable state for metrics collection.
00164   void metrics_enabled(int enabled);
00165 
00166   // Return the enable state for metrics collection.
00167   int metrics_enabled(void) const;
00168 
00169 protected:
00170 
00171   // Obtain an allocator pointer correctly thunked for the current
00172   // address space.  If there is no allocator stored in the instance,
00173   // the singleton allocator in the current process is used.
00174   ALLOCATOR * allocator (void);
00175 
00176   // = Implementation members.
00177 
00178   // Number of probes in each supplier/consumer set.
00179   u_long probe_set_size_;
00180 
00181   // Probe data counts for each supplier/consumer set.
00182   u_long * enqueue_count_ [2];
00183   u_long * dequeue_count_ [2];
00184 
00185   // Probes for each supplier/consumer set.
00186   ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> ** enqueue_probes_ [2];
00187   ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> ** dequeue_probes_ [2];
00188 
00189   // Names for the probes.
00190   char ** enqueue_names_;
00191   char ** dequeue_names_;
00192 
00193   // Index from which probe events are being consumed.
00194   // for WSOA, it's the data being sent to the logger
00195   int consumer_index_;
00196 
00197   // Index to which probe events are being supplied.
00198   // for WSOA, it's the data being recorded from the probes
00199   int supplier_index_;
00200 
00201   // Size of the timestamp table in each probe.
00202   u_long table_size_;
00203 
00204   // Interval start and stop timestamps.
00205   ACE_Time_Value interval_start_;
00206 
00207   // Interval start and stop timestamps.
00208   ACE_Time_Value interval_end_;
00209 
00210   // Flag to indicate whether or not start time of interval has been
00211   // initialized since the last reset.
00212   int interval_initialized_;
00213 
00214   // Indicator of whether metrics is enabled.
00215   int metrics_enabled_;
00216 
00217 private:
00218 
00219   // Allocation strategy object.
00220   ALLOCATOR* allocator_;
00221 
00222   // Declare but do not define.
00223   ACE_Metrics_Cache (const ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR> &);
00224   void operator = (const ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR> &);
00225 };
00226 
00227 ACE_END_VERSIONED_NAMESPACE_DECL
00228 
00229 #if defined (__ACE_INLINE__)
00230 #include "ace/Metrics_Cache_T.inl"
00231 #endif /* __ACE_INLINE__ */
00232 
00233 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00234 #include "ace/Metrics_Cache_T.cpp"
00235 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00236 
00237 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00238 #pragma implementation ("Metrics_Cache_T.cpp")
00239 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00240 
00241 #endif /* defined (ACE_COMPILE_TIMEPROBES) */
00242 
00243 #endif /* ACE_METRICS_CACHE_T_H */

Generated on Thu Nov 9 09:41:56 2006 for ACE by doxygen 1.3.6