Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / AMH_Single_Threaded / client.cpp
blobcf8de4e49ea1eea1157d0890dfbac83e61e726a1
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/Stats.h"
6 #include "ace/Throughput_Stats.h"
7 #include "ace/Sample_History.h"
8 #include "ace/OS_NS_errno.h"
10 #include "tao/Strategies/advanced_resource.h"
12 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
13 int niterations = 100;
14 int do_dump_history = 0;
15 int do_shutdown = 1;
16 int sz = 512;
18 const ACE_TCHAR *data_type = ACE_TEXT("octet");
20 int
21 parse_args (int argc, ACE_TCHAR *argv[])
23 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:s:hxk:i:"));
24 int c;
26 while ((c = get_opts ()) != -1)
27 switch (c)
29 case 't':
30 data_type = get_opts.opt_arg ();
32 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) != 0 &&
33 ACE_OS::strcmp (data_type, ACE_TEXT("char")) != 0 &&
34 ACE_OS::strcmp (data_type, ACE_TEXT("long")) != 0 &&
35 ACE_OS::strcmp (data_type, ACE_TEXT("short")) != 0 &&
36 ACE_OS::strcmp (data_type, ACE_TEXT("double")) != 0 &&
37 ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) != 0)
38 return -1;
39 break;
41 case 's':
42 sz = ACE_OS::atoi (get_opts.opt_arg ());
43 break;
45 case 'h':
46 do_dump_history = 1;
47 break;
49 case 'x':
50 do_shutdown = 0;
51 break;
53 case 'k':
54 ior = get_opts.opt_arg ();
55 break;
57 case 'i':
58 niterations = ACE_OS::atoi (get_opts.opt_arg ());
59 break;
61 case '?':
62 default:
63 ACE_ERROR_RETURN ((LM_ERROR,
64 "usage: %s "
65 "-t <datatype> "
66 "-s <size> "
67 "-k <ior> "
68 "-i <niterations> "
69 "-x (disable shutdown) "
70 "-h (dump history) "
71 "\n",
72 argv [0]),
73 -1);
75 // Indicates successful parsing of the command line
76 return 0;
80 void
81 test_octet_seq (Test::Roundtrip_ptr roundtrip)
83 ACE_Sample_History history (niterations);
85 Test::octet_load ol (sz);
86 ol.length (sz);
88 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
89 for (int i = 0; i < niterations; ++i)
91 ACE_hrtime_t start = ACE_OS::gethrtime ();
93 (void) roundtrip->test_octet_method (ol, start);
95 ACE_hrtime_t now = ACE_OS::gethrtime ();
96 history.sample (now - start);
99 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
101 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
103 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
104 ACE_High_Res_Timer::global_scale_factor_type gsf =
105 ACE_High_Res_Timer::global_scale_factor ();
106 ACE_DEBUG ((LM_DEBUG, "done\n"));
108 if (do_dump_history)
110 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
113 ACE_Basic_Stats stats;
114 history.collect_basic_stats (stats);
115 stats.dump_results (ACE_TEXT("Total"), gsf);
117 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
118 test_end - test_start,
119 stats.samples_count ());
123 void
124 test_long_seq (Test::Roundtrip_ptr roundtrip)
126 ACE_Sample_History history (niterations);
128 Test::long_load ll (sz);
129 ll.length (sz);
131 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
132 for (int i = 0; i < niterations; ++i)
134 ACE_hrtime_t start = ACE_OS::gethrtime ();
136 (void) roundtrip->test_long_method (ll, start);
138 ACE_hrtime_t now = ACE_OS::gethrtime ();
139 history.sample (now - start);
142 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
144 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
146 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
147 ACE_High_Res_Timer::global_scale_factor_type gsf =
148 ACE_High_Res_Timer::global_scale_factor ();
149 ACE_DEBUG ((LM_DEBUG, "done\n"));
151 if (do_dump_history)
153 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
156 ACE_Basic_Stats stats;
157 history.collect_basic_stats (stats);
158 stats.dump_results (ACE_TEXT("Total"), gsf);
160 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
161 test_end - test_start,
162 stats.samples_count ());
166 void
167 test_short_seq (Test::Roundtrip_ptr roundtrip)
169 ACE_Sample_History history (niterations);
171 Test::short_load sl (sz);
172 sl.length (sz);
174 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
175 for (int i = 0; i < niterations; ++i)
177 ACE_hrtime_t start = ACE_OS::gethrtime ();
179 (void) roundtrip->test_short_method (sl, start);
181 ACE_hrtime_t now = ACE_OS::gethrtime ();
182 history.sample (now - start);
185 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
187 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
189 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
190 ACE_High_Res_Timer::global_scale_factor_type gsf =
191 ACE_High_Res_Timer::global_scale_factor ();
192 ACE_DEBUG ((LM_DEBUG, "done\n"));
194 if (do_dump_history)
196 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
199 ACE_Basic_Stats stats;
200 history.collect_basic_stats (stats);
201 stats.dump_results (ACE_TEXT("Total"), gsf);
203 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
204 test_end - test_start,
205 stats.samples_count ());
209 void
210 test_char_seq (Test::Roundtrip_ptr roundtrip)
212 ACE_Sample_History history (niterations);
214 Test::char_load cl (sz);
215 cl.length (sz);
217 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
218 for (int i = 0; i < niterations; ++i)
220 ACE_hrtime_t start = ACE_OS::gethrtime ();
222 (void) roundtrip->test_char_method (cl, start);
224 ACE_hrtime_t now = ACE_OS::gethrtime ();
225 history.sample (now - start);
228 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
230 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
232 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
233 ACE_High_Res_Timer::global_scale_factor_type gsf =
234 ACE_High_Res_Timer::global_scale_factor ();
235 ACE_DEBUG ((LM_DEBUG, "done\n"));
237 if (do_dump_history)
239 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
242 ACE_Basic_Stats stats;
243 history.collect_basic_stats (stats);
244 stats.dump_results (ACE_TEXT("Total"), gsf);
246 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
247 test_end - test_start,
248 stats.samples_count ());
252 void
253 test_longlong_seq (Test::Roundtrip_ptr roundtrip)
255 ACE_Sample_History history (niterations);
257 Test::longlong_load ll (sz);
258 ll.length (sz);
260 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
261 for (int i = 0; i < niterations; ++i)
263 ACE_hrtime_t start = ACE_OS::gethrtime ();
265 (void) roundtrip->test_longlong_method (ll, start);
267 ACE_hrtime_t now = ACE_OS::gethrtime ();
268 history.sample (now - start);
271 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
273 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
275 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
276 ACE_High_Res_Timer::global_scale_factor_type gsf =
277 ACE_High_Res_Timer::global_scale_factor ();
278 ACE_DEBUG ((LM_DEBUG, "done\n"));
280 if (do_dump_history)
282 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
285 ACE_Basic_Stats stats;
286 history.collect_basic_stats (stats);
287 stats.dump_results (ACE_TEXT("Total"), gsf);
289 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
290 test_end - test_start,
291 stats.samples_count ());
295 void
296 test_double_seq (Test::Roundtrip_ptr roundtrip)
298 ACE_Sample_History history (niterations);
300 Test::double_load dl (sz);
301 dl.length (sz);
303 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
304 for (int i = 0; i < niterations; ++i)
306 ACE_hrtime_t start = ACE_OS::gethrtime ();
308 (void) roundtrip->test_double_method (dl, start);
310 ACE_hrtime_t now = ACE_OS::gethrtime ();
311 history.sample (now - start);
314 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
316 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
318 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
319 ACE_High_Res_Timer::global_scale_factor_type gsf =
320 ACE_High_Res_Timer::global_scale_factor ();
321 ACE_DEBUG ((LM_DEBUG, "done\n"));
323 if (do_dump_history)
325 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
328 ACE_Basic_Stats stats;
329 history.collect_basic_stats (stats);
330 stats.dump_results (ACE_TEXT("Total"), gsf);
332 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
333 test_end - test_start,
334 stats.samples_count ());
339 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
341 int priority =
342 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
343 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
344 // Enable FIFO scheduling
346 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
347 priority,
348 ACE_SCOPE_PROCESS)) != 0)
350 if (ACE_OS::last_error () == EPERM)
352 ACE_DEBUG ((LM_DEBUG,
353 "client (%P|%t): user is not superuser, "
354 "test runs in time-shared class\n"));
356 else
357 ACE_ERROR ((LM_ERROR,
358 "client (%P|%t): sched_params failed\n"));
363 CORBA::ORB_var orb =
364 CORBA::ORB_init (argc, argv);
366 if (parse_args (argc, argv) != 0)
367 return 1;
369 CORBA::Object_var object =
370 orb->string_to_object (ior);
372 Test::Roundtrip_var roundtrip =
373 Test::Roundtrip::_narrow (object.in ());
375 if (CORBA::is_nil (roundtrip.in ()))
377 ACE_ERROR_RETURN ((LM_ERROR,
378 "Nil Test::Roundtrip reference <%s>\n",
379 ior),
383 Test::octet_load oc;
385 for (int j = 0; j < 100; ++j)
387 ACE_hrtime_t start = 0;
388 (void) roundtrip->test_octet_method (oc,
389 start);
392 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) == 0)
394 test_octet_seq (roundtrip.in ());
396 else if (ACE_OS::strcmp (data_type, ACE_TEXT("char")) == 0)
398 test_char_seq (roundtrip.in ());
400 else if (ACE_OS::strcmp (data_type, ACE_TEXT("long")) == 0)
402 test_long_seq (roundtrip.in ());
404 else if (ACE_OS::strcmp (data_type, ACE_TEXT("short")) == 0)
406 test_short_seq (roundtrip.in ());
408 else if (ACE_OS::strcmp (data_type, ACE_TEXT("double")) == 0)
410 test_double_seq (roundtrip.in ());
412 else if (ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) == 0)
414 test_longlong_seq (roundtrip.in ());
417 if (do_shutdown)
419 roundtrip->shutdown ();
422 catch (const CORBA::Exception& ex)
424 ex._tao_print_exception ("Exception caught:");
425 return 1;
428 return 0;