Cleanup Solaris support
[ACE_TAO.git] / TAO / performance-tests / Latency / Deferred / client.cpp
blob5803b9977d330202e850ee9f5f74dcdc2374880c
1 #include "tao/DynamicInterface/Request.h" /* This must come first for
2 G++ 3.4 or better */
4 #include "TestC.h"
6 #include "tao/AnyTypeCode/TypeCode_Constants.h"
8 #include "tao/Strategies/advanced_resource.h"
10 #include "ace/Get_Opt.h"
11 #include "ace/Sched_Params.h"
12 #include "ace/High_Res_Timer.h"
13 #include "ace/Sched_Params.h"
14 #include "ace/Stats.h"
15 #include "ace/Throughput_Stats.h"
16 #include "ace/Sample_History.h"
17 #include "ace/OS_NS_errno.h"
19 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
20 int niterations = 1000;
21 int burst = 10;
22 int do_shutdown = 1;
23 int do_dump_history = 0;
25 int
26 parse_args (int argc, ACE_TCHAR *argv[])
28 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hxk:i:b:"));
29 int c;
31 while ((c = get_opts ()) != -1)
32 switch (c)
34 case 'h':
35 do_dump_history = 1;
36 break;
38 case 'x':
39 do_shutdown = 0;
40 break;
42 case 'k':
43 ior = get_opts.opt_arg ();
44 break;
46 case 'i':
47 niterations = ACE_OS::atoi (get_opts.opt_arg ());
48 break;
50 case 'b':
51 burst = ACE_OS::atoi (get_opts.opt_arg ());
52 break;
54 case '?':
55 default:
56 ACE_ERROR_RETURN ((LM_ERROR,
57 "usage: %s "
58 "-k <ior> "
59 "-i <niterations> "
60 "-b <burst> "
61 "-x (disable shutdown) "
62 "-h (dump history) "
63 "\n",
64 argv [0]),
65 -1);
67 // Indicates successful parsing of the command line
68 return 0;
71 int
72 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
74 int priority =
75 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
76 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
77 // Enable FIFO scheduling
79 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
80 priority,
81 ACE_SCOPE_PROCESS)) != 0)
83 if (ACE_OS::last_error () == EPERM)
85 ACE_DEBUG ((LM_DEBUG,
86 "client (%P|%t): user is not superuser, "
87 "test runs in time-shared class\n"));
89 else
90 ACE_ERROR ((LM_ERROR,
91 "client (%P|%t): sched_params failed\n"));
94 try
96 CORBA::ORB_var orb =
97 CORBA::ORB_init (argc, argv);
99 if (parse_args (argc, argv) != 0)
100 return 1;
102 CORBA::Object_var object =
103 orb->string_to_object (ior);
105 Test::Roundtrip_var roundtrip =
106 Test::Roundtrip::_narrow (object.in ());
108 if (CORBA::is_nil (roundtrip.in ()))
110 ACE_ERROR_RETURN ((LM_ERROR,
111 "Nil Test::Roundtrip reference <%s>\n",
112 ior),
116 for (int j = 0; j < 100; ++j)
118 ACE_hrtime_t start = 0;
119 (void) roundtrip->test_method (start);
122 ACE_Sample_History history (niterations);
124 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
126 CORBA::Request_var *request;
127 ACE_NEW_RETURN (request, CORBA::Request_var[burst], 1);
129 for (int i = 0; i < niterations; ++i)
131 int j;
133 for (j = 0; j != burst; ++j)
135 CORBA::ULongLong start = ACE_OS::gethrtime ();
137 request[j] =
138 roundtrip->_request ("test_method");
140 request[j]->add_in_arg () <<= start;
141 request[j]->set_return_type (CORBA::_tc_ulonglong);
143 request[j]->send_deferred ();
146 for (j = 0; j != burst; ++j)
148 request[j]->get_response ();
150 CORBA::ULongLong retval;
151 if ((request[j]->return_value () >>= retval) == 1)
153 ACE_hrtime_t now = ACE_OS::gethrtime ();
154 history.sample (ACE_HRTIME_TO_U64(now) - retval);
158 delete[] request;
160 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
162 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
164 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
165 ACE_High_Res_Timer::global_scale_factor_type gsf =
166 ACE_High_Res_Timer::global_scale_factor ();
167 ACE_DEBUG ((LM_DEBUG, "done\n"));
169 if (do_dump_history)
171 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
174 ACE_Basic_Stats stats;
175 history.collect_basic_stats (stats);
176 stats.dump_results (ACE_TEXT("Total"), gsf);
178 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
179 test_end - test_start,
180 stats.samples_count ());
182 if (do_shutdown)
184 roundtrip->shutdown ();
187 catch (const CORBA::Exception& ex)
189 ex._tao_print_exception ("Caught exception:");
190 return 1;
193 return 0;