3 //=============================================================================
5 * @file Metrics_Cache_T.h
7 * $Id: Metrics_Cache_T.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Chris Gill <cdgill@cse.wustl.edu>
11 //=============================================================================
14 #ifndef ACE_METRICS_CACHE_T_H
15 #define ACE_METRICS_CACHE_T_H
17 #include /**/ "ace/config-all.h"
19 // helpful macro definitions
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #if defined (ACE_COMPILE_TIMEPROBES)
26 #include "ace/Timeprobe.h"
27 #include "ace/Timeprobe_T.h"
29 // Defaults for initializing timeprobes and timeprobe arays.
30 #define METRICS_MIN_TIMEPROBE_TABLE_SIZE 256 * 4
31 #define METRICS_MAX_TIMEPROBE_TABLE_SIZE 256 * 256
32 #define METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE METRICS_MIN_TIMEPROBE_TABLE_SIZE
33 #define METRICS_DEFAULT_TIMEPROBE_COUNT 6
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
38 * @class ACE_Metrics_Timeprobe
40 * @brief This class implements a timeprobe for use in a Metrics framework.
42 * This class provides a probe for specific thread and method call
43 * metrics timing points.
45 template <class ACE_LOCK
, class ALLOCATOR
>
46 class ACE_Metrics_Timeprobe
:
47 public ACE_Timeprobe_Ex
<ACE_LOCK
, ALLOCATOR
>
51 typedef ACE_Metrics_Timeprobe
<ACE_LOCK
, ALLOCATOR
>
52 ACE_METRICS_TIMEPROBE_TYPE
;
54 typedef ACE_timeprobe_t ACE_METRICS_TIMEPROBE_DATA_TYPE
;
55 typedef ACE_METRICS_TIMEPROBE_TYPE
* ACE_METRICS_TIMEPROBE_BASED_PTR_TYPE
;
56 typedef char* ACE_METRICS_NAME_BASED_PTR_TYPE
;
58 // Enumerated timeprobe event types.
67 // Default constructor: plugs in the above event descriptions.
68 ACE_Metrics_Timeprobe (u_int id
= 0,
70 u_long size
= METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE
);
72 // Constructor with allocator: plugs in the above event descriptions.
73 ACE_Metrics_Timeprobe (ALLOCATOR
*allocatorPtr
,
76 u_long size
= METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE
);
79 virtual ~ACE_Metrics_Timeprobe ();
81 // Returns true if a timeprobe event matches the passed id.
82 int is_event (const ACE_METRICS_TIMEPROBE_DATA_TYPE
&t
,
83 ACE_Metrics_Timeprobe
<ACE_LOCK
, ALLOCATOR
>::event_id id
);
85 // Accessor and mutator for probe name.
86 const char * probe_name (void);
87 void probe_name (char * name
);
89 // Accessor for probe id.
90 u_int
probe_id (void);
92 // Mutator for probe id.
93 void probe_id (u_int id
);
95 // Flush the ACE metrics timeprobe into shared memory.
96 void flush_ACE_Metrics_Timeprobe ();
100 // Identifier for the timeprobe.
103 // Name of the timeprobe.
108 // Declare but do not define.
109 ACE_Metrics_Timeprobe (const ACE_Metrics_Timeprobe
<ACE_LOCK
, ALLOCATOR
> &);
110 void operator =(const ACE_Metrics_Timeprobe
<ACE_LOCK
, ALLOCATOR
> &);
114 * @class ACE_Metrics_Cache
116 * @brief This class implements a cache for metrics timeprobe data.
118 * This class allows probes to be recorded into a single cache that
119 * monitors and other higher level metrics classes can query.
121 template <class ACE_LOCK
, class ALLOCATOR
>
122 class ACE_Metrics_Cache
126 typedef ACE_Metrics_Cache
<ACE_LOCK
, ALLOCATOR
> ACE_METRICS_CACHE_TYPE
;
128 // Default constructor.
129 ACE_Metrics_Cache (u_long table_size
130 = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE
,
131 u_long number_of_probes
132 = METRICS_DEFAULT_TIMEPROBE_COUNT
,
133 ALLOCATOR
* allocatorPtr
= (ALLOCATOR
*)ALLOCATOR::instance());
136 ~ACE_Metrics_Cache ();
138 // = Dispatching metrics.
140 // Report start, stop, suspend, and resume times of a dispatch
141 // enqueue: stores data metrics on the supplier side.
142 void report_enqueue_start (u_long i
);
143 void report_enqueue_stop (u_long i
);
144 void report_enqueue_suspend (u_long i
);
145 void report_enqueue_resume (u_long i
);
147 // Report start, stop, suspend, and resume times of a dispatch
148 // dequeue: stores data metrics on the supplier side..
149 void report_dequeue_start (u_long i
);
150 void report_dequeue_stop (u_long i
);
151 void report_dequeue_suspend (u_long i
);
152 void report_dequeue_resume (u_long i
);
154 // Reset the metrics data on the consumer side.
155 void reset_base_statistics ();
157 // Flips the supplier and consumer sides.
158 void flip_supplier_and_consumer ();
160 // Flush the ACE metrics cache into shared memory.
161 void flush_ACE_Metrics_Cache ();
163 // Set the enable state for metrics collection.
164 void metrics_enabled(int enabled
);
166 // Return the enable state for metrics collection.
167 int metrics_enabled(void) const;
171 // Obtain an allocator pointer correctly thunked for the current
172 // address space. If there is no allocator stored in the instance,
173 // the singleton allocator in the current process is used.
174 ALLOCATOR
* allocator (void);
176 // = Implementation members.
178 // Number of probes in each supplier/consumer set.
179 u_long probe_set_size_
;
181 // Probe data counts for each supplier/consumer set.
182 u_long
* enqueue_count_
[2];
183 u_long
* dequeue_count_
[2];
185 // Probes for each supplier/consumer set.
186 ACE_Metrics_Timeprobe
<ACE_LOCK
, ALLOCATOR
> ** enqueue_probes_
[2];
187 ACE_Metrics_Timeprobe
<ACE_LOCK
, ALLOCATOR
> ** dequeue_probes_
[2];
189 // Names for the probes.
190 char ** enqueue_names_
;
191 char ** dequeue_names_
;
193 // Index from which probe events are being consumed.
194 // for WSOA, it's the data being sent to the logger
197 // Index to which probe events are being supplied.
198 // for WSOA, it's the data being recorded from the probes
201 // Size of the timestamp table in each probe.
204 // Interval start and stop timestamps.
205 ACE_Time_Value interval_start_
;
207 // Interval start and stop timestamps.
208 ACE_Time_Value interval_end_
;
210 // Flag to indicate whether or not start time of interval has been
211 // initialized since the last reset.
212 int interval_initialized_
;
214 // Indicator of whether metrics is enabled.
215 int metrics_enabled_
;
219 // Allocation strategy object.
220 ALLOCATOR
* allocator_
;
222 // Declare but do not define.
223 ACE_Metrics_Cache (const ACE_Metrics_Cache
<ACE_LOCK
, ALLOCATOR
> &);
224 void operator = (const ACE_Metrics_Cache
<ACE_LOCK
, ALLOCATOR
> &);
227 ACE_END_VERSIONED_NAMESPACE_DECL
229 #if defined (__ACE_INLINE__)
230 #include "ace/Metrics_Cache_T.inl"
231 #endif /* __ACE_INLINE__ */
233 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
234 #include "ace/Metrics_Cache_T.cpp"
235 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
237 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
238 #pragma implementation ("Metrics_Cache_T.cpp")
239 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
241 #endif /* defined (ACE_COMPILE_TIMEPROBES) */
243 #endif /* ACE_METRICS_CACHE_T_H */