Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / Deferred / client.cpp
blob2049494d33e9f44f56280b66e7634b3525ebf2a7
1 #include "tao/DynamicInterface/Request.h" /* Must come first for G++
2 3.4 or better */
4 #include "TestC.h"
6 #include "tao/Strategies/advanced_resource.h"
7 #include "tao/AnyTypeCode/TypeCode_Constants.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/Sched_Params.h"
11 #include "ace/High_Res_Timer.h"
12 #include "ace/Sched_Params.h"
13 #include "ace/Stats.h"
14 #include "ace/Throughput_Stats.h"
15 #include "ace/Sample_History.h"
16 #include "ace/OS_NS_errno.h"
18 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
19 int niterations = 1000;
20 int burst = 10;
21 int do_shutdown = 1;
22 int do_dump_history = 0;
23 int sz = 512;
25 const ACE_TCHAR *data_type = ACE_TEXT("octet");
27 int
28 parse_args (int argc, ACE_TCHAR *argv[])
30 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:s:hxk:i:b:"));
31 int c;
33 while ((c = get_opts ()) != -1)
34 switch (c)
36 case 't':
37 data_type = get_opts.opt_arg ();
39 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) != 0 &&
40 ACE_OS::strcmp (data_type, ACE_TEXT("char")) != 0 &&
41 ACE_OS::strcmp (data_type, ACE_TEXT("long")) != 0 &&
42 ACE_OS::strcmp (data_type, ACE_TEXT("short")) != 0 &&
43 ACE_OS::strcmp (data_type, ACE_TEXT("double")) != 0 &&
44 ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) != 0)
45 return -1;
46 break;
48 case 's':
49 sz = ACE_OS::atoi (get_opts.opt_arg ());
50 break;
52 case 'h':
53 do_dump_history = 1;
54 break;
56 case 'x':
57 do_shutdown = 0;
58 break;
60 case 'k':
61 ior = get_opts.opt_arg ();
62 break;
64 case 'i':
65 niterations = ACE_OS::atoi (get_opts.opt_arg ());
66 break;
68 case 'b':
69 burst = ACE_OS::atoi (get_opts.opt_arg ());
70 break;
72 case '?':
73 default:
74 ACE_ERROR_RETURN ((LM_ERROR,
75 "usage: %s "
76 "-t <datatype> "
77 "-s <size> "
78 "-k <ior> "
79 "-i <niterations> "
80 "-b <burst> "
81 "-x (disable shutdown) "
82 "-h (dump history) "
83 "\n",
84 argv [0]),
85 -1);
87 // Indicates successful parsing of the command line
88 return 0;
92 int
93 test_octet_seq (Test::Roundtrip_ptr roundtrip)
95 ACE_Sample_History history (niterations);
97 Test::octet_load ol (sz);
98 ol.length (sz);
100 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
102 CORBA::Request_var *request;
103 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
105 for (int i = 0; i < niterations; ++i)
107 int j;
109 for (j = 0; j != burst; ++j)
111 CORBA::ULongLong start = ACE_OS::gethrtime ();
113 request[j] =
114 roundtrip->_request ("test_octet_method");
116 request[j]->add_in_arg ("octet_load") <<= ol;
117 request[j]->add_in_arg ("send_time") <<= start;
118 request[j]->set_return_type (CORBA::_tc_ulonglong);
120 request[j]->send_deferred ();
123 for (j = 0; j != burst; ++j)
125 request[j]->get_response ();
127 CORBA::ULongLong retval;
128 if ((request[j]->return_value () >>= retval) == 1)
130 ACE_hrtime_t now = ACE_OS::gethrtime ();
131 history.sample (ACE_HRTIME_TO_U64(now) - retval);
135 delete[] request;
137 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
139 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
141 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
142 ACE_High_Res_Timer::global_scale_factor_type gsf =
143 ACE_High_Res_Timer::global_scale_factor ();
144 ACE_DEBUG ((LM_DEBUG, "done\n"));
146 if (do_dump_history)
148 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
151 ACE_Basic_Stats stats;
152 history.collect_basic_stats (stats);
153 stats.dump_results (ACE_TEXT("Total"), gsf);
155 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
156 test_end - test_start,
157 stats.samples_count ());
158 return 0;
163 test_long_seq (Test::Roundtrip_ptr roundtrip)
165 ACE_Sample_History history (niterations);
167 Test::long_load ll (sz);
168 ll.length (sz);
170 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
172 CORBA::Request_var *request;
173 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
175 for (int i = 0; i < niterations; ++i)
177 int j;
179 for (j = 0; j != burst; ++j)
181 CORBA::ULongLong start = ACE_OS::gethrtime ();
183 request[j] =
184 roundtrip->_request ("test_long_method");
186 request[j]->add_in_arg ("long_load") <<= ll;
187 request[j]->add_in_arg ("send_time") <<= start;
188 request[j]->set_return_type (CORBA::_tc_ulonglong);
190 request[j]->send_deferred ();
193 for (j = 0; j != burst; ++j)
195 request[j]->get_response ();
197 CORBA::ULongLong retval;
198 if ((request[j]->return_value () >>= retval) == 1)
200 ACE_hrtime_t now = ACE_OS::gethrtime ();
201 history.sample (ACE_HRTIME_TO_U64(now) - retval);
205 delete[] request;
207 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
209 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
211 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
212 ACE_High_Res_Timer::global_scale_factor_type gsf =
213 ACE_High_Res_Timer::global_scale_factor ();
214 ACE_DEBUG ((LM_DEBUG, "done\n"));
216 if (do_dump_history)
218 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
221 ACE_Basic_Stats stats;
222 history.collect_basic_stats (stats);
223 stats.dump_results (ACE_TEXT("Total"), gsf);
225 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
226 test_end - test_start,
227 stats.samples_count ());
228 return 0;
233 test_short_seq (Test::Roundtrip_ptr roundtrip)
235 ACE_Sample_History history (niterations);
237 Test::short_load sl (sz);
238 sl.length (sz);
240 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
242 CORBA::Request_var *request;
243 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
245 for (int i = 0; i < niterations; ++i)
247 int j;
249 for (j = 0; j != burst; ++j)
251 CORBA::ULongLong start = ACE_OS::gethrtime ();
253 request[j] =
254 roundtrip->_request ("test_short_method");
256 request[j]->add_in_arg ("short_load") <<= sl;
257 request[j]->add_in_arg ("send_time") <<= start;
258 request[j]->set_return_type (CORBA::_tc_ulonglong);
260 request[j]->send_deferred ();
263 for (j = 0; j != burst; ++j)
265 request[j]->get_response ();
267 CORBA::ULongLong retval;
268 if ((request[j]->return_value () >>= retval) == 1)
270 ACE_hrtime_t now = ACE_OS::gethrtime ();
271 history.sample (ACE_HRTIME_TO_U64(now) - retval);
275 delete[] request;
277 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
279 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
281 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
282 ACE_High_Res_Timer::global_scale_factor_type gsf =
283 ACE_High_Res_Timer::global_scale_factor ();
284 ACE_DEBUG ((LM_DEBUG, "done\n"));
286 if (do_dump_history)
288 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
291 ACE_Basic_Stats stats;
292 history.collect_basic_stats (stats);
293 stats.dump_results (ACE_TEXT("Total"), gsf);
295 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
296 test_end - test_start,
297 stats.samples_count ());
298 return 0;
303 test_char_seq (Test::Roundtrip_ptr roundtrip)
305 ACE_Sample_History history (niterations);
307 Test::char_load cl (sz);
308 cl.length (sz);
310 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
312 CORBA::Request_var *request;
313 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
315 for (int i = 0; i < niterations; ++i)
317 int j;
319 for (j = 0; j != burst; ++j)
321 CORBA::ULongLong start = ACE_OS::gethrtime ();
323 request[j] =
324 roundtrip->_request ("test_char_method");
326 request[j]->add_in_arg ("char_load") <<= cl;
327 request[j]->add_in_arg ("send_time") <<= start;
328 request[j]->set_return_type (CORBA::_tc_ulonglong);
330 request[j]->send_deferred ();
333 for (j = 0; j != burst; ++j)
335 request[j]->get_response ();
337 CORBA::ULongLong retval;
338 if ((request[j]->return_value () >>= retval) == 1)
340 ACE_hrtime_t now = ACE_OS::gethrtime ();
341 history.sample (ACE_HRTIME_TO_U64(now) - retval);
345 delete[] request;
347 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
349 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
351 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
352 ACE_High_Res_Timer::global_scale_factor_type gsf =
353 ACE_High_Res_Timer::global_scale_factor ();
354 ACE_DEBUG ((LM_DEBUG, "done\n"));
356 if (do_dump_history)
358 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
361 ACE_Basic_Stats stats;
362 history.collect_basic_stats (stats);
363 stats.dump_results (ACE_TEXT("Total"), gsf);
365 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
366 test_end - test_start,
367 stats.samples_count ());
368 return 0;
373 test_longlong_seq (Test::Roundtrip_ptr roundtrip)
375 ACE_Sample_History history (niterations);
377 Test::longlong_load ll (sz);
378 ll.length (sz);
380 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
382 CORBA::Request_var *request;
383 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
385 for (int i = 0; i < niterations; ++i)
387 int j;
389 for (j = 0; j != burst; ++j)
391 CORBA::ULongLong start = ACE_OS::gethrtime ();
393 request[j] =
394 roundtrip->_request ("test_longlong_method");
396 request[j]->add_in_arg ("longlong_load") <<= ll;
397 request[j]->add_in_arg ("send_time") <<= start;
398 request[j]->set_return_type (CORBA::_tc_ulonglong);
400 request[j]->send_deferred ();
403 for (j = 0; j != burst; ++j)
405 request[j]->get_response ();
407 CORBA::ULongLong retval;
408 if ((request[j]->return_value () >>= retval) == 1)
410 ACE_hrtime_t now = ACE_OS::gethrtime ();
411 history.sample (ACE_HRTIME_TO_U64(now) - retval);
415 delete[] request;
417 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
419 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
421 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
422 ACE_High_Res_Timer::global_scale_factor_type gsf =
423 ACE_High_Res_Timer::global_scale_factor ();
424 ACE_DEBUG ((LM_DEBUG, "done\n"));
426 if (do_dump_history)
428 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
431 ACE_Basic_Stats stats;
432 history.collect_basic_stats (stats);
433 stats.dump_results (ACE_TEXT("Total"), gsf);
435 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
436 test_end - test_start,
437 stats.samples_count ());
438 return 0;
443 test_double_seq (Test::Roundtrip_ptr roundtrip)
445 ACE_Sample_History history (niterations);
447 Test::double_load dl (sz);
448 dl.length (sz);
450 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
452 CORBA::Request_var *request;
453 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
455 for (int i = 0; i < niterations; ++i)
457 int j;
459 for (j = 0; j != burst; ++j)
461 CORBA::ULongLong start = ACE_OS::gethrtime ();
463 request[j] =
464 roundtrip->_request ("test_double_method");
466 request[j]->add_in_arg ("double_load") <<= dl;
467 request[j]->add_in_arg ("send_time") <<= start;
468 request[j]->set_return_type (CORBA::_tc_ulonglong);
470 request[j]->send_deferred ();
473 for (j = 0; j != burst; ++j)
475 request[j]->get_response ();
477 CORBA::ULongLong retval;
478 if ((request[j]->return_value () >>= retval) == 1)
480 ACE_hrtime_t now = ACE_OS::gethrtime ();
481 history.sample (ACE_HRTIME_TO_U64(now) - retval);
485 delete[] request;
487 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
489 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
491 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
492 ACE_High_Res_Timer::global_scale_factor_type gsf =
493 ACE_High_Res_Timer::global_scale_factor ();
494 ACE_DEBUG ((LM_DEBUG, "done\n"));
496 if (do_dump_history)
498 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
501 ACE_Basic_Stats stats;
502 history.collect_basic_stats (stats);
503 stats.dump_results (ACE_TEXT("Total"), gsf);
505 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
506 test_end - test_start,
507 stats.samples_count ());
508 return 0;
512 // The main() function starts here
515 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
517 int priority =
518 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
519 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
520 // Enable FIFO scheduling
522 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
523 priority,
524 ACE_SCOPE_PROCESS)) != 0)
526 if (ACE_OS::last_error () == EPERM)
528 ACE_DEBUG ((LM_DEBUG,
529 "client (%P|%t): user is not superuser, "
530 "test runs in time-shared class\n"));
532 else
533 ACE_ERROR ((LM_ERROR,
534 "client (%P|%t): sched_params failed\n"));
539 CORBA::ORB_var orb =
540 CORBA::ORB_init (argc, argv);
542 if (parse_args (argc, argv) != 0)
543 return 1;
545 CORBA::Object_var object =
546 orb->string_to_object (ior);
548 Test::Roundtrip_var roundtrip =
549 Test::Roundtrip::_narrow (object.in ());
551 if (CORBA::is_nil (roundtrip.in ()))
553 ACE_ERROR_RETURN ((LM_ERROR,
554 "Nil Test::Roundtrip reference <%s>\n",
555 ior),
559 Test::octet_load oc;
561 for (int j = 0; j < 100; ++j)
563 ACE_hrtime_t start = 0;
564 (void) roundtrip->test_octet_method (oc,
565 start);
569 // Test various sequence types
571 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) == 0)
573 test_octet_seq (roundtrip.in ());
575 else if (ACE_OS::strcmp (data_type, ACE_TEXT("char")) == 0)
577 test_char_seq (roundtrip.in ());
579 else if (ACE_OS::strcmp (data_type, ACE_TEXT("long")) == 0)
581 test_long_seq (roundtrip.in ());
583 else if (ACE_OS::strcmp (data_type, ACE_TEXT("short")) == 0)
585 test_short_seq (roundtrip.in ());
587 else if (ACE_OS::strcmp (data_type, ACE_TEXT("double")) == 0)
589 test_double_seq (roundtrip.in ());
591 else if (ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) == 0)
593 test_longlong_seq (roundtrip.in ());
596 if (do_shutdown)
598 roundtrip->shutdown ();
601 catch (const CORBA::Exception& ex)
603 ex._tao_print_exception ("Caught exception:");
604 return 1;
607 return 0;