summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Metrics/Metrics_FrameManager_T.h
blob: 0335c8bf43c6b166b34d8bc9b43aadcb684c04db (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
// $Id$

#ifndef METRICS_FRAME_MANAGER_T_H
#define METRICS_FRAME_MANAGER_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/High_Res_Timer.h"

#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/RtecSchedulerC.h"
#include "orbsvcs/MetricsS.h"

#include "orbsvcs/Metrics/Metrics_FrameManager.h"


template <class ACE_LOCK>
struct TAO_Metrics_Frame_Manager_Data
{
  // = TITLE
  //   Defines a class for time frame management data.
  //
  // = DESCRIPTION
  //   This class makes use of the <ACE_Time_Value> class to
  //   store period and endpoint data for a given time frame.

public:

  TAO_Metrics_Frame_Manager_Data (RtecScheduler::Period_t p)
    : frame_id_ (0), period_ (0, p / 10) {}
  // Constructor.  Note that p is in hundreds of nanoseconds so we
  // divide by ten to get microseconds.  The start_ and end_ data
  // members are set equal to ACE_Time_Value::zero by their own
  // default constructors.

  CORBA::ULong frame_id_;
  // Stores the number of previous frames for that period.  May roll
  // over, but is intended to provide a locally (for a large range of
  // locality) unique frame identifier.

  ACE_Time_Value period_;
  // Relative time to the next frame, from the start of this one.

  ACE_Time_Value start_;
  // Absolute time of the start of the frame and end of the last.

  ACE_Time_Value end_;
  // Absolute time to the end of the frame and start of the next.

  ACE_LOCK lock_;
  // Lock for synchronizing access to the data instance.
};


template <class ACE_LOCK>
class TAO_Metrics_FrameManager : public POA_Metrics::FrameManager

{
  // = 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 TAO_Metrics_FrameManager<ACE_LOCK> TAO_METRICS_FRAME_MANAGER_TYPE;
  typedef TAO_Metrics_Frame_Manager_Data<ACE_LOCK> TAO_METRICS_FRAME_MANAGER_DATA_TYPE;

  typedef ACE_Hash_Map_Manager_Ex<RtecScheduler::Period_t,
	                          TAO_METRICS_FRAME_MANAGER_DATA_TYPE *,
                                  ACE_Hash<RtecScheduler::Period_t>,
                                  ACE_Equal_To<RtecScheduler::Period_t>,
                                  ACE_Null_Mutex> METRICS_FRAME_DATA_MAP;
  // Type of map used for O(1) lookup of monitored data for operations.

  typedef ACE_Hash_Map_Entry<RtecScheduler::Period_t,
                             TAO_METRICS_FRAME_MANAGER_DATA_TYPE *>
    METRICS_FRAME_DATA_MAP_ENTRY;
  // Type of entry in monitor map.

  typedef ACE_Hash_Map_Iterator_Ex<RtecScheduler::Period_t,
	                           TAO_METRICS_FRAME_MANAGER_DATA_TYPE *,
                                   ACE_Hash<RtecScheduler::Period_t>,
                                   ACE_Equal_To<RtecScheduler::Period_t>,
                                   ACE_Null_Mutex>
    METRICS_FRAME_DATA_MAP_ITERATOR;
  // Type of iterator for monitor map.

  TAO_Metrics_FrameManager ();
  // Constructor.

  ~TAO_Metrics_FrameManager ();
  // Destructor.

  CORBA::Short register_period (RtecScheduler::Period_t p,
                                CORBA::Environment &ACE_TRY_ENV
                                  = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Binds the period to the internal frame map, with a new frame data
  // structure.  Returns 0 if a new entry is bound successfully,
  // returns 1 if an attempt is made to bind an existing entry, and
  // returns -1 if failures occur.

  CORBA::Short update_all_frames (const ACE_Time_Value& tv);
  // Updates time frames, based on the passed time value.

  CORBA::Short update_all_frames_with_time (Metrics::Time mt,
                                            CORBA::Environment &ACE_TRY_ENV
                                              = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::SYNCHRONIZATION));
  // Updates time frames, based on the passed time value.

  CORBA::Short update_all_frames (CORBA::Environment &ACE_TRY_ENV
                                    = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::SYNCHRONIZATION));
  // Updates time frames, based on the current time as of the call.

  CORBA::Short update_frame (RtecScheduler::Period_t p, const ACE_Time_Value& tv);
  // Updates the passed period's time frame, based on the passed time
  // value.

  CORBA::Short update_frame_with_time (RtecScheduler::Period_t p,
                                       Metrics::Time mt,
                                       CORBA::Environment &ACE_TRY_ENV
                                         = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Updates the passed period's time frame, based on the passed time
  // value.

  CORBA::Short update_frame (RtecScheduler::Period_t p,
                             CORBA::Environment &ACE_TRY_ENV
                               = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Updates the passed period's time frame, based on the current time
  // as of the call.

  CORBA::Short reset_all_frames (const ACE_Time_Value& tv);
  // Resets time frames, based on the passed time value.

  CORBA::Short reset_all_frames_with_time (Metrics::Time mt,
                                           CORBA::Environment &ACE_TRY_ENV
                                             = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::SYNCHRONIZATION));
  // Resets time frames, based on the passed time value.

  CORBA::Short reset_all_frames (CORBA::Environment &ACE_TRY_ENV
                                   = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::SYNCHRONIZATION));
  // Resets time frames, based on the current time as of the call.

  CORBA::Short reset_frame (RtecScheduler::Period_t p, const ACE_Time_Value& tv);
  // Resets the passed period's start-of-frame, based on the passed time
  // value.

  CORBA::Short reset_frame_with_time (RtecScheduler::Period_t p,
                                      Metrics::Time mt,
                                      CORBA::Environment &ACE_TRY_ENV
                                        = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Resets the passed period's start-of-frame, based on the passed time
  // value.

  CORBA::Short reset_frame (RtecScheduler::Period_t p,
                            CORBA::Environment &ACE_TRY_ENV
                              = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Resets the passed period's start-of-frame, based on the current time
  // as of the call.

  CORBA::Short get_start_time (RtecScheduler::Period_t p, ACE_Time_Value &start);
  // Gets the start time for the period's current frame.

  CORBA::Short get_start_time (RtecScheduler::Period_t p,
                               Metrics::Time &start,
                               CORBA::Environment &ACE_TRY_ENV
                                 = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Gets the start time for the period's current frame.

  CORBA::Short get_end_time (RtecScheduler::Period_t p, ACE_Time_Value &end);
  // Gets the end time for the period's current frame.

  CORBA::Short get_end_time (RtecScheduler::Period_t p,
                             Metrics::Time &end,
                             CORBA::Environment &ACE_TRY_ENV
                               = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Gets the end time for the period's current frame.

  CORBA::Short get_frame_id (RtecScheduler::Period_t p,
                             CORBA::ULong &id,
                             CORBA::Environment &ACE_TRY_ENV
                               = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Gets the locally unique identifier for the period's current frame.

  CORBA::Short get_frame_data (RtecScheduler::Period_t p, ACE_Time_Value &start,
                      ACE_Time_Value &end, CORBA::ULong &id);
  // Gets the start time, end time, and id period's current frame.

  CORBA::Short get_frame_data (RtecScheduler::Period_t p,
                               Metrics::Time &start,
                               Metrics::Time &end,
                               CORBA::ULong &id,
                               CORBA::Environment &ACE_TRY_ENV
                                 = CORBA::Environment::default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL,
                     Metrics::SYNCHRONIZATION));
  // Gets the start time, end time, and id period's current frame.

protected:

  CORBA::Short update_data (TAO_Metrics_Frame_Manager_Data<ACE_LOCK> & data,
                   const ACE_Time_Value& tv);
  // Updates the passed frame data structure's start and end times,
  // based on the passed time value.  This is a protected internal
  // method, and should only be called with locks already held.


  CORBA::Short reset_data (TAO_Metrics_Frame_Manager_Data<ACE_LOCK> & data,
                  const ACE_Time_Value& tv);
  // Resets the passed frame data structure's start and end times, to
  // the passed time value and one period later, respectively.  This
  // is a protected internal method, and should only be called with
  // locks already held.

  METRICS_FRAME_DATA_MAP frame_data_map_;
  // Maps periods to frame data.

  // Count of the number of registered periods.
  u_long period_count_;

  ACE_LOCK lock_;
  // Lock for synchronizing access to the map.
};

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "orbsvcs/Metrics/Metrics_FrameManager_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

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

#if defined (__ACE_INLINE__)
#include "orbsvcs/Metrics/Metrics_FrameManager_T.inl"
#endif /* __ACE_INLINE__ */

#endif /* METRICS_FRAME_MANAGER_T_H */