1 #include "Roundtrip_Handler.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Sched_Params.h"
7 #include "ace/Throughput_Stats.h"
8 #include "ace/OS_NS_errno.h"
10 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 ACE_hrtime_t throughput_base
;
14 int niterations
= 1000;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:i:"));
22 while ((c
= get_opts ()) != -1)
26 ior
= get_opts
.opt_arg ();
30 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
35 ACE_ERROR_RETURN ((LM_ERROR
,
39 "-p <period (msecs)> "
45 // Indicates successful parsing of the command line
50 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
53 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
54 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
56 // Enable FIFO scheduling
57 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
59 ACE_SCOPE_PROCESS
)) != 0)
61 if (ACE_OS::last_error () == EPERM
)
64 "client (%P|%t): user is not superuser, "
65 "test runs in time-shared class\n"));
69 "client (%P|%t): sched_params failed\n"));
75 CORBA::ORB_init (argc
, argv
);
77 CORBA::Object_var poa_object
=
78 orb
->resolve_initial_references("RootPOA");
80 if (CORBA::is_nil (poa_object
.in ()))
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 " (%P|%t) Unable to initialize the POA.\n"),
85 PortableServer::POA_var root_poa
=
86 PortableServer::POA::_narrow (poa_object
.in ());
88 PortableServer::POAManager_var poa_manager
=
89 root_poa
->the_POAManager ();
91 if (parse_args (argc
, argv
) != 0)
94 CORBA::Object_var object
=
95 orb
->string_to_object (ior
);
97 Test::Roundtrip_var roundtrip
=
98 Test::Roundtrip::_narrow (object
.in ());
100 if (CORBA::is_nil (roundtrip
.in ()))
101 ACE_ERROR_RETURN ((LM_ERROR
,
102 "Nil Test::Roundtrip reference <%s>\n",
106 for (int j
= 0; j
< 100; ++j
)
108 ACE_hrtime_t start
= 0;
109 (void) roundtrip
->test_method (start
);
112 Roundtrip_Handler
*roundtrip_handler_impl
;
113 ACE_NEW_RETURN (roundtrip_handler_impl
,
114 Roundtrip_Handler (niterations
),
116 PortableServer::ServantBase_var
owner_transfer(roundtrip_handler_impl
);
118 Test::AMI_RoundtripHandler_var roundtrip_handler
=
119 roundtrip_handler_impl
->_this ();
121 poa_manager
->activate ();
123 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
125 for (int i
= 0; i
!= niterations
; ++i
)
127 // Invoke asynchronous operation....
128 roundtrip
->sendc_test_method (roundtrip_handler
.in (),
129 ACE_OS::gethrtime ());
130 if (orb
->work_pending ())
131 orb
->perform_work ();
134 ACE_Time_Value
tv (0, 2000);
136 while (roundtrip_handler_impl
->pending_callbacks ())
138 orb
->perform_work (tv
);
141 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
143 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
144 ACE_High_Res_Timer::global_scale_factor_type gsf
=
145 ACE_High_Res_Timer::global_scale_factor ();
146 ACE_DEBUG ((LM_DEBUG
, "done\n"));
148 roundtrip_handler_impl
->dump_results (gsf
);
150 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
151 test_end
- test_start
,
154 roundtrip
->shutdown ();
156 root_poa
->destroy (true, true);
160 catch (const CORBA::Exception
& ex
)
162 ex
._tao_print_exception ("Exception caught: ");