Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / ACE / ace / Metrics_Cache_T.cpp
bloba9967e460acd456d02bb0b1c77029ee5828a7460
1 #ifndef ACE_METRICS_CACHE_CPP
2 #define ACE_METRICS_CACHE_CPP
4 #include "ace/Metrics_Cache_T.h"
6 #if defined (ACE_COMPILE_TIMEPROBES)
8 #include "ace/Metrics_Cache.h"
10 #if !defined (__ACE_INLINE__)
11 #include "ace/Metrics_Cache_T.inl"
12 #endif /* __ACE_INLINE__ */
14 /// Const strings for timeprobe event type descriptions.
15 static const char * event_description_strings [] =
17 "start",
18 "stop",
19 "suspend",
20 "resume"
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
25 /////////////////////////////////
26 // class ACE_Metrics_Timeprobe //
27 /////////////////////////////////
29 template <class ACE_LOCK, class ALLOCATOR>
30 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::ACE_Metrics_Timeprobe (u_int id,
31 const char *name,
32 u_long size)
34 ACE_Timeprobe<ACE_LOCK> (size),
35 id_ (id),
36 name_ (0)
38 if (name == 0)
40 name = "";
43 char * name_tmp = 0;
44 ACE_NEW_MALLOC_ARRAY (name_tmp,
45 (char *) this->allocator ()->malloc (ACE_OS::strlen(name)+1),
46 char,
47 ACE_OS::strlen(name)+1);
48 ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
49 name_ = name_tmp;
51 this->event_descriptions (event_description_strings,
52 sizeof(event_description_strings)/sizeof(const char *));
55 template <class ACE_LOCK, class ALLOCATOR>
56 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
57 ACE_Metrics_Timeprobe (ALLOCATOR *alloc,
58 u_int id,
59 const char *name,
60 u_long size)
61 : ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR> (size),
62 id_ (id),
63 name_ (0)
65 if (name == 0)
67 name = "";
70 char * name_tmp = 0;
71 ACE_NEW_MALLOC_ARRAY (name_tmp,
72 (char *) alloc->malloc(ACE_OS::strlen(name)+1),
73 char,
74 ACE_OS::strlen(name)+1);
75 ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
76 name_ = name_tmp;
78 this->event_descriptions (event_description_strings,
79 sizeof(event_description_strings)/sizeof(const char *));
82 template <class ACE_LOCK, class ALLOCATOR>
83 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Timeprobe ()
85 if (name_)
87 this->allocator ()->free ((void*) name_);
92 // Returns true if a timeprobe matches the passed id.
94 template <class ACE_LOCK, class ALLOCATOR>
95 int
96 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::is_event (const ACE_Metrics_Timeprobe<ACE_LOCK,
97 ALLOCATOR>::
98 ACE_METRICS_TIMEPROBE_DATA_TYPE &t,
99 ACE_Metrics_Timeprobe<ACE_LOCK,
100 ALLOCATOR>::
101 event_id id)
103 return (t.event_.event_number_ == (u_long) id) ? 1 : 0;
106 template <class ACE_LOCK, class ALLOCATOR>
107 const char *
108 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name ()
110 return name_;
113 template <class ACE_LOCK, class ALLOCATOR>
114 void
115 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (char * name)
117 char * name_tmp = 0;
118 ACE_NEW_MALLOC_ARRAY (name_tmp,
119 (char *) this->allocator ()->malloc (ACE_OS::strlen(name)+1),
120 char,
121 ACE_OS::strlen(name)+1);
122 ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
124 if (name_)
126 this->allocator ()->free (name_);
129 name_ = name_tmp;
132 template <class ACE_LOCK, class ALLOCATOR>
133 u_int
134 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id ()
136 return id_;
140 template <class ACE_LOCK, class ALLOCATOR>
141 void
142 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (u_int id)
144 id_ = id;
148 // Flush the ACE metrics timeprobe into shared memory.
150 template <class ACE_LOCK, class ALLOCATOR> void
151 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
152 flush_ACE_Metrics_Timeprobe ()
157 /////////////////////////////
158 // Class ACE_Metrics_Cache //
159 /////////////////////////////
162 // Constructor.
164 template <class ACE_LOCK, class ALLOCATOR>
165 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
166 ACE_Metrics_Cache (u_long table_size,
167 u_long,
168 ALLOCATOR *alloc)
169 : probe_set_size_ (0),
170 enqueue_names_ (0),
171 dequeue_names_ (0),
172 consumer_index_ (0),
173 supplier_index_ (1),
174 table_size_ (table_size),
175 interval_start_ (ACE_Time_Value::zero),
176 interval_end_ (ACE_Time_Value::zero),
177 interval_initialized_ (0),
178 metrics_enabled_(1),
179 allocator_ (alloc)
181 // Initialize probe and count arrays.
183 // Ensure that the high res timer global scale factor
184 // is set before any of its static methods are used
185 ACE_High_Res_Timer::global_scale_factor ();
187 enqueue_count_ [0] = 0;
188 enqueue_count_ [1] = 0;
189 dequeue_count_ [0] = 0;
190 dequeue_count_ [1] = 0;
191 enqueue_probes_ [0] = 0;
192 enqueue_probes_ [1] = 0;
193 dequeue_probes_ [0] = 0;
194 dequeue_probes_ [1] = 0;
197 // Destructor.
199 template <class ACE_LOCK, class ALLOCATOR>
200 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Cache ()
204 // Obtain an allocator pointer correctly thunked for the current
205 // address space. If there is no allocator stored in the instance,
206 // the singleton allocator in the current process is used.
208 template <class ACE_LOCK, class ALLOCATOR> ALLOCATOR *
209 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::allocator ()
211 ALLOCATOR * alloc = allocator_;
212 return alloc
213 ? alloc
214 : ACE_Singleton<ALLOCATOR, ACE_LOCK>::instance ();
218 // Flush the ACE metrics cache into shared memory.
220 template <class ACE_LOCK, class ALLOCATOR> void
221 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
222 flush_ACE_Metrics_Cache ()
226 ACE_END_VERSIONED_NAMESPACE_DECL
228 #endif /* defined (ACE_COMPILE_TIMEPROBES) */
230 #endif /* ACE_METRICS_CACHE_CPP */