Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Metrics_Cache_T.cpp
blobb17c85c131f15dc08efe0a368d08f092f3d37b32
1 #ifndef ACE_METRICS_CACHE_CPP
2 #define ACE_METRICS_CACHE_CPP
4 //#define ACE_BUILD_DLL
6 #include "ace/Metrics_Cache_T.h"
8 #if defined (ACE_COMPILE_TIMEPROBES)
10 #include "ace/Metrics_Cache.h"
12 #if !defined (__ACE_INLINE__)
13 #include "ace/Metrics_Cache_T.inl"
14 #endif /* __ACE_INLINE__ */
16 /// Const strings for timeprobe event type descriptions.
17 static const char * event_description_strings [] =
19 "start",
20 "stop",
21 "suspend",
22 "resume"
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 /////////////////////////////////
28 // class ACE_Metrics_Timeprobe //
29 /////////////////////////////////
31 template <class ACE_LOCK, class ALLOCATOR>
32 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::ACE_Metrics_Timeprobe (u_int id,
33 const char *name,
34 u_long size)
36 ACE_Timeprobe<ACE_LOCK> (size),
37 id_ (id),
38 name_ (0)
40 if (name == 0)
42 name = "";
45 char * name_tmp = 0;
46 ACE_NEW_MALLOC_ARRAY (name_tmp,
47 (char *) this->allocator ()->malloc (ACE_OS::strlen(name)+1),
48 char,
49 ACE_OS::strlen(name)+1);
50 ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
51 name_ = name_tmp;
53 this->event_descriptions (event_description_strings,
54 sizeof(event_description_strings)/sizeof(const char *));
57 template <class ACE_LOCK, class ALLOCATOR>
58 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
59 ACE_Metrics_Timeprobe (ALLOCATOR *alloc,
60 u_int id,
61 const char *name,
62 u_long size)
63 : ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR> (size),
64 id_ (id),
65 name_ (0)
67 if (name == 0)
69 name = "";
72 char * name_tmp = 0;
73 ACE_NEW_MALLOC_ARRAY (name_tmp,
74 (char *) alloc->malloc(ACE_OS::strlen(name)+1),
75 char,
76 ACE_OS::strlen(name)+1);
77 ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
78 name_ = name_tmp;
80 this->event_descriptions (event_description_strings,
81 sizeof(event_description_strings)/sizeof(const char *));
84 template <class ACE_LOCK, class ALLOCATOR>
85 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Timeprobe ()
87 if (name_)
89 this->allocator ()->free ((void*) name_);
94 // Returns true if a timeprobe matches the passed id.
96 template <class ACE_LOCK, class ALLOCATOR>
97 int
98 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::is_event (const ACE_Metrics_Timeprobe<ACE_LOCK,
99 ALLOCATOR>::
100 ACE_METRICS_TIMEPROBE_DATA_TYPE &t,
101 ACE_Metrics_Timeprobe<ACE_LOCK,
102 ALLOCATOR>::
103 event_id id)
105 return (t.event_.event_number_ == (u_long) id) ? 1 : 0;
108 template <class ACE_LOCK, class ALLOCATOR>
109 const char *
110 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (void)
112 return name_;
115 template <class ACE_LOCK, class ALLOCATOR>
116 void
117 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (char * name)
119 char * name_tmp = 0;
120 ACE_NEW_MALLOC_ARRAY (name_tmp,
121 (char *) this->allocator ()->malloc (ACE_OS::strlen(name)+1),
122 char,
123 ACE_OS::strlen(name)+1);
124 ACE_OS::memcpy (name_tmp, name, ACE_OS::strlen (name)+1);
126 if (name_)
128 this->allocator ()->free (name_);
131 name_ = name_tmp;
134 template <class ACE_LOCK, class ALLOCATOR>
135 u_int
136 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (void)
138 return id_;
142 template <class ACE_LOCK, class ALLOCATOR>
143 void
144 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (u_int id)
146 id_ = id;
150 // Flush the ACE metrics timeprobe into shared memory.
152 template <class ACE_LOCK, class ALLOCATOR> void
153 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
154 flush_ACE_Metrics_Timeprobe ()
159 /////////////////////////////
160 // Class ACE_Metrics_Cache //
161 /////////////////////////////
164 // Constructor.
166 template <class ACE_LOCK, class ALLOCATOR>
167 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
168 ACE_Metrics_Cache (u_long table_size,
169 u_long,
170 ALLOCATOR *alloc)
171 : probe_set_size_ (0),
172 enqueue_names_ (0),
173 dequeue_names_ (0),
174 consumer_index_ (0),
175 supplier_index_ (1),
176 table_size_ (table_size),
177 interval_start_ (ACE_Time_Value::zero),
178 interval_end_ (ACE_Time_Value::zero),
179 interval_initialized_ (0),
180 metrics_enabled_(1),
181 allocator_ (alloc)
183 // Initialize probe and count arrays.
185 // Ensure that the high res timer global scale factor
186 // is set before any of its static methods are used
187 ACE_High_Res_Timer::global_scale_factor ();
189 enqueue_count_ [0] = 0;
190 enqueue_count_ [1] = 0;
191 dequeue_count_ [0] = 0;
192 dequeue_count_ [1] = 0;
193 enqueue_probes_ [0] = 0;
194 enqueue_probes_ [1] = 0;
195 dequeue_probes_ [0] = 0;
196 dequeue_probes_ [1] = 0;
199 // Destructor.
201 template <class ACE_LOCK, class ALLOCATOR>
202 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Cache ()
206 // Obtain an allocator pointer correctly thunked for the current
207 // address space. If there is no allocator stored in the instance,
208 // the singleton allocator in the current process is used.
210 template <class ACE_LOCK, class ALLOCATOR> ALLOCATOR *
211 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::allocator (void)
213 ALLOCATOR * alloc = allocator_;
214 return alloc
215 ? alloc
216 : ACE_Singleton<ALLOCATOR, ACE_LOCK>::instance ();
220 // Flush the ACE metrics cache into shared memory.
222 template <class ACE_LOCK, class ALLOCATOR> void
223 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
224 flush_ACE_Metrics_Cache ()
228 ACE_END_VERSIONED_NAMESPACE_DECL
230 #endif /* defined (ACE_COMPILE_TIMEPROBES) */
232 #endif /* ACE_METRICS_CACHE_CPP */