summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Metrics/Metrics_LocalCache_T.h
blob: 690b4fb8d0b72aaba96534975641b84477129c83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// $Id$

#ifndef METRICS_LOCAL_CACHE_T_H
#define METRICS_LOCAL_CACHE_T_H

#include "ace/OS.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Hash_Map_Manager.h"
#include "ace/Metrics_Cache.h"
#include "ace/Metrics_Cache_T.h"

#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/Scheduler_Factory.h"
#include "orbsvcs/MetricsC.h"
#include "orbsvcs/Metrics/Metrics_Utils.h"

#if defined (ACE_HAS_METRICS_BASE_POINTERS)
  typedef ACE_Based_Pointer<char> ACE_METRICS_STRING_TYPE;
  typedef ACE_Based_Pointer<Metrics::TimeprobeParameter_Set> ACE_METRICS_PARAMETER_SET_TYPE;
#else
  typedef char * ACE_METRICS_STRING_TYPE;
  typedef Metrics::TimeprobeParameter_Set * ACE_METRICS_PARAMETER_SET_TYPE;
#endif

//DCL:Commented out to remove Linux compile error
//#include "orbsvcs/Metrics/Metrics_LocalCache.h"

template <typename ACE_LOCK, typename ALLOCATOR>
class TAO_Metrics_LocalTimeprobe
  : public ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>
{
  // = TITLE
  //   Defines a class that implements a local timeprobe.
  //
  // = DESCRIPTION
  //   This class makes use of the <ACE_Metrics_Timeprobe> class to
  //   implement a timeprobe for use in a local metrics cache.
public:

  typedef TAO_Metrics_LocalTimeprobe<ACE_LOCK, ALLOCATOR> TAO_METRICS_TIMEPROBE_TYPE;

  TAO_Metrics_LocalTimeprobe (u_int id = 0,
                              const char *name = 0,
                              u_long size
                                = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE,
                              ALLOCATOR * alloc = 0);
  // Default constructor.

  void report_intervals (int report_full_interval_times = 0);
  // Reports valid intervals between start and stop events.

  void install_data_set (Metrics::TimeprobeParameter_Set *data_set = 0);
  // Installs or unistalls the data set into which probe will report.

  void mark_as_operation (void) {this->is_operation_ = 1;}
  // Marks the probe as being for an operation.

  void set_hrt (int hrt) {this->is_hrt_ = hrt;}
  // Marks the probe as being SRT/HRT.

  ACE_Time_Value last_recorded_timestamp (void);
  // Returns the last timestamp that was recorded in the probe.
  // If no stamps are recorded, returns zero.

  void flush_TAO_Metrics_LocalTimeprobe ();
  // Flush the TAO metrics local timeprobe into shared memory.

protected:

  int is_operation_;
  // Indicates whether or not the probe is for an operation.

  int is_hrt_;
  // Indicates whether or not the probe is Hard Real-Time.

  ACE_METRICS_PARAMETER_SET_TYPE data_set_;
  // Points to a probe metrics data set.
};

template <class ACE_LOCK, class ALLOCATOR>
class TAO_Metrics_LocalCache
  : public ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>
{
  // = TITLE
  //   Defines a class that implements a local metrics cache.
  //
  // = DESCRIPTION
  //   This class makes use of the <ACE_Metrics_Cache> class to
  //   implement a cache for local use.
public:

  typedef ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>
          ACE_METRICS_TIMEPROBE_TYPE;

#if defined (ACE_HAS_METRICS_BASE_POINTERS)
  typedef ACE_Based_Pointer<ACE_METRICS_TIMEPROBE_TYPE>
          ACE_METRICS_TIMEPROBE_BASED_PTR_TYPE;
#else
  typedef ACE_METRICS_TIMEPROBE_TYPE * ACE_METRICS_TIMEPROBE_BASED_PTR_TYPE;
#endif

  typedef TAO_Metrics_LocalTimeprobe<ACE_LOCK, ALLOCATOR> TAO_METRICS_TIMEPROBE_TYPE;

  typedef TAO_Metrics_LocalCache<ACE_LOCK, ALLOCATOR> TAO_METRICS_CACHE_TYPE;

  struct TAO_Metrics_Cache_Data_Base
  {
     ACE_METRICS_STRING_TYPE probe_name;
     TAO_Metrics_LocalTimeprobe<ACE_LOCK, ALLOCATOR> probe;
  };

  struct TAO_Metrics_Cache_Data : public TAO_Metrics_Cache_Data_Base
  {
     int is_hrt;
     u_long missed_deadlines;
     u_long made_deadlines;
     u_long cancellations;
  };

#if defined (ACE_HAS_METRICS_BASE_POINTERS)
  typedef ACE_Based_Pointer<TAO_Metrics_Cache_Data_Base> ACE_METRICS_CACHE_DATA_BASE_TYPE;
  typedef ACE_Based_Pointer<TAO_Metrics_Cache_Data> ACE_METRICS_CACHE_DATA_TYPE;
#else
  typedef TAO_Metrics_Cache_Data_Base* ACE_METRICS_CACHE_DATA_BASE_TYPE;
  typedef TAO_Metrics_Cache_Data* ACE_METRICS_CACHE_DATA_TYPE;
#endif

  typedef ACE_Hash_Map_Manager_Ex<RtecScheduler::handle_t,
                                  ACE_METRICS_CACHE_DATA_BASE_TYPE,
                                  ACE_Hash<RtecScheduler::handle_t>,
                                  ACE_Equal_To<RtecScheduler::handle_t>,
                                  ACE_Null_Mutex> METRICS_BASE_MONITOR_MAP;
  // Type of map used for O(1) lookup of monitored data for operations.

  typedef ACE_Hash_Map_Entry<RtecScheduler::handle_t,
                             ACE_METRICS_CACHE_DATA_BASE_TYPE >
    METRICS_BASE_MONITOR_MAP_ENTRY;
  // Type of entry in monitor map.

  typedef ACE_Hash_Map_Iterator_Ex<RtecScheduler::handle_t,
                                   ACE_METRICS_CACHE_DATA_BASE_TYPE,
                                   ACE_Hash<RtecScheduler::handle_t>,
                                   ACE_Equal_To<RtecScheduler::handle_t>,
                                   ACE_Null_Mutex>
    METRICS_BASE_MONITOR_MAP_ITERATOR;
  // Type of iterator for monitor map.

  typedef ACE_Hash_Map_Manager_Ex<RtecScheduler::handle_t,
                                  ACE_METRICS_CACHE_DATA_TYPE,
                                  ACE_Hash<RtecScheduler::handle_t>,
                                  ACE_Equal_To<RtecScheduler::handle_t>,
                                  ACE_Null_Mutex> METRICS_MONITOR_MAP;
  // Type of map used for O(1) lookup of monitored data for operations.

  typedef ACE_Hash_Map_Entry<RtecScheduler::handle_t,
                             ACE_METRICS_CACHE_DATA_TYPE >
    METRICS_MONITOR_MAP_ENTRY;
  // Type of entry in monitor map.

  typedef ACE_Hash_Map_Iterator_Ex<RtecScheduler::handle_t,
                                   ACE_METRICS_CACHE_DATA_TYPE,
                                   ACE_Hash<RtecScheduler::handle_t>,
                                   ACE_Equal_To<RtecScheduler::handle_t>,
                                   ACE_Null_Mutex>
    METRICS_MONITOR_MAP_ITERATOR;
  // Type of iterator for monitor map.

  TAO_Metrics_LocalCache (u_long table_size
                            = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE,
                          u_long number_of_probes
                            = METRICS_DEFAULT_TIMEPROBE_COUNT,
                          ALLOCATOR * alloc = 0);
  // Constructor.

  ~TAO_Metrics_LocalCache () {this->fini ();}
  // Destructor.

  void reset_statistics ();
  // Reset the collection of metrics data.

  int init (u_long number_of_probes);
  // Factory method for constructing probes.

  void fini ();
  // Method for destroying probes.

  void register_upcall_adapter (RtecScheduler::handle_t handle,
                                const char *name,
                                int is_hrt,
                                unsigned short incr_upcall_id = 1);
  // Registers an upcall adapter, allocates monitoring data structures
  // for it in hash maps if not already present.

  RtecScheduler::handle_t register_base_metrics (const char *name,
                                                 TAO_Metrics_Utils::Base_Metrics_Type bmt,
                                                 unsigned short incr_base_id = 1);
  // Registers a base metrics probe, allocates monitoring data structures
  // for it in hash maps, returns a handle to the metrics segment.

  void report_upcall_start (RtecScheduler::handle_t handle);
  // Inline: Records start time of an upcall.

  int report_upcall_stop (RtecScheduler::handle_t handle,
                          const ACE_Time_Value & deadline);
  // Inline: Records end time of an upcall, returns 0 if the deadline
  // was made, 1 if the deadline was missed, or -1 if an error occurred.
  // If the passed deadline is equal to ACE_Time_Value::zero, by definition
  // the deadline is made, and the method returns 0.

  void report_upcall_cancellation (RtecScheduler::handle_t handle);
  // Inline: Reports a cancelled upcall.

  void report_base_metrics_start (RtecScheduler::handle_t handle);
  // Inline: Records start time of a base metrics segment.

  void report_base_metrics_stop (RtecScheduler::handle_t handle);
  // Inline: Records stop time of a base metrics segment.

  void report_base_metrics_suspend (RtecScheduler::handle_t handle);
  // Inline: Records start time of a base metrics segment.

  void report_base_metrics_resume (RtecScheduler::handle_t handle);
  // Inline: Records stop time of a base metrics segment.

  void flush_TAO_Metrics_LocalCache ();
  // Flush the TAO metrics local cache into shared memory.

protected:
  void increment_base_handle(TAO_Metrics_Utils::Base_Metrics_Type bmt);
  // Used to increment the probe id counter for a particular metrics type

  void increment_upcall_handle();
  // Used to increment the probe id counter for a upcall probe type

  METRICS_BASE_MONITOR_MAP base_monitor_maps_ [2];
  // These map base metrics ids to base monitor data.

  METRICS_MONITOR_MAP monitor_maps_ [2];
  // These map operation handles to upcall monitor data.

  // Count of the number of registered sched probes.
  u_long sched_count_;

  // Count of the number of registered quo probes.
  u_long quo_count_;

    // Count of the number of registered tns probes.
  u_long tns_count_;

  // Count of the number of registered teec probes.
  u_long teec_count_;

  // Count of the number of registered rtarm probes.
  u_long rtarm_count_;

  // Count of the number of registered upcall adapters.
  u_long upcall_adapter_count_;

  // Holds the next base metrics probe handle to assign
  RtecScheduler::handle_t next_base_metrics_handle_;

};



template <class ACE_LOCK, class ALLOCATOR>
class TAO_Metrics_ReportingLocalCache
  : public TAO_Metrics_LocalCache<ACE_LOCK, ALLOCATOR>
{
  // = TITLE
  //   Defines a class that adds metrics logger reporting to a local cache.
  //
  // = DESCRIPTION
  //   This class makes use of the <TAO_Metrics_LocalCache> as its
  //   a cache for local use, and adds reporting to the logger.
public:

  TAO_Metrics_ReportingLocalCache (u_long table_size
                                     = METRICS_DEFAULT_TIMEPROBE_TABLE_SIZE,
                                   u_long number_of_probes
                                     = METRICS_DEFAULT_TIMEPROBE_COUNT,
                                   ALLOCATOR * alloc = 0);
  // Constructor.

  ~TAO_Metrics_ReportingLocalCache () {this->fini ();}
  // Destructor.

  void output_statistics (Metrics::QoSLogger_ptr logger);
  // Output the statistics to the remote logger servant.

  void register_upcall_adapter (RtecScheduler::handle_t handle,
                                const char *name,
                                int is_hrt,
                                Metrics::QoSLogger_ptr logger);
  // Registers an upcall adapter, allocates monitoring data structures
  // for it in hash maps if not already present.

  RtecScheduler::handle_t register_base_metrics (const char *name,
                                                 TAO_Metrics_Utils::Base_Metrics_Type bmt,
                                                 Metrics::QoSLogger_ptr logger);
  // Registers a base metrics probe, allocates monitoring data structures
  // for it in hash maps, returns a handle to the metrics segment.

  int register_probes (Metrics::QoSLogger_ptr logger);
  // Registers probes with the logger.

  void flush_TAO_Metrics_ReportingLocalCache ();
  // Flush the TAO metrics local cache into shared memory.
};

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "Metrics_LocalCache_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Metrics_LocalCache_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#if defined (__ACE_INLINE__)
#include "Metrics_LocalCache_T.i"
#endif /* __ACE_INLINE__ */

#endif /* METRICS_LOCAL_CACHE_T_H */