Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / InterfaceRepo / Latency_Test / Latency_Query_Client.cpp
blob1535d3bc8e6b05489562b3d7eafd608db296dd59
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 ()
12 : debug_ (false),
13 do_dump_history_ (0),
14 iterations_ (DEFAULT_NUMCALLS)
18 Latency_Query_Client::~Latency_Query_Client ()
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"
45 ), -1);
48 this->repo_ =
49 CORBA::Repository::_narrow (object.in ());
51 if (CORBA::is_nil (this->repo_.in ()))
53 ACE_ERROR_RETURN ((LM_ERROR,
54 "CORBA::Repository::_narrow failed\n"),
55 -1);
58 retval = this->populate_ifr ();
60 if (retval != 0)
62 return retval;
65 catch (const CORBA::Exception& ex)
67 ex._tao_print_exception ("Latency_Query_Client::init:");
68 return -1;
71 return 0;
74 int
75 Latency_Query_Client::run ()
77 // CORBA::DefinitionKind dk;
78 CORBA::AttributeMode am;
80 try
82 for (int j = 0; j < 100; ++j)
84 am = this->attr_->mode ();
86 if (am != CORBA::ATTR_NORMAL)
88 return -1;
92 ACE_Sample_History history (this->iterations_);
93 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
95 for (CORBA::ULong i = 0; i < this->iterations_; ++i)
97 ACE_hrtime_t start = ACE_OS::gethrtime ();
99 am = this->attr_->mode ();
101 ACE_hrtime_t now = ACE_OS::gethrtime ();
102 history.sample (now - start);
105 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
107 if (this->debug_)
109 ACE_DEBUG ((LM_DEBUG,
110 "test finished\n"));
111 ACE_DEBUG ((LM_DEBUG,
112 "High resolution timer calibration...."));
113 ACE_High_Res_Timer::global_scale_factor_type gsf =
114 ACE_High_Res_Timer::global_scale_factor ();
115 ACE_DEBUG ((LM_DEBUG,
116 "done\n"));
118 if (this->do_dump_history_)
120 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
123 ACE_Basic_Stats stats;
124 history.collect_basic_stats (stats);
125 stats.dump_results (ACE_TEXT("Total"), gsf);
127 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
128 gsf,
129 test_end - test_start,
130 stats.samples_count ());
133 catch (const CORBA::Exception& ex)
135 ex._tao_print_exception ("Latency_Query_Client::run:");
136 return -1;
139 return 0;
143 Latency_Query_Client::parse_args (int argc,
144 ACE_TCHAR *argv[])
146 ACE_Get_Opt opts (argc, argv, ACE_TEXT("dhi:"));
147 int c;
148 int result = 0;
150 while ((c = opts ()) != -1)
152 switch (c)
154 case 'd':
155 this->debug_ = true;
156 break;
157 case 'h':
158 this->do_dump_history_ = true;
159 break;
160 case 'i':
161 result = ACE_OS::atoi (opts.opt_arg ());
163 if (result > 0)
165 this->iterations_ = result;
168 break;
169 case '?':
170 default:
171 ACE_ERROR_RETURN ((LM_ERROR,
172 "usage: %s"
173 " [-d]"
174 " [-i iterations]"
175 "\n",
176 argv [0]),
177 -1);
181 return 0;
185 Latency_Query_Client::populate_ifr ()
187 CORBA::Contained_var irobj = this->repo_->lookup_id ("IDL:dummy/attr:1.0");
189 if (! CORBA::is_nil (irobj.in ()))
191 this->attr_ = CORBA::AttributeDef::_narrow (irobj.in ());
193 if (CORBA::is_nil (this->attr_.in ()))
195 ACE_ERROR_RETURN ((LM_ERROR,
196 "Latency_Query_Client::populate_ifr - "
197 "AttributeDef::_narrow returned null\n"),
198 -1);
201 return 0;
204 CORBA::InterfaceDefSeq in_bases (0);
205 in_bases.length (0);
207 CORBA::InterfaceDef_var iface =
208 this->repo_->create_interface ("IDL:dummy:1.0",
209 "dummy",
210 "1.0",
211 in_bases);
213 CORBA::PrimitiveDef_var p_long =
214 this->repo_->get_primitive (CORBA::pk_long);
216 this->attr_ =
217 iface->create_attribute ("IDL:dummt/attr:1.0",
218 "attr",
219 "1.0",
220 p_long.in (),
221 CORBA::ATTR_NORMAL);
223 return 0;