summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Metrics/Metrics_UpcallMonitor.i
blob: 41c3b8ff649e5052c4560144082278b0672a7a89 (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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// $Id$

// @METRICS@

#ifndef METRICS_UPCALL_MONITOR_I
#define METRICS_UPCALL_MONITOR_I

//# if defined (METRICS_USES_OP_CANCELLATION)
//# undef METRICS_USES_OP_CANCELLATION
//# endif /* METRICS_USES_OP_CANCELLATION */

# if ! defined (METRICS_USES_OP_CANCELLATION)
#   define METRICS_USES_OP_CANCELLATION
# endif /* ! METRICS_USES_OP_CANCELLATION */


/////////////////////////////////////
// Class TAO_Metrics_UpcallMonitor //
/////////////////////////////////////

// Default constructor.

ACE_INLINE
TAO_Metrics_UpcallMonitor::TAO_Metrics_UpcallMonitor ()
{
}

// Destructor.

ACE_INLINE
TAO_Metrics_UpcallMonitor::~TAO_Metrics_UpcallMonitor ()
{
}

// Reports a successful upcall.

ACE_INLINE void
TAO_Metrics_UpcallMonitor::
report_made_deadline (RtecScheduler::handle_t handle
                      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_0))
{
  CORBA::ULong count = 0;
  MONITOR_MAP_ENTRY *entry;

  if (made_map_.trybind (handle, count, entry) < 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Failed trybind for handle %u in made map\n", handle));
      ACE_THROW (Metrics::INTERNAL_0 ());
    }

  ++entry->int_id_;
}

// Reports an unsuccessful upcall.

ACE_INLINE void
TAO_Metrics_UpcallMonitor::
report_missed_deadline (RtecScheduler::handle_t handle
                        ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_1))
{
  CORBA::ULong count = 0;
  MONITOR_MAP_ENTRY *entry;

  if (missed_map_.trybind (handle, count, entry) < 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Failed trybind for handle %u in missed map\n", handle));
      ACE_THROW (Metrics::INTERNAL_1 ());
    }

  ++entry->int_id_;
}


// Get the aggregate QoS statistics collected so far by the monitor.

ACE_INLINE void
TAO_Metrics_UpcallMonitor::get_aggregate_QoS (RtecScheduler::handle_t handle,
                                              Metrics::QoSParameter_t_out qos
                                              ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_2,
                     Metrics::INTERNAL_3))
{
  CORBA::ULong made_count = 0;
  CORBA::ULong missed_count = 0;
  MONITOR_MAP_ENTRY *made_entry;
  MONITOR_MAP_ENTRY *missed_entry;

  if (made_map_.trybind (handle, made_count, made_entry) < 0)
    {
      ACE_DEBUG ((LM_DEBUG, "TAO_Metrics_UpcallMonitor::get_aggregate_QoS: "
                  "Failed trybind for handle %u in made map\n", handle));
      ACE_THROW (Metrics::INTERNAL_2 ());
    }

  if (missed_map_.trybind (handle, missed_count, missed_entry) < 0)
    {
      ACE_DEBUG ((LM_DEBUG, "TAO_Metrics_UpcallMonitor::get_aggregate_QoS: "
                  "Failed trybind for handle %u in missed map\n", handle));
      ACE_THROW (Metrics::INTERNAL_3 ());
    }

  ACE_NEW_THROW_EX (qos,
                    Metrics::QoSParameter_t,
                    CORBA::NO_MEMORY ());

  qos->handle = handle;
  qos->deadlines_made = made_entry->int_id_;
  qos->deadlines_missed = missed_entry->int_id_;
  qos->operations_cancelled = 0;
  qos->is_hrt = 0;
}


// Get the aggregate QoS statistics collected for each handle in the
// passed set.

ACE_INLINE void
TAO_Metrics_UpcallMonitor::get_aggregate_QoS_set (
      const Metrics::Handle_Set_t & handle_set,
      Metrics::QoSParameter_Set_out qos_set
      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_4,
                     Metrics::INTERNAL_5))
{
  CORBA::ULong made_count = 0;
  CORBA::ULong missed_count = 0;
  MONITOR_MAP_ENTRY *made_entry = 0;
  MONITOR_MAP_ENTRY *missed_entry = 0;

  ACE_NEW_THROW_EX (qos_set,
                    Metrics::QoSParameter_Set (handle_set.length ()),
                    CORBA::NO_MEMORY ());
  qos_set->length (handle_set.length ());


  for (u_int i = 0; i < handle_set.length (); ++i)
    {
      made_count = 0;
      missed_count = 0;
      made_entry = 0;
      missed_entry = 0;

      if (made_map_.trybind (handle_set [i], made_count, made_entry) < 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "TAO_Metrics_UpcallMonitor::get_aggregate_QoS_set: "
                      "Failed trybind for handle_set [%d] = %u in made map\n",
                      i, handle_set [i]));
          ACE_THROW (Metrics::INTERNAL_4 ());
        }

      if (missed_map_.trybind (handle_set [i], missed_count, missed_entry) < 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "TAO_Metrics_UpcallMonitor::get_aggregate_QoS_set: "
                      "Failed trybind for handle_set[%d]=%u in missed map\n",
                      i, handle_set [i]));
          ACE_THROW (Metrics::INTERNAL_5 ());
        }

      qos_set [i].handle = handle_set [i];
      qos_set [i].deadlines_made = made_entry->int_id_;
      qos_set [i].deadlines_missed = missed_entry->int_id_;
      qos_set [i].operations_cancelled = 0;
      qos_set [i].is_hrt = 0;
    }
}



// Resets the aggregate QoS information for the given operation.

ACE_INLINE void
TAO_Metrics_UpcallMonitor::reset_statistics (RtecScheduler::handle_t handle
                                             ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_7,
                     Metrics::INTERNAL_8))
{
  CORBA::ULong count = 0;

  if (made_map_.rebind (handle, count) < 0)
    {
      ACE_THROW (Metrics::INTERNAL_7 ());
    }

  if (missed_map_.rebind (handle, count) < 0)
    {
      ACE_THROW (Metrics::INTERNAL_8 ());
    }
}


// Accessor for map of operation handle to a count of deadlines missed.

ACE_INLINE
TAO_Metrics_UpcallMonitor::MONITOR_MAP &
TAO_Metrics_UpcallMonitor::missed_map ()
{
  return this->missed_map_;
}

// Accessor for map of operation handle to a count of deadlines made.

ACE_INLINE
TAO_Metrics_UpcallMonitor::MONITOR_MAP &
TAO_Metrics_UpcallMonitor::made_map ()
{
  return this->made_map_;
}

//////////////////////////////////////////////
// Class TAO_Metrics_ReportingUpcallMonitor //
//////////////////////////////////////////////

// Default constructor.

ACE_INLINE
TAO_Metrics_ReportingUpcallMonitor::TAO_Metrics_ReportingUpcallMonitor ()
{
}

// Destructor.

ACE_INLINE
TAO_Metrics_ReportingUpcallMonitor::~TAO_Metrics_ReportingUpcallMonitor ()
{
}

// Reports a successful upcall.

ACE_INLINE void
TAO_Metrics_ReportingUpcallMonitor::
report_made_deadline (RtecScheduler::handle_t handle
                      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_0))
{
  monitor_.report_made_deadline (handle
                                 ACE_ENV_ARG_DECL);
}

// Reports an unsuccessful upcall.

ACE_INLINE void
TAO_Metrics_ReportingUpcallMonitor::
report_missed_deadline (RtecScheduler::handle_t handle
                        ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_1))
{
  monitor_.report_missed_deadline (handle
                                   ACE_ENV_ARG_DECL);
}


// Get the aggregate QoS statistics collected so far by the monitor.

ACE_INLINE void
TAO_Metrics_ReportingUpcallMonitor::get_aggregate_QoS (RtecScheduler::handle_t handle,
                                              Metrics::QoSParameter_t_out qos
                                              ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_2,
                     Metrics::INTERNAL_3))
{
  monitor_.get_aggregate_QoS (handle,
                              qos
                              ACE_ENV_ARG_DECL);
}


// Get the aggregate QoS statistics collected for each handle in the
// passed set.

ACE_INLINE void
TAO_Metrics_ReportingUpcallMonitor::get_aggregate_QoS_set (
      const Metrics::Handle_Set_t & handle_set,
      Metrics::QoSParameter_Set_out qos_set
      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_4,
                     Metrics::INTERNAL_5))
{
  monitor_.get_aggregate_QoS_set (handle_set,
                                  qos_set
                                  ACE_ENV_ARG_DECL);
}



// Resets the aggregate QoS information for the given operation.

ACE_INLINE void
TAO_Metrics_ReportingUpcallMonitor::reset_statistics (RtecScheduler::handle_t handle
                                                      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::INTERNAL_7,
                     Metrics::INTERNAL_8))
{
  monitor_.reset_statistics (handle
                             ACE_ENV_ARG_DECL);
}


// Reports the aggregate QoS statistics to the logger.

ACE_INLINE void
TAO_Metrics_ReportingUpcallMonitor::report_aggregate_QoS (
      Metrics::QoSLogger_ptr logger,
      Metrics::Time interval
      ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     Metrics::NIL_LOGGER,
                     Metrics::INTERNAL_6))
{
  if (CORBA::is_nil (logger))
    {
      ACE_THROW (Metrics::NIL_LOGGER ());
    }

  Metrics::QoSParameter_Set qos_set;
  u_int set_length = 1;

  // First, look at made map handles
  MONITOR_MAP_ITERATOR iter (monitor_.made_map ());
  for (; iter.done () == 0; ++iter, ++set_length)
    {
      CORBA::ULong missed_count;
      if (monitor_.missed_map ().find ((*iter).ext_id_, missed_count) < 0)
        {
          missed_count = 0;
        }

      qos_set.length (set_length);

      qos_set [set_length - 1].entry_point = (const char *) "MONITOR MADE_MAP_OP";
      qos_set [set_length - 1].handle = (*iter).ext_id_;
      qos_set [set_length - 1].deadlines_made = (*iter).int_id_;
      qos_set [set_length - 1].deadlines_missed = missed_count;
      qos_set [set_length - 1].operations_cancelled = 0;
      qos_set [set_length - 1].is_hrt = 0;
    }

  // Then, find missed map handles with no made map entry.
  MONITOR_MAP_ITERATOR missed_iter (monitor_.missed_map ());
  for (; missed_iter.done () == 0; ++missed_iter)
    {
      CORBA::ULong made_count;
      if (monitor_.made_map ().find ((*missed_iter).ext_id_, made_count) < 0)
        {
          qos_set.length (set_length);

          qos_set [set_length - 1].entry_point = (const char *) "MONITOR MISS_MAP_OP";
          qos_set [set_length - 1].handle = (*missed_iter).ext_id_;
          qos_set [set_length - 1].deadlines_made = 0;
          qos_set [set_length - 1].deadlines_missed = (*missed_iter).int_id_;
          qos_set [set_length - 1].operations_cancelled = 0;
          qos_set [set_length - 1].is_hrt = 0;

          ++set_length;
        }
    }

  logger->log_aggregate_QoS (qos_set, interval);
}

#endif /* METRICS_UPCALL_MONITOR_I */