Revert to Current Include Style
[ACE_TAO.git] / ACE / ace / Metrics_Cache_T.h
blob037ae3bee81156da5584ba7b1c550609b2564caf
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Metrics_Cache_T.h
7 * @author Chris Gill <cdgill@cse.wustl.edu>
8 */
9 //=============================================================================
12 #ifndef ACE_METRICS_CACHE_T_H
13 #define ACE_METRICS_CACHE_T_H
15 #include /**/ "ace/config-all.h"
17 // helpful macro definitions
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #if defined (ACE_COMPILE_TIMEPROBES)
24 #include "ace/Timeprobe.h"
25 #include "ace/Timeprobe_T.h"
27 // Defaults for initializing timeprobes and timeprobe arays.
28 #define METRICS_MIN_TIMEPROBE_TABLE_SIZE 256 * 4
29 #define METRICS_MAX_TIMEPROBE_TABLE_SIZE 256 * 256
30 #define METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE METRICS_MIN_TIMEPROBE_TABLE_SIZE
31 #define METRICS_DEFAULT_TIMEPROBE_COUNT 6
33 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
35 /**
36 * @class ACE_Metrics_Timeprobe
38 * @brief This class implements a timeprobe for use in a Metrics framework.
40 * This class provides a probe for specific thread and method call
41 * metrics timing points.
43 template <class ACE_LOCK, class ALLOCATOR>
44 class ACE_Metrics_Timeprobe :
45 public ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR>
47 public:
49 typedef ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>
50 ACE_METRICS_TIMEPROBE_TYPE;
52 typedef ACE_timeprobe_t ACE_METRICS_TIMEPROBE_DATA_TYPE;
53 typedef ACE_METRICS_TIMEPROBE_TYPE* ACE_METRICS_TIMEPROBE_BASED_PTR_TYPE;
54 typedef char* ACE_METRICS_NAME_BASED_PTR_TYPE;
56 /// Enumerated timeprobe event types.
57 enum event_id
59 WORK_START = 0,
60 WORK_STOP = 1,
61 WORK_SUSPEND = 2,
62 WORK_RESUME = 3
65 /// Default constructor: plugs in the above event descriptions.
66 ACE_Metrics_Timeprobe (u_int id = 0,
67 const char *name = 0,
68 u_long size = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE);
70 /// Constructor with allocator: plugs in the above event descriptions.
71 ACE_Metrics_Timeprobe (ALLOCATOR *allocatorPtr,
72 u_int id = 0,
73 const char *name = 0,
74 u_long size = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE);
76 /// Destructor.
77 virtual ~ACE_Metrics_Timeprobe ();
79 /// Returns true if a timeprobe event matches the passed id.
80 int is_event (const ACE_METRICS_TIMEPROBE_DATA_TYPE &t,
81 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::event_id id);
83 /// Accessor and mutator for probe name.
84 const char * probe_name (void);
85 void probe_name (char * name);
87 /// Accessor for probe id.
88 u_int probe_id (void);
90 /// Mutator for probe id.
91 void probe_id (u_int id);
93 /// Flush the ACE metrics timeprobe into shared memory.
94 void flush_ACE_Metrics_Timeprobe ();
96 protected:
98 /// Identifier for the timeprobe.
99 u_int id_;
101 /// Name of the timeprobe.
102 char* name_;
104 private:
106 // Declare but do not define.
107 ACE_Metrics_Timeprobe (const ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> &);
108 void operator =(const ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> &);
112 * @class ACE_Metrics_Cache
114 * @brief This class implements a cache for metrics timeprobe data.
116 * This class allows probes to be recorded into a single cache that
117 * monitors and other higher level metrics classes can query.
119 template <class ACE_LOCK, class ALLOCATOR>
120 class ACE_Metrics_Cache
122 public:
124 typedef ACE_Metrics_Cache <ACE_LOCK, ALLOCATOR> ACE_METRICS_CACHE_TYPE;
126 /// Default constructor.
127 ACE_Metrics_Cache (u_long table_size
128 = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE,
129 u_long number_of_probes
130 = METRICS_DEFAULT_TIMEPROBE_COUNT,
131 ALLOCATOR * allocatorPtr = (ALLOCATOR*)ALLOCATOR::instance());
133 /// Destructor.
134 ~ACE_Metrics_Cache ();
136 // = Dispatching metrics.
138 /// Report start, stop, suspend, and resume times of a dispatch
139 /// enqueue: stores data metrics on the supplier side.
140 void report_enqueue_start (u_long i);
141 void report_enqueue_stop (u_long i);
142 void report_enqueue_suspend (u_long i);
143 void report_enqueue_resume (u_long i);
145 /// Report start, stop, suspend, and resume times of a dispatch
146 /// dequeue: stores data metrics on the supplier side..
147 void report_dequeue_start (u_long i);
148 void report_dequeue_stop (u_long i);
149 void report_dequeue_suspend (u_long i);
150 void report_dequeue_resume (u_long i);
152 /// Reset the metrics data on the consumer side.
153 void reset_base_statistics ();
155 /// Flips the supplier and consumer sides.
156 void flip_supplier_and_consumer ();
158 /// Flush the ACE metrics cache into shared memory.
159 void flush_ACE_Metrics_Cache ();
161 /// Set the enable state for metrics collection.
162 void metrics_enabled(int enabled);
164 /// Return the enable state for metrics collection.
165 int metrics_enabled(void) const;
167 protected:
169 /// Obtain an allocator pointer correctly thunked for the current
170 /// address space. If there is no allocator stored in the instance,
171 /// the singleton allocator in the current process is used.
172 ALLOCATOR * allocator (void);
174 // = Implementation members.
176 /// Number of probes in each supplier/consumer set.
177 u_long probe_set_size_;
179 /// Probe data counts for each supplier/consumer set.
180 u_long * enqueue_count_ [2];
181 u_long * dequeue_count_ [2];
183 /// Probes for each supplier/consumer set.
184 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> ** enqueue_probes_ [2];
185 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> ** dequeue_probes_ [2];
187 /// Names for the probes.
188 char ** enqueue_names_;
189 char ** dequeue_names_;
191 /// Index from which probe events are being consumed.
192 /// for WSOA, it's the data being sent to the logger
193 int consumer_index_;
195 /// Index to which probe events are being supplied.
196 /// for WSOA, it's the data being recorded from the probes
197 int supplier_index_;
199 /// Size of the timestamp table in each probe.
200 u_long table_size_;
202 /// Interval start and stop timestamps.
203 ACE_Time_Value interval_start_;
205 /// Interval start and stop timestamps.
206 ACE_Time_Value interval_end_;
208 /// Flag to indicate whether or not start time of interval has been
209 /// initialized since the last reset.
210 int interval_initialized_;
212 /// Indicator of whether metrics is enabled.
213 int metrics_enabled_;
215 private:
217 /// Allocation strategy object.
218 ALLOCATOR* allocator_;
220 // Declare but do not define.
221 ACE_Metrics_Cache (const ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR> &);
222 void operator = (const ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR> &);
225 ACE_END_VERSIONED_NAMESPACE_DECL
227 #if defined (__ACE_INLINE__)
228 #include "ace/Metrics_Cache_T.inl"
229 #endif /* __ACE_INLINE__ */
231 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
232 #include "ace/Metrics_Cache_T.cpp"
233 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
235 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
236 #pragma implementation ("Metrics_Cache_T.cpp")
237 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
239 #endif /* defined (ACE_COMPILE_TIMEPROBES) */
241 #endif /* ACE_METRICS_CACHE_T_H */