Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / DII / client.cpp
blobf7813fce89491aacf263e5bb76fcf431dad2b0bc
1 #include "tao/DynamicInterface/Request.h"
2 #include "tao/Strategies/advanced_resource.h"
3 #include "tao/AnyTypeCode/TypeCode_Constants.h"
4 #include "tao/AnyTypeCode/Any.h"
6 #include "TestC.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/High_Res_Timer.h"
10 #include "ace/Sched_Params.h"
11 #include "ace/Stats.h"
12 #include "ace/Throughput_Stats.h"
13 #include "ace/Sample_History.h"
14 #include "ace/OS_NS_errno.h"
16 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
17 int niterations = 100;
18 int do_dump_history = 0;
19 int do_shutdown = 1;
20 int sz = 512;
22 const ACE_TCHAR *data_type = ACE_TEXT("octet");
24 int
25 parse_args (int argc, ACE_TCHAR *argv[])
27 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:s:hxk:i:"));
28 int c;
30 while ((c = get_opts ()) != -1)
31 switch (c)
33 case 't':
34 data_type = get_opts.opt_arg ();
36 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) != 0 &&
37 ACE_OS::strcmp (data_type, ACE_TEXT("char")) != 0 &&
38 ACE_OS::strcmp (data_type, ACE_TEXT("long")) != 0 &&
39 ACE_OS::strcmp (data_type, ACE_TEXT("short")) != 0 &&
40 ACE_OS::strcmp (data_type, ACE_TEXT("double")) != 0 &&
41 ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) != 0)
42 return -1;
43 break;
45 case 's':
46 sz = ACE_OS::atoi (get_opts.opt_arg ());
47 break;
49 case 'h':
50 do_dump_history = 1;
51 break;
53 case 'x':
54 do_shutdown = 0;
55 break;
57 case 'k':
58 ior = get_opts.opt_arg ();
59 break;
61 case 'i':
62 niterations = ACE_OS::atoi (get_opts.opt_arg ());
63 break;
65 case '?':
66 default:
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "usage: %s "
69 "-t <datatype> "
70 "-s <size> "
71 "-k <ior> "
72 "-i <niterations> "
73 "-x (disable shutdown) "
74 "\n",
75 argv [0]),
76 -1);
78 // Indicates successful parsing of the command line
79 return 0;
83 void
84 test_octet_seq (const CORBA::Object_var object)
86 ACE_Sample_History history (niterations);
88 Test::octet_load ol (sz);
89 ol.length (sz);
91 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
92 for (int i = 0; i < niterations; ++i)
94 ACE_hrtime_t start = ACE_OS::gethrtime ();
95 Test::Timestamp start_time = static_cast <Test::Timestamp> (start);
97 CORBA::Request_var request =
98 object->_request ("test_octet_method");
100 request->add_in_arg("octet_load") <<= ol;
101 request->add_in_arg("send_time") <<= start_time;
103 request->set_return_type (CORBA::_tc_ulonglong);
104 request->invoke ();
106 ACE_hrtime_t now = ACE_OS::gethrtime ();
107 history.sample (now - start);
110 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
112 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
114 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
115 ACE_High_Res_Timer::global_scale_factor_type gsf =
116 ACE_High_Res_Timer::global_scale_factor ();
117 ACE_DEBUG ((LM_DEBUG, "done\n"));
119 if (do_dump_history)
121 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
124 ACE_Basic_Stats stats;
125 history.collect_basic_stats (stats);
126 stats.dump_results (ACE_TEXT("Total"), gsf);
128 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
129 test_end - test_start,
130 stats.samples_count ());
133 void
134 test_long_seq (const CORBA::Object_var object)
136 ACE_Sample_History history (niterations);
138 Test::long_load ll (sz);
139 ll.length (sz);
141 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
142 for (int i = 0; i < niterations; ++i)
144 ACE_hrtime_t start = ACE_OS::gethrtime ();
146 CORBA::Request_var request =
147 object->_request ("test_long_method");
149 request->add_in_arg("long_load") <<= ll;
150 request->add_in_arg("send_time") <<= static_cast <Test::Timestamp> (start);
152 request->set_return_type (CORBA::_tc_ulonglong);
153 request->invoke ();
155 ACE_hrtime_t now = ACE_OS::gethrtime ();
156 history.sample (now - start);
159 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
161 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
163 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
164 ACE_High_Res_Timer::global_scale_factor_type gsf =
165 ACE_High_Res_Timer::global_scale_factor ();
166 ACE_DEBUG ((LM_DEBUG, "done\n"));
168 if (do_dump_history)
170 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
173 ACE_Basic_Stats stats;
174 history.collect_basic_stats (stats);
175 stats.dump_results (ACE_TEXT("Total"), gsf);
177 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
178 test_end - test_start,
179 stats.samples_count ());
182 void
183 test_short_seq (const CORBA::Object_var object)
185 ACE_Sample_History history (niterations);
187 Test::short_load sl (sz);
188 sl.length (sz);
190 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
191 for (int i = 0; i < niterations; ++i)
193 ACE_hrtime_t start = ACE_OS::gethrtime ();
195 CORBA::Request_var request =
196 object->_request ("test_short_method");
198 request->add_in_arg("short_load") <<= sl;
199 request->add_in_arg("send_time") <<= static_cast <Test::Timestamp> (start);
201 request->set_return_type (CORBA::_tc_ulonglong);
202 request->invoke ();
204 ACE_hrtime_t now = ACE_OS::gethrtime ();
205 history.sample (now - start);
208 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
210 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
212 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
213 ACE_High_Res_Timer::global_scale_factor_type gsf =
214 ACE_High_Res_Timer::global_scale_factor ();
215 ACE_DEBUG ((LM_DEBUG, "done\n"));
217 if (do_dump_history)
219 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
222 ACE_Basic_Stats stats;
223 history.collect_basic_stats (stats);
224 stats.dump_results (ACE_TEXT("Total"), gsf);
226 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
227 test_end - test_start,
228 stats.samples_count ());
231 void
232 test_char_seq (const CORBA::Object_var object)
234 ACE_Sample_History history (niterations);
236 Test::char_load cl (sz);
237 cl.length (sz);
239 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
240 for (int i = 0; i < niterations; ++i)
242 ACE_hrtime_t start = ACE_OS::gethrtime ();
244 CORBA::Request_var request =
245 object->_request ("test_char_method");
247 request->add_in_arg("char_load") <<= cl;
248 request->add_in_arg("send_time") <<= static_cast <Test::Timestamp> (start);
250 request->set_return_type (CORBA::_tc_ulonglong);
251 request->invoke ();
253 ACE_hrtime_t now = ACE_OS::gethrtime ();
254 history.sample (now - start);
257 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
259 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
261 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
262 ACE_High_Res_Timer::global_scale_factor_type gsf =
263 ACE_High_Res_Timer::global_scale_factor ();
264 ACE_DEBUG ((LM_DEBUG, "done\n"));
266 if (do_dump_history)
268 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
271 ACE_Basic_Stats stats;
272 history.collect_basic_stats (stats);
273 stats.dump_results (ACE_TEXT("Total"), gsf);
275 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
276 test_end - test_start,
277 stats.samples_count ());
280 void
281 test_double_seq (const CORBA::Object_var object)
283 ACE_Sample_History history (niterations);
285 Test::double_load dl (sz);
286 dl.length (sz);
288 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
289 for (int i = 0; i < niterations; ++i)
291 ACE_hrtime_t start = ACE_OS::gethrtime ();
293 CORBA::Request_var request =
294 object->_request ("test_double_method");
296 request->add_in_arg("double_load") <<= dl;
297 request->add_in_arg("send_time") <<= static_cast <Test::Timestamp> (start);
299 request->set_return_type (CORBA::_tc_ulonglong);
300 request->invoke ();
302 ACE_hrtime_t now = ACE_OS::gethrtime ();
303 history.sample (now - start);
306 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
308 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
310 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
311 ACE_High_Res_Timer::global_scale_factor_type gsf =
312 ACE_High_Res_Timer::global_scale_factor ();
313 ACE_DEBUG ((LM_DEBUG, "done\n"));
315 if (do_dump_history)
317 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
320 ACE_Basic_Stats stats;
321 history.collect_basic_stats (stats);
322 stats.dump_results (ACE_TEXT("Total"), gsf);
324 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
325 test_end - test_start,
326 stats.samples_count ());
329 void
330 test_longlong_seq (const CORBA::Object_var object)
332 ACE_Sample_History history (niterations);
334 Test::longlong_load ll (sz);
335 ll.length (sz);
337 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
338 for (int i = 0; i < niterations; ++i)
340 ACE_hrtime_t start = ACE_OS::gethrtime ();
342 CORBA::Request_var request =
343 object->_request ("test_longlong_method");
345 request->add_in_arg("longlong_load") <<= ll;
346 request->add_in_arg("send_time") <<= static_cast <Test::Timestamp> (start);
348 request->set_return_type (CORBA::_tc_ulonglong);
349 request->invoke ();
351 ACE_hrtime_t now = ACE_OS::gethrtime ();
352 history.sample (now - start);
355 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
357 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
359 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
360 ACE_High_Res_Timer::global_scale_factor_type gsf =
361 ACE_High_Res_Timer::global_scale_factor ();
362 ACE_DEBUG ((LM_DEBUG, "done\n"));
364 if (do_dump_history)
366 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
369 ACE_Basic_Stats stats;
370 history.collect_basic_stats (stats);
371 stats.dump_results (ACE_TEXT("Total"), gsf);
373 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
374 test_end - test_start,
375 stats.samples_count ());
379 // The main() function starts here
382 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
384 int priority =
385 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
386 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
387 // Enable FIFO scheduling
389 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
390 priority,
391 ACE_SCOPE_PROCESS)) != 0)
393 if (ACE_OS::last_error () == EPERM)
395 ACE_DEBUG ((LM_DEBUG,
396 "client (%P|%t): user is not superuser, "
397 "test runs in time-shared class\n"));
399 else
400 ACE_ERROR ((LM_ERROR,
401 "client (%P|%t): sched_params failed\n"));
406 CORBA::ORB_var orb =
407 CORBA::ORB_init (argc, argv);
409 if (parse_args (argc, argv) != 0)
410 return 1;
412 CORBA::Object_var object =
413 orb->string_to_object (ior);
415 if (CORBA::is_nil (object.in ()))
417 ACE_ERROR_RETURN ((LM_ERROR,
418 "Nil CORBA::Object reference <%s>\n",
419 ior),
423 Test::octet_load oc;
425 for (int j = 0; j < 100; ++j)
427 CORBA::Request_var request =
428 object->_request ("test_octet_method");
430 Test::Timestamp dummy = 0;
431 request->add_in_arg("octet_load") <<= oc;
432 request->add_in_arg("send_time") <<= dummy;
434 request->set_return_type (CORBA::_tc_ulonglong);
435 request->invoke ();
438 // Test various sequence types
440 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) == 0 )
442 test_octet_seq (object);
444 else if (ACE_OS::strcmp (data_type, ACE_TEXT("char")) == 0)
446 test_char_seq (object);
448 else if (ACE_OS::strcmp (data_type, ACE_TEXT("long")) == 0)
450 test_long_seq (object);
452 else if (ACE_OS::strcmp (data_type, ACE_TEXT("short")) == 0)
454 test_short_seq (object);
456 else if (ACE_OS::strcmp (data_type, ACE_TEXT("double")) == 0)
458 test_double_seq (object);
460 else if (ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) == 0)
462 test_longlong_seq (object);
465 if (do_shutdown)
467 CORBA::Request_var request =
468 object->_request ("shutdown");
470 request->invoke ();
473 catch (const CORBA::Exception& ex)
475 ex._tao_print_exception ("Exception caught:");
476 return 1;
479 return 0;