summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Metrics/Metrics_Logger.h
blob: 1d63dbbdeaf817417a8ce1222efd4edeaede9b8d (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
// $Id$

#ifndef METRICS_LOGGER_H
#define METRICS_LOGGER_H

#if ! defined (VXWORKS)

// Comment out both of these to disable output
#  define METRICS_LOGGER_ERROR_OUTPUT_ENABLED
#  define METRICS_LOGGER_DEBUG_OUTPUT_ENABLED

#endif /* ! VXWORKS */

// Comment this out to disable event passing
#define TAO_METRICS_LOGGER_SENDS_EVENTS

#include "ace/OS.h"
#include "ace/Task.h"
#include "ace/Singleton.h"

#include "tao/TAO.h"

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

#include "Metrics_Utils.h"

#if defined (METRICS_LOGGER_SENDS_EVENTS)
#include "MetricsC.h"
#include "DOVE_Supplier.h"
#endif /* METRICS_LOGGER_SENDS_EVENTS */

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

class TAO_ORBSVCS_Export TAO_Metrics_Logger_Data
{
  // = TITLE
  //   Defines a class for logger data.
  //
  // = DESCRIPTION
  //   This class is used to transfer metrics data to the logger class.
public:

  enum LOGGER_DATA_TYPE {QOS_TYPE, TIMEPROBE_TYPE, BANNER_TYPE};

  TAO_Metrics_Logger_Data (LOGGER_DATA_TYPE data_type,
                    Metrics::Time interval = ORBSVCS_Time::zero ())
    : data_type_ (data_type),
      interval_ (interval),
      qos_params_ (0),
      timeprobe_params_ (0),
      banner_ (0)
    {
    }
  // Constructor.

  ~TAO_Metrics_Logger_Data ()
    {
      delete qos_params_;
      delete timeprobe_params_;
      delete banner_;
    }
  // Destructor.

  LOGGER_DATA_TYPE data_type_;
  // Identifies type of data.

  Metrics::Time interval_;
  // Time interval over which data were collected.

  Metrics::QoSParameter_Set * qos_params_;
  // Points to a QoS parameter data set.

  Metrics::TimeprobeParameter_Set * timeprobe_params_;
  // Points to a timeprobe data set.

  char * banner_;
  // Banner for entry in the log and/or visualization stream.
};



class TAO_ORBSVCS_Export TAO_Metrics_Logger
  : public ACE_Task<ACE_MT_SYNCH>, public POA_Metrics::QoSLogger
  // = TITLE
  //   This class implements a Metrics QoS logger.
  //
  // = DESCRIPTION
  //   This class allows clients to log monitored QoS.
{
public:

  typedef ACE_Hash_Map_Manager_Ex<CORBA::ULong,
	                          CORBA::String_var *,
                                  ACE_Hash<CORBA::ULong>,
                                  ACE_Equal_To<CORBA::ULong>,
                                  ACE_Null_Mutex> PROBE_NAME_MAP;
  // Type of map used for O(1) lookup of probe names.

  typedef ACE_Hash_Map_Entry<CORBA::ULong, CORBA::String_var> PROBE_NAME_MAP_ENTRY;
  // Type of map used for O(1) lookup of RT_Infos by their handles.

  TAO_Metrics_Logger (int generate_events = 0, int generate_log = 0, int generate_export_file = 1, const char *log_filename = 0);
  // Default constructor.

  virtual ~TAO_Metrics_Logger ();
  // Destructor.

  virtual int svc (void);
  // Active object loop for processing logged data.

  void send_banner (const char *banner,
                    CORBA::Environment &ACE_TRY_ENV = 
                        CORBA::Environment::default_environment ());
  // Sends a banner to be written to the log file and to the visualization browser.

  void process_banner (const char *banner);
  // Writes banner to the log file and/or to the visualization browser.

  void log_aggregate_QoS (const Metrics::QoSParameter_Set & qos_params,
                          Metrics::Time interval,
                          CORBA::Environment &ACE_TRY_ENV = 
                            CORBA::Environment::default_environment ());
  // Reports the aggregate QoS information for all operations
  // to the passed QoS logger.

  void process_aggregate_QoS (const Metrics::QoSParameter_Set & qos_params,
                              Metrics::Time interval);
  // Processes the aggregate QoS information for all operations
  // to the passed QoS logger.

  void set_identities (const Metrics::ProbeIdentity_Set & probe_identities,
                       CORBA::Environment &ACE_TRY_ENV = 
                         CORBA::Environment::default_environment ());
  // Binds the names of various timeprobes to their identifiers so 
  // that ids alone can be used (for efficiency) in passing data.

  void set_identity (const Metrics::ProbeIdentity_t & probe_identity,
                     CORBA::Environment &ACE_TRY_ENV = 
                       CORBA::Environment::default_environment ());
  // Binds the names of various timeprobes to their identifiers so 
  // that ids alone can be used (for efficiency) in passing data.

  void log_timeprobe_data (const Metrics::TimeprobeParameter_Set & timeprobe_params,
                           Metrics::Time interval,
                           CORBA::Environment &ACE_TRY_ENV = 
                             CORBA::Environment::default_environment ());
  // Reports timeprobe data collected since last run.

  void process_timeprobe_data (const Metrics::TimeprobeParameter_Set & timeprobe_params,
                               Metrics::Time interval);
  // Processes timeprobe data collected since last run.

protected:

  int generate_events_;
  // Indicates whether or not to generate events for displays.

  int generate_log_;
  // Indicates whether or not to generate a text log.

  int generate_totals_;
  // Indicates whether information of totals are logged.

  int generate_export_file_;
  // Indicates whether information of totals are logged.

  //DCL:Move code here to remove Linux compiler warning
  const char *log_filename_;
  // Name of the text log file (if any)

  int log_started_;
  // Indicates whether or not the log has been started already.

  FILE *log_file_;
  // Handle to the text log file (if any).

  FILE *export_file_;
  // Handle to the excel export log file (if any).

  PROBE_NAME_MAP probe_name_map_;
  // Maps probe ids to their names.

#if defined (METRICS_LOGGER_SENDS_EVENTS)
  DOVE_Supplier dove_supplier_;
  // DOVE Event supplier.

  Metrics::QoSData qos_data_;
  // QoS data structure.

  Metrics::UtilData util_data_;
  // Utilization data structure.

#endif /* METRICS_LOGGER_SENDS_EVENTS */

  // Only write the file once every OPEN_CLOSE_BANNER_CYCLE banner
  // changes
  int saveFileCnt_;
};

typedef ACE_Singleton<Metrics::QoSLogger_var, ACE_SYNCH_MUTEX>
TAO_METRICS_LOGGER_REF_SINGLETON;

typedef ACE_Singleton<TAO_Metrics_Logger, ACE_SYNCH_MUTEX>
TAO_METRICS_LOGGER_SINGLETON;


#endif /* METRICS_LOGGER_H */