diff options
Diffstat (limited to 'TAO/orbsvcs/tests/InterfaceRepo/Latency_Test/Latency_Query_Client.cpp')
-rw-r--r-- | TAO/orbsvcs/tests/InterfaceRepo/Latency_Test/Latency_Query_Client.cpp | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/InterfaceRepo/Latency_Test/Latency_Query_Client.cpp b/TAO/orbsvcs/tests/InterfaceRepo/Latency_Test/Latency_Query_Client.cpp new file mode 100644 index 00000000000..824b5879aad --- /dev/null +++ b/TAO/orbsvcs/tests/InterfaceRepo/Latency_Test/Latency_Query_Client.cpp @@ -0,0 +1,257 @@ +// -*- C++ -*- +// $Id$ + +#include "Latency_Query_Client.h" +#include "ace/Get_Opt.h" +#include "ace/High_Res_Timer.h" +#include "ace/Stats.h" +#include "ace/Sample_History.h" + +ACE_RCSID (Latency_Test, + Latency_Query_Client, + "$Id$") + +const CORBA::ULong DEFAULT_NUMCALLS = 250; + +Latency_Query_Client::Latency_Query_Client (void) + : debug_ (0), + do_dump_history_ (0), + iterations_ (DEFAULT_NUMCALLS) +{ +} + +Latency_Query_Client::~Latency_Query_Client (void) +{ +} + +int +Latency_Query_Client::init (int argc, + char *argv[]) +{ + ACE_TRY_NEW_ENV + { + this->orb_ = CORBA::ORB_init (argc, + argv, + 0 + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + int retval = this->parse_args (argc, + argv); + + if (retval != 0) + { + return retval; + } + + CORBA::Object_var object = + this->orb_->resolve_initial_references ("InterfaceRepository" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (object.in ())) + { + ACE_ERROR_RETURN (( + LM_ERROR, + "Null objref from resolve_initial_references\n" + ), + -1 + ); + } + + this->repo_ = + CORBA::Repository::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (this->repo_.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "CORBA::Repository::_narrow failed\n"), + -1); + } + + retval = this->populate_ifr (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (retval != 0) + { + return retval; + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Latency_Query_Client::init:"); + return -1; + } + ACE_ENDTRY; + + return 0; +} + +int +Latency_Query_Client::run (void) +{ + CORBA::DefinitionKind dk; + + ACE_TRY_NEW_ENV + { + for (int j = 0; j < 100; ++j) + { + ACE_hrtime_t start = 0; + dk = this->tdef_->def_kind (ACE_ENV_SINGLE_ARG_PARAMETER); + + if (dk != CORBA::dk_Alias) + { + return -1; + } + + ACE_TRY_CHECK; + } + + ACE_Sample_History history (this->iterations_); + ACE_hrtime_t test_start = ACE_OS::gethrtime (); + + for (int i = 0; i < this->iterations_; ++i) + { + ACE_hrtime_t start = ACE_OS::gethrtime (); + + dk = this->tdef_->def_kind (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_hrtime_t now = ACE_OS::gethrtime (); + history.sample (now - start); + } + + ACE_hrtime_t test_end = ACE_OS::gethrtime (); + + ACE_DEBUG ((LM_DEBUG, + "test finished\n")); + ACE_DEBUG ((LM_DEBUG, + "High resolution timer calibration....")); + ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor (); + ACE_DEBUG ((LM_DEBUG, + "done\n")); + + if (this->do_dump_history_) + { + history.dump_samples ("HISTORY", gsf); + } + + ACE_Basic_Stats stats; + history.collect_basic_stats (stats); + stats.dump_results ("Total", gsf); + + ACE_Throughput_Stats::dump_throughput ("Total", + gsf, + test_end - test_start, + stats.samples_count ()); + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Latency_Query_Client::run:"); + return -1; + } + ACE_ENDTRY; + + return 0; +} + +Latency_Query_Client::parse_args (int argc, + char *argv[]) +{ + ACE_Get_Opt opts (argc, argv, "dhi:"); + int c; + int result = 0; + + while ((c = opts ()) != -1) + switch (c) + { + case 'd': + this->debug_ = 1; + break; + case 'h': + this->do_dump_history_ = 1; + break; + case 'i': + result = ACE_OS::atoi (opts.opt_arg ()); + + if (result > 0) + { + this->iterations_ = result; + } + + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-i iterations]" + "\n", + argv [0]), + -1); + } + + return 0; +} + +int +Latency_Query_Client::populate_ifr (ACE_ENV_SINGLE_ARG_DECL) +{ + CORBA::Contained_var irobj = this->repo_->lookup_id ("IDL:longtype:1.0" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (! CORBA::is_nil (irobj.in ())) + { + this->tdef_ = CORBA::AliasDef::_narrow (irobj.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil (this->tdef_.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Latency_Query_Client::populate_ifr - " + "AliasDef::_narrow returned null\n"), + -1); + } + + return 0; + } + + CORBA::PrimitiveDef_var longdef = + this->repo_->get_primitive (CORBA::pk_long + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil (longdef.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Latency_Query_Client::populate_ifr - " + "get_primitive returned null\n"), + -1); + } + + this->tdef_ = + this->repo_->create_alias ("IDL:longtype:1.0", + "longtype", + "1.0", + longdef.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil (this->tdef_.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Latency_Query_Client::populate_ifr - " + "create_alias returned null\n"), + -1); + } + + return 0; +} + |