1 #include "tao/DynamicInterface/Request.h"
2 #include "tao/Strategies/advanced_resource.h"
3 #include "tao/AnyTypeCode/TypeCode_Constants.h"
4 #include "tao/AnyTypeCode/Any.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/High_Res_Timer.h"
10 #include "ace/Sched_Params.h"
11 #include "ace/Stats.h"
12 #include "ace/Throughput_Stats.h"
13 #include "ace/Sample_History.h"
14 #include "ace/OS_NS_errno.h"
16 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
17 int niterations
= 100;
18 int do_dump_history
= 0;
22 const ACE_TCHAR
*data_type
= ACE_TEXT("octet");
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:s:hxk:i:"));
30 while ((c
= get_opts ()) != -1)
34 data_type
= get_opts
.opt_arg ();
36 if (ACE_OS::strcmp (data_type
, ACE_TEXT("octet")) != 0 &&
37 ACE_OS::strcmp (data_type
, ACE_TEXT("char")) != 0 &&
38 ACE_OS::strcmp (data_type
, ACE_TEXT("long")) != 0 &&
39 ACE_OS::strcmp (data_type
, ACE_TEXT("short")) != 0 &&
40 ACE_OS::strcmp (data_type
, ACE_TEXT("double")) != 0 &&
41 ACE_OS::strcmp (data_type
, ACE_TEXT("longlong")) != 0)
46 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
58 ior
= get_opts
.opt_arg ();
62 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
67 ACE_ERROR_RETURN ((LM_ERROR
,
73 "-x (disable shutdown) "
78 // Indicates successful parsing of the command line
84 test_octet_seq (const CORBA::Object_var object
)
86 ACE_Sample_History
history (niterations
);
88 Test::octet_load
ol (sz
);
91 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
92 for (int i
= 0; i
< niterations
; ++i
)
94 ACE_hrtime_t start
= ACE_OS::gethrtime ();
95 Test::Timestamp start_time
= static_cast <Test::Timestamp
> (start
);
97 CORBA::Request_var request
=
98 object
->_request ("test_octet_method");
100 request
->add_in_arg("octet_load") <<= ol
;
101 request
->add_in_arg("send_time") <<= start_time
;
103 request
->set_return_type (CORBA::_tc_ulonglong
);
106 ACE_hrtime_t now
= ACE_OS::gethrtime ();
107 history
.sample (now
- start
);
110 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
112 ACE_DEBUG ((LM_DEBUG
, "test finished\n"));
114 ACE_DEBUG ((LM_DEBUG
, "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
, "done\n"));
121 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
124 ACE_Basic_Stats stats
;
125 history
.collect_basic_stats (stats
);
126 stats
.dump_results (ACE_TEXT("Total"), gsf
);
128 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
129 test_end
- test_start
,
130 stats
.samples_count ());
134 test_long_seq (const CORBA::Object_var object
)
136 ACE_Sample_History
history (niterations
);
138 Test::long_load
ll (sz
);
141 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
142 for (int i
= 0; i
< niterations
; ++i
)
144 ACE_hrtime_t start
= ACE_OS::gethrtime ();
146 CORBA::Request_var request
=
147 object
->_request ("test_long_method");
149 request
->add_in_arg("long_load") <<= ll
;
150 request
->add_in_arg("send_time") <<= static_cast <Test::Timestamp
> (start
);
152 request
->set_return_type (CORBA::_tc_ulonglong
);
155 ACE_hrtime_t now
= ACE_OS::gethrtime ();
156 history
.sample (now
- start
);
159 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
161 ACE_DEBUG ((LM_DEBUG
, "test finished\n"));
163 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
164 ACE_High_Res_Timer::global_scale_factor_type gsf
=
165 ACE_High_Res_Timer::global_scale_factor ();
166 ACE_DEBUG ((LM_DEBUG
, "done\n"));
170 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
173 ACE_Basic_Stats stats
;
174 history
.collect_basic_stats (stats
);
175 stats
.dump_results (ACE_TEXT("Total"), gsf
);
177 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
178 test_end
- test_start
,
179 stats
.samples_count ());
183 test_short_seq (const CORBA::Object_var object
)
185 ACE_Sample_History
history (niterations
);
187 Test::short_load
sl (sz
);
190 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
191 for (int i
= 0; i
< niterations
; ++i
)
193 ACE_hrtime_t start
= ACE_OS::gethrtime ();
195 CORBA::Request_var request
=
196 object
->_request ("test_short_method");
198 request
->add_in_arg("short_load") <<= sl
;
199 request
->add_in_arg("send_time") <<= static_cast <Test::Timestamp
> (start
);
201 request
->set_return_type (CORBA::_tc_ulonglong
);
204 ACE_hrtime_t now
= ACE_OS::gethrtime ();
205 history
.sample (now
- start
);
208 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
210 ACE_DEBUG ((LM_DEBUG
, "test finished\n"));
212 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
213 ACE_High_Res_Timer::global_scale_factor_type gsf
=
214 ACE_High_Res_Timer::global_scale_factor ();
215 ACE_DEBUG ((LM_DEBUG
, "done\n"));
219 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
222 ACE_Basic_Stats stats
;
223 history
.collect_basic_stats (stats
);
224 stats
.dump_results (ACE_TEXT("Total"), gsf
);
226 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
227 test_end
- test_start
,
228 stats
.samples_count ());
232 test_char_seq (const CORBA::Object_var object
)
234 ACE_Sample_History
history (niterations
);
236 Test::char_load
cl (sz
);
239 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
240 for (int i
= 0; i
< niterations
; ++i
)
242 ACE_hrtime_t start
= ACE_OS::gethrtime ();
244 CORBA::Request_var request
=
245 object
->_request ("test_char_method");
247 request
->add_in_arg("char_load") <<= cl
;
248 request
->add_in_arg("send_time") <<= static_cast <Test::Timestamp
> (start
);
250 request
->set_return_type (CORBA::_tc_ulonglong
);
253 ACE_hrtime_t now
= ACE_OS::gethrtime ();
254 history
.sample (now
- start
);
257 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
259 ACE_DEBUG ((LM_DEBUG
, "test finished\n"));
261 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
262 ACE_High_Res_Timer::global_scale_factor_type gsf
=
263 ACE_High_Res_Timer::global_scale_factor ();
264 ACE_DEBUG ((LM_DEBUG
, "done\n"));
268 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
271 ACE_Basic_Stats stats
;
272 history
.collect_basic_stats (stats
);
273 stats
.dump_results (ACE_TEXT("Total"), gsf
);
275 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
276 test_end
- test_start
,
277 stats
.samples_count ());
281 test_double_seq (const CORBA::Object_var object
)
283 ACE_Sample_History
history (niterations
);
285 Test::double_load
dl (sz
);
288 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
289 for (int i
= 0; i
< niterations
; ++i
)
291 ACE_hrtime_t start
= ACE_OS::gethrtime ();
293 CORBA::Request_var request
=
294 object
->_request ("test_double_method");
296 request
->add_in_arg("double_load") <<= dl
;
297 request
->add_in_arg("send_time") <<= static_cast <Test::Timestamp
> (start
);
299 request
->set_return_type (CORBA::_tc_ulonglong
);
302 ACE_hrtime_t now
= ACE_OS::gethrtime ();
303 history
.sample (now
- start
);
306 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
308 ACE_DEBUG ((LM_DEBUG
, "test finished\n"));
310 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
311 ACE_High_Res_Timer::global_scale_factor_type gsf
=
312 ACE_High_Res_Timer::global_scale_factor ();
313 ACE_DEBUG ((LM_DEBUG
, "done\n"));
317 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
320 ACE_Basic_Stats stats
;
321 history
.collect_basic_stats (stats
);
322 stats
.dump_results (ACE_TEXT("Total"), gsf
);
324 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
325 test_end
- test_start
,
326 stats
.samples_count ());
330 test_longlong_seq (const CORBA::Object_var object
)
332 ACE_Sample_History
history (niterations
);
334 Test::longlong_load
ll (sz
);
337 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
338 for (int i
= 0; i
< niterations
; ++i
)
340 ACE_hrtime_t start
= ACE_OS::gethrtime ();
342 CORBA::Request_var request
=
343 object
->_request ("test_longlong_method");
345 request
->add_in_arg("longlong_load") <<= ll
;
346 request
->add_in_arg("send_time") <<= static_cast <Test::Timestamp
> (start
);
348 request
->set_return_type (CORBA::_tc_ulonglong
);
351 ACE_hrtime_t now
= ACE_OS::gethrtime ();
352 history
.sample (now
- start
);
355 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
357 ACE_DEBUG ((LM_DEBUG
, "test finished\n"));
359 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
360 ACE_High_Res_Timer::global_scale_factor_type gsf
=
361 ACE_High_Res_Timer::global_scale_factor ();
362 ACE_DEBUG ((LM_DEBUG
, "done\n"));
366 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
369 ACE_Basic_Stats stats
;
370 history
.collect_basic_stats (stats
);
371 stats
.dump_results (ACE_TEXT("Total"), gsf
);
373 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
374 test_end
- test_start
,
375 stats
.samples_count ());
379 // The main() function starts here
382 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
385 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
386 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
387 // Enable FIFO scheduling
389 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
391 ACE_SCOPE_PROCESS
)) != 0)
393 if (ACE_OS::last_error () == EPERM
)
395 ACE_DEBUG ((LM_DEBUG
,
396 "client (%P|%t): user is not superuser, "
397 "test runs in time-shared class\n"));
400 ACE_ERROR ((LM_ERROR
,
401 "client (%P|%t): sched_params failed\n"));
407 CORBA::ORB_init (argc
, argv
);
409 if (parse_args (argc
, argv
) != 0)
412 CORBA::Object_var object
=
413 orb
->string_to_object (ior
);
415 if (CORBA::is_nil (object
.in ()))
417 ACE_ERROR_RETURN ((LM_ERROR
,
418 "Nil CORBA::Object reference <%s>\n",
425 for (int j
= 0; j
< 100; ++j
)
427 CORBA::Request_var request
=
428 object
->_request ("test_octet_method");
430 Test::Timestamp dummy
= 0;
431 request
->add_in_arg("octet_load") <<= oc
;
432 request
->add_in_arg("send_time") <<= dummy
;
434 request
->set_return_type (CORBA::_tc_ulonglong
);
438 // Test various sequence types
440 if (ACE_OS::strcmp (data_type
, ACE_TEXT("octet")) == 0 )
442 test_octet_seq (object
);
444 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("char")) == 0)
446 test_char_seq (object
);
448 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("long")) == 0)
450 test_long_seq (object
);
452 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("short")) == 0)
454 test_short_seq (object
);
456 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("double")) == 0)
458 test_double_seq (object
);
460 else if (ACE_OS::strcmp (data_type
, ACE_TEXT("longlong")) == 0)
462 test_longlong_seq (object
);
467 CORBA::Request_var request
=
468 object
->_request ("shutdown");
473 catch (const CORBA::Exception
& ex
)
475 ex
._tao_print_exception ("Exception caught:");