Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / performance-tests / Latency / AMI / client.cpp
blob997c2687aec238876f7430493377358f4c2f54ce
1 #include "Roundtrip_Handler.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Sched_Params.h"
6 #include "ace/Stats.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;
16 int
17 parse_args (int argc, ACE_TCHAR *argv[])
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'k':
26 ior = get_opts.opt_arg ();
27 break;
29 case 'i':
30 niterations = ACE_OS::atoi (get_opts.opt_arg ());
31 break;
33 case '?':
34 default:
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "usage: %s "
37 "-k <ior> "
38 "-i <niterations> "
39 "-p <period (msecs)> "
40 "-b <burst size> "
41 "\n",
42 argv [0]),
43 -1);
45 // Indicates successful parsing of the command line
46 return 0;
49 int
50 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
52 int priority =
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,
58 priority,
59 ACE_SCOPE_PROCESS)) != 0)
61 if (ACE_OS::last_error () == EPERM)
63 ACE_DEBUG ((LM_DEBUG,
64 "client (%P|%t): user is not superuser, "
65 "test runs in time-shared class\n"));
67 else
68 ACE_ERROR ((LM_ERROR,
69 "client (%P|%t): sched_params failed\n"));
72 try
74 CORBA::ORB_var orb =
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"),
83 1);
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)
92 return 1;
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",
103 ior),
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,
152 niterations);
154 roundtrip->shutdown ();
156 root_poa->destroy (true, true);
158 orb->destroy ();
160 catch (const CORBA::Exception& ex)
162 ex._tao_print_exception ("Exception caught: ");
163 return 1;
166 return 0;