1 #include "tao/DynamicInterface/Request.h" /* Must come first for G++
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;
22 int do_dump_history
= 0;
25 const ACE_TCHAR
*data_type
= ACE_TEXT("octet");
28 parse_args (int argc
, ACE_TCHAR
*argv
[])
30 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:s:hxk:i:b:"));
33 while ((c
= get_opts ()) != -1)
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)
49 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
61 ior
= get_opts
.opt_arg ();
65 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
69 burst
= ACE_OS::atoi (get_opts
.opt_arg ());
74 ACE_ERROR_RETURN ((LM_ERROR
,
81 "-x (disable shutdown) "
87 // Indicates successful parsing of the command line
93 test_octet_seq (Test::Roundtrip_ptr roundtrip
)
95 ACE_Sample_History
history (niterations
);
97 Test::octet_load
ol (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
)
109 for (j
= 0; j
!= burst
; ++j
)
111 CORBA::ULongLong start
= ACE_OS::gethrtime ();
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
);
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"));
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 ());
163 test_long_seq (Test::Roundtrip_ptr roundtrip
)
165 ACE_Sample_History
history (niterations
);
167 Test::long_load
ll (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
)
179 for (j
= 0; j
!= burst
; ++j
)
181 CORBA::ULongLong start
= ACE_OS::gethrtime ();
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
);
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"));
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 ());
233 test_short_seq (Test::Roundtrip_ptr roundtrip
)
235 ACE_Sample_History
history (niterations
);
237 Test::short_load
sl (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
)
249 for (j
= 0; j
!= burst
; ++j
)
251 CORBA::ULongLong start
= ACE_OS::gethrtime ();
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
);
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"));
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 ());
303 test_char_seq (Test::Roundtrip_ptr roundtrip
)
305 ACE_Sample_History
history (niterations
);
307 Test::char_load
cl (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
)
319 for (j
= 0; j
!= burst
; ++j
)
321 CORBA::ULongLong start
= ACE_OS::gethrtime ();
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
);
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"));
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 ());
373 test_longlong_seq (Test::Roundtrip_ptr roundtrip
)
375 ACE_Sample_History
history (niterations
);
377 Test::longlong_load
ll (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
)
389 for (j
= 0; j
!= burst
; ++j
)
391 CORBA::ULongLong start
= ACE_OS::gethrtime ();
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
);
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"));
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 ());
443 test_double_seq (Test::Roundtrip_ptr roundtrip
)
445 ACE_Sample_History
history (niterations
);
447 Test::double_load
dl (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
)
459 for (j
= 0; j
!= burst
; ++j
)
461 CORBA::ULongLong start
= ACE_OS::gethrtime ();
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
);
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"));
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 ());
512 // The main() function starts here
515 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
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
,
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"));
533 ACE_ERROR ((LM_ERROR
,
534 "client (%P|%t): sched_params failed\n"));
540 CORBA::ORB_init (argc
, argv
);
542 if (parse_args (argc
, argv
) != 0)
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",
561 for (int j
= 0; j
< 100; ++j
)
563 ACE_hrtime_t start
= 0;
564 (void) roundtrip
->test_octet_method (oc
,
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 ());
598 roundtrip
->shutdown ();
601 catch (const CORBA::Exception
& ex
)
603 ex
._tao_print_exception ("Caught exception:");