📄 metrics_logger.cpp
字号:
// Metrics_Logger.cpp,v 1.3 2003/07/21 21:36:26 storri Exp
#include "Metrics_Logger.h"
#include "ace/Auto_Ptr.h"
#include "ace/ace_wchar.h"
ACE_RCSID(Metrics_Logger, Metrics_Logger, "Metrics_Logger.cpp,v 1.3 2003/07/21 21:36:26 storri Exp")
#if defined (ACE_METRICS_COLLECTION)
#if defined (ACE_ENABLE_TIMEPROBES) && defined (ACE_COMPILE_TIMEPROBES)
const int OPEN_CLOSE_BANNER_CYCLE = 4;
//////////////////////////////
// class TAO_Metrics_Logger //
//////////////////////////////
// Default constructor.
TAO_Metrics_Logger::TAO_Metrics_Logger (int generate_events,
int generate_log,
int generate_export_file,
const char *log_filename)
: generate_events_ (generate_events),
#ifdef VXWORKS
generate_log_ (1),
log_filename_ ("logger.txt"),
#else
generate_log_ (generate_log),
log_filename_ (log_filename),
#endif
generate_totals_(0),
generate_export_file_(generate_export_file),
log_started_ (0),
log_file_ (stdout),
export_file_(stdout),
saveFileCnt_(0)
{
#ifdef VXWORKS
taskPrioritySet( taskIdSelf(), 145 );
#endif
#if defined (METRICS_LOGGER_SENDS_EVENTS)
if (this->generate_events_)
{
// Connect the underlying DOVE event supplier.
if (this->dove_supplier_.connect () < 0)
{
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR, "failed to connect DOVE event supplier\n"));
#endif
this->generate_events_ = 0;
}
}
#endif /* METRICS_LOGGER_SENDS_EVENTS */
if (generate_log_)
{
if (log_filename_)
{
log_file_ = ACE_OS::fopen (log_filename_, "w+");
if (log_file_ == NULL)
{
generate_log_ = 0;
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR,
"Logger failed to open log file %s\n",
log_filename_));
#endif
return;
}
if (generate_export_file_)
{
export_file_ = ACE_OS::fopen ("remote_logger_export.excel", "w+");
if (export_file_ == NULL)
{
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR, "Logger failed to open log file %s\n", log_filename_));
#endif
return;
}
}
log_started_ = 1;
}
// Write a start of logging session message.
time_t current_time = ACE_OS::time ();
ACE_OS::fprintf (log_file_,
"\n\nTAO_Metrics Metrics Logging Session: %s\n\n",
ACE_OS::ctime (& current_time));
ACE_OS::fprintf (export_file_,
"\n\nTAO_Metrics Metrics Logging Session: %s\n\n",
ACE_OS::ctime (& current_time));
if (log_filename_)
{
ACE_OS::fflush (log_file_);
ACE_OS::fflush (export_file_);
// ACE_OS::fclose (log_file_);
}
}
}
// Destructor.
TAO_Metrics_Logger::~TAO_Metrics_Logger ()
{
if (generate_log_)
{
if (log_filename_)
{
// log_file_ = ACE_OS::fopen (log_filename_, "a+");
}
ACE_OS::fprintf (log_file_, "\n\n");
ACE_OS::fflush (log_file_);
ACE_OS::fprintf (export_file_, "\n\n");
ACE_OS::fflush (export_file_);
if (log_filename_)
{
// ACE_OS::fclose (log_file_);
}
}
#if defined (METRICS_LOGGER_SENDS_EVENTS)
if (this->generate_events_)
{
this->dove_supplier_.disconnect ();
}
#endif /* METRICS_LOGGER_SENDS_EVENTS */
}
// Active object loop for processing logged data.
int
TAO_Metrics_Logger::svc (void)
{
ACE_Message_Block *mb;
// Loop forever.
while (1)
if (this->getq (mb) < 0)
{
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR,
"(%P|%t) getq failed in TAO_Metrics_Logger::svc"));
#endif
return -1;
}
else if (! mb)
{
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR,
"(%P|%t) null message block pointer in TAO_Metrics_Logger::svc"));
#endif
return -1;
}
else if (! mb->rd_ptr ())
{
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR,
"(%P|%t) null message block pointer in TAO_Metrics_Logger::svc"));
#endif
return -1;
}
else
{
// Process message.
TAO_Metrics_Logger_Data *data = (TAO_Metrics_Logger_Data *) mb->rd_ptr ();
switch (data->data_type_)
{
case TAO_Metrics_Logger_Data::QOS_TYPE:
this->process_aggregate_QoS (*data->qos_params_, data->interval_);
delete data;
delete mb;
break;
case TAO_Metrics_Logger_Data::TIMEPROBE_TYPE:
this->process_timeprobe_data (*data->timeprobe_params_, data->interval_);
delete data;
delete mb;
break;
case TAO_Metrics_Logger_Data::BANNER_TYPE:
this->process_banner (data->banner_);
delete data;
delete mb;
break;
default:
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR,
"(%P|%t) unrecognized data type in TAO_Metrics_Logger::svc"));
#endif
return -1;
}
}
// Modified by BAP. Remove unreachable code.
// return 0;
}
// Sends a banner to be written to the log file and to the visualization browser.
void
TAO_Metrics_Logger::send_banner (const char *banner
ACE_ENV_ARG_DECL)
throw (CORBA::SystemException)
{
// Package up the data and put it on the task queue.
TAO_Metrics_Logger_Data *data;
ACE_NEW (data,
TAO_Metrics_Logger_Data (TAO_Metrics_Logger_Data::BANNER_TYPE));
ACE_NEW (data->banner_, char [ACE_OS::strlen (banner) + 1]);
ACE_OS::strcpy (data->banner_, banner);
ACE_Message_Block *mb;
ACE_NEW (mb,
ACE_Message_Block ((char *) data,
sizeof (TAO_Metrics_Logger_Data)));
if (this->putq (mb) < 0)
{
#if defined (METRICS_LOGGER_ERROR_OUTPUT_ENABLED)
ACE_ERROR ((LM_ERROR,
"TAO_Metrics_Logger::send_banner putq failed"));
#endif
}
}
void
TAO_Metrics_Logger::process_banner (const char *banner)
{
if (this->generate_log_)
{
if (log_filename_)
{
// log_file_ = ACE_OS::fopen (log_filename_, "a+");
}
ACE_OS::fprintf (log_file_,
"%s\n", banner);
ACE_OS::fprintf (export_file_,
"%s\n", banner);
if (log_filename_)
{
ACE_OS::fflush (log_file_);
ACE_OS::fflush (export_file_);
// Close and then reopen the file. We can't afford to open & close all of the time.
if (( saveFileCnt_++ % OPEN_CLOSE_BANNER_CYCLE) == 0 )
{
ACE_OS::fclose (log_file_);
log_file_ = ACE_OS::fopen (log_filename_, "a+");
ACE_OS::fclose (export_file_);
export_file_ = ACE_OS::fopen ("remote_logger_export.excel", "a+");
}
}
}
}
// Reports the aggregate QoS information for all operations
// to the passed QoS logger.
void
TAO_Metrics_Logger::log_aggregate_QoS (const Metrics::QoSParameter_Set & qos_params,
Metrics::Time interval
ACE_ENV_ARG_DECL)
throw (CORBA::SystemException)
{
// This is a temporary patch to eliminate this data from the log. It was
// done to bypass a long rebuild that would have been required otherwise.
// Remove this patch later. Brian Mendel
//Added to remove Linux warning (Boeing Extension)
ACE_UNUSED_ARG(qos_params);
ACE_UNUSED_ARG(interval);
// Package up the data and put it on the task queue.
#if 0
TAO_Metrics_Logger_Data *data;
ACE_NEW (data,
TAO_Metrics_Logger_Data (TAO_Metrics_Logger_Data::QOS_TYPE,
interval));
ACE_NEW (data->qos_params_,
Metrics::QoSParameter_Set (qos_params));
ACE_Message_Block *mb;
ACE_NEW (mb,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -