Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / InterfaceRepo / Latency_Test / Latency_Query_Client.cpp
blobb9353a4913c028aa8d2a2e68cad3f72194e16db4
1 // -*- C++ -*-
2 #include "Latency_Query_Client.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Stats.h"
6 #include "ace/Throughput_Stats.h"
7 #include "ace/Sample_History.h"
9 const CORBA::ULong DEFAULT_NUMCALLS = 20000;
11 Latency_Query_Client::Latency_Query_Client (void)
12 : debug_ (false),
13 do_dump_history_ (0),
14 iterations_ (DEFAULT_NUMCALLS)
18 Latency_Query_Client::~Latency_Query_Client (void)
22 int
23 Latency_Query_Client::init (int argc,
24 ACE_TCHAR *argv[])
26 try
28 this->orb_ = CORBA::ORB_init (argc, argv);
30 int retval = this->parse_args (argc, argv);
32 if (retval != 0)
34 return retval;
37 CORBA::Object_var object =
38 this->orb_->resolve_initial_references ("InterfaceRepository");
40 if (CORBA::is_nil (object.in ()))
42 ACE_ERROR_RETURN ((
43 LM_ERROR,
44 "Null objref from resolve_initial_references\n"
50 this->repo_ =
51 CORBA::Repository::_narrow (object.in ());
53 if (CORBA::is_nil (this->repo_.in ()))
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "CORBA::Repository::_narrow failed\n"),
57 -1);
60 retval = this->populate_ifr ();
62 if (retval != 0)
64 return retval;
67 catch (const CORBA::Exception& ex)
69 ex._tao_print_exception ("Latency_Query_Client::init:");
70 return -1;
73 return 0;
76 int
77 Latency_Query_Client::run (void)
79 // CORBA::DefinitionKind dk;
80 CORBA::AttributeMode am;
82 try
84 for (int j = 0; j < 100; ++j)
86 am = this->attr_->mode ();
88 if (am != CORBA::ATTR_NORMAL)
90 return -1;
94 ACE_Sample_History history (this->iterations_);
95 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
97 for (CORBA::ULong i = 0; i < this->iterations_; ++i)
99 ACE_hrtime_t start = ACE_OS::gethrtime ();
101 am = this->attr_->mode ();
103 ACE_hrtime_t now = ACE_OS::gethrtime ();
104 history.sample (now - start);
107 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
109 if (this->debug_)
111 ACE_DEBUG ((LM_DEBUG,
112 "test finished\n"));
113 ACE_DEBUG ((LM_DEBUG,
114 "High resolution timer calibration...."));
115 ACE_High_Res_Timer::global_scale_factor_type gsf =
116 ACE_High_Res_Timer::global_scale_factor ();
117 ACE_DEBUG ((LM_DEBUG,
118 "done\n"));
120 if (this->do_dump_history_)
122 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
125 ACE_Basic_Stats stats;
126 history.collect_basic_stats (stats);
127 stats.dump_results (ACE_TEXT("Total"), gsf);
129 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
130 gsf,
131 test_end - test_start,
132 stats.samples_count ());
135 catch (const CORBA::Exception& ex)
137 ex._tao_print_exception ("Latency_Query_Client::run:");
138 return -1;
141 return 0;
145 Latency_Query_Client::parse_args (int argc,
146 ACE_TCHAR *argv[])
148 ACE_Get_Opt opts (argc, argv, ACE_TEXT("dhi:"));
149 int c;
150 int result = 0;
152 while ((c = opts ()) != -1)
154 switch (c)
156 case 'd':
157 this->debug_ = true;
158 break;
159 case 'h':
160 this->do_dump_history_ = true;
161 break;
162 case 'i':
163 result = ACE_OS::atoi (opts.opt_arg ());
165 if (result > 0)
167 this->iterations_ = result;
170 break;
171 case '?':
172 default:
173 ACE_ERROR_RETURN ((LM_ERROR,
174 "usage: %s"
175 " [-d]"
176 " [-i iterations]"
177 "\n",
178 argv [0]),
179 -1);
183 return 0;
187 Latency_Query_Client::populate_ifr (void)
189 CORBA::Contained_var irobj = this->repo_->lookup_id ("IDL:dummy/attr:1.0");
191 if (! CORBA::is_nil (irobj.in ()))
193 this->attr_ = CORBA::AttributeDef::_narrow (irobj.in ());
195 if (CORBA::is_nil (this->attr_.in ()))
197 ACE_ERROR_RETURN ((LM_ERROR,
198 "Latency_Query_Client::populate_ifr - "
199 "AttributeDef::_narrow returned null\n"),
200 -1);
203 return 0;
206 CORBA::InterfaceDefSeq in_bases (0);
207 in_bases.length (0);
209 CORBA::InterfaceDef_var iface =
210 this->repo_->create_interface ("IDL:dummy:1.0",
211 "dummy",
212 "1.0",
213 in_bases);
215 CORBA::PrimitiveDef_var p_long =
216 this->repo_->get_primitive (CORBA::pk_long);
218 this->attr_ =
219 iface->create_attribute ("IDL:dummt/attr:1.0",
220 "attr",
221 "1.0",
222 p_long.in (),
223 CORBA::ATTR_NORMAL);
225 return 0;