Metrics_Cache_T.cpp

Go to the documentation of this file.
00001 // $Id: Metrics_Cache_T.cpp 80826 2008-03-04 14:51:23Z wotte $
00002 
00003 #ifndef ACE_METRICS_CACHE_CPP
00004 #define ACE_METRICS_CACHE_CPP
00005 
00006 //#define ACE_BUILD_DLL
00007 
00008 #include "ace/Metrics_Cache_T.h"
00009 
00010 #if defined (ACE_COMPILE_TIMEPROBES)
00011 
00012 #include "ace/Metrics_Cache.h"
00013 
00014 #if !defined (__ACE_INLINE__)
00015 #include "ace/Metrics_Cache_T.inl"
00016 #endif /* __ACE_INLINE__ */
00017 
00018 // Const strings for timeprobe event type descriptions.
00019 
00020 static const char * event_description_strings [] =
00021 {
00022   "start",
00023   "stop",
00024   "suspend",
00025   "resume"
00026 };
00027 
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029 
00030 /////////////////////////////////
00031 // class ACE_Metrics_Timeprobe //
00032 /////////////////////////////////
00033 
00034 template <class ACE_LOCK, class ALLOCATOR>
00035 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::ACE_Metrics_Timeprobe (u_int id,
00036                                                                    const char *name,
00037                                                                    u_long size)
00038   :
00039     ACE_Timeprobe<ACE_LOCK> (size),
00040     id_ (id),
00041     name_ (0)
00042 {
00043   if (name == 0)
00044     {
00045       name = "";
00046     }
00047 
00048   char * name_tmp = 0;
00049   ACE_NEW_MALLOC_ARRAY (name_tmp,
00050                         (char *) this->allocator ()->malloc (ACE_OS::strlen(name)+1),
00051                         char,
00052                         ACE_OS::strlen(name)+1);
00053   ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
00054   name_ = name_tmp;
00055 
00056   this->event_descriptions (event_description_strings,
00057                             sizeof(event_description_strings)/sizeof(const char *));
00058 }
00059 
00060 template <class ACE_LOCK, class ALLOCATOR>
00061 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
00062 ACE_Metrics_Timeprobe (ALLOCATOR *alloc,
00063                        u_int id,
00064                        const char *name,
00065                        u_long size)
00066   : ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR> (size),
00067     id_ (id),
00068     name_ (0)
00069 {
00070   if (name == 0)
00071     {
00072       name = "";
00073     }
00074 
00075   char * name_tmp = 0;
00076   ACE_NEW_MALLOC_ARRAY (name_tmp,
00077                         (char *) alloc->malloc(ACE_OS::strlen(name)+1),
00078                         char,
00079                         ACE_OS::strlen(name)+1);
00080   ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
00081   name_ = name_tmp;
00082 
00083   this->event_descriptions (event_description_strings,
00084                             sizeof(event_description_strings)/sizeof(const char *));
00085 }
00086 
00087 template <class ACE_LOCK, class ALLOCATOR>
00088 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Timeprobe ()
00089 {
00090    if (name_)
00091     {
00092          this->allocator ()->free ((void*) name_);
00093     }
00094 }
00095 
00096 
00097 // Returns true if a timeprobe matches the passed id.
00098 
00099 template <class ACE_LOCK, class ALLOCATOR>
00100 int
00101 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::is_event (const ACE_Metrics_Timeprobe<ACE_LOCK,
00102                                                       ALLOCATOR>::
00103                                                       ACE_METRICS_TIMEPROBE_DATA_TYPE &t,
00104                                                       ACE_Metrics_Timeprobe<ACE_LOCK,
00105                                                       ALLOCATOR>::
00106                                                       event_id id)
00107 {
00108   return (t.event_.event_number_ ==  (u_long) id) ? 1 : 0;
00109 }
00110 
00111 template <class ACE_LOCK, class ALLOCATOR>
00112 const char *
00113 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (void)
00114 {
00115    return name_;
00116 }
00117 
00118 template <class ACE_LOCK, class ALLOCATOR>
00119 void
00120 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (char * name)
00121 {
00122   char * name_tmp = 0;
00123   ACE_NEW_MALLOC_ARRAY (name_tmp,
00124                         (char *) this->allocator ()->malloc (ACE_OS::strlen(name)+1),
00125                         char,
00126                         ACE_OS::strlen(name)+1);
00127   ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
00128 
00129   if (name_)
00130   {
00131      this->allocator ()->free (name_);
00132   }
00133 
00134   name_ = name_tmp;
00135 }
00136 
00137 template <class ACE_LOCK, class ALLOCATOR>
00138 u_int
00139 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (void)
00140 {
00141   return id_;
00142 }
00143 
00144 
00145 template <class ACE_LOCK, class ALLOCATOR>
00146 void
00147 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (u_int id)
00148 {
00149   id_ = id;
00150 }
00151 
00152 
00153 // Flush the ACE metrics timeprobe into shared memory.
00154 
00155 template <class ACE_LOCK, class ALLOCATOR> void
00156 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
00157 flush_ACE_Metrics_Timeprobe ()
00158 {
00159 }
00160 
00161 
00162 /////////////////////////////
00163 // Class ACE_Metrics_Cache //
00164 /////////////////////////////
00165 
00166 
00167 // Constructor.
00168 
00169 template <class ACE_LOCK, class ALLOCATOR>
00170 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
00171 ACE_Metrics_Cache (u_long table_size,
00172                    u_long number_of_probes,
00173                    ALLOCATOR *alloc)
00174   : probe_set_size_ (0),
00175     enqueue_names_ (0),
00176     dequeue_names_ (0),
00177     consumer_index_ (0),
00178     supplier_index_ (1),
00179     table_size_ (table_size),
00180     interval_start_ (ACE_Time_Value::zero),
00181     interval_end_ (ACE_Time_Value::zero),
00182     interval_initialized_ (0),
00183     metrics_enabled_(1),
00184     allocator_ (alloc)
00185 {
00186   ACE_UNUSED_ARG(number_of_probes);
00187   // Initialize probe and count arrays.
00188 
00189   // Ensure that the high res timer global scale factor
00190   // is set before any of its static methods are used
00191   ACE_High_Res_Timer::global_scale_factor ();
00192 
00193   enqueue_count_ [0] = 0;
00194   enqueue_count_ [1] = 0;
00195   dequeue_count_ [0] = 0;
00196   dequeue_count_ [1] = 0;
00197   enqueue_probes_ [0] = 0;
00198   enqueue_probes_ [1] = 0;
00199   dequeue_probes_ [0] = 0;
00200   dequeue_probes_ [1] = 0;
00201 }
00202 
00203 // Destructor.
00204 
00205 template <class ACE_LOCK, class ALLOCATOR>
00206 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Cache ()
00207 {
00208 }
00209 
00210 
00211 // Obtain an allocator pointer correctly thunked for the current
00212 // address space.  If there is no allocator stored in the instance,
00213 // the singleton allocator in the current process is used.
00214 
00215 template <class ACE_LOCK, class ALLOCATOR> ALLOCATOR *
00216 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::allocator (void)
00217 {
00218   ALLOCATOR * alloc = allocator_;
00219   return alloc
00220          ? alloc
00221          : ACE_Singleton<ALLOCATOR, ACE_LOCK>::instance ();
00222 }
00223 
00224 
00225 // Flush the ACE metrics cache into shared memory.
00226 
00227 template <class ACE_LOCK, class ALLOCATOR> void
00228 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
00229 flush_ACE_Metrics_Cache ()
00230 {
00231 }
00232 
00233 ACE_END_VERSIONED_NAMESPACE_DECL
00234 
00235 #endif /* defined (ACE_COMPILE_TIMEPROBES) */
00236 
00237 #endif /* ACE_METRICS_CACHE_CPP */

Generated on Tue Feb 2 17:18:40 2010 for ACE by  doxygen 1.4.7