Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / DSI / client.cpp
blob44c7a7ba2fedb78e1bfddbea7fc4e1051a0ceba3
2 #include "TestC.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/Sample_History.h"
9 #include "ace/OS_NS_errno.h"
11 #include "tao/Strategies/advanced_resource.h"
13 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
14 int niterations = 100;
15 int do_dump_history = 0;
16 int do_shutdown = 1;
17 int sz = 512;
19 const ACE_TCHAR *data_type = ACE_TEXT("octet");
21 int
22 parse_args (int argc, ACE_TCHAR *argv[])
24 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:s:hxk:i:"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 't':
31 data_type = get_opts.opt_arg ();
33 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) != 0 &&
34 ACE_OS::strcmp (data_type, ACE_TEXT("char")) != 0 &&
35 ACE_OS::strcmp (data_type, ACE_TEXT("long")) != 0 &&
36 ACE_OS::strcmp (data_type, ACE_TEXT("short")) != 0 &&
37 ACE_OS::strcmp (data_type, ACE_TEXT("double")) != 0 &&
38 ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) != 0)
39 return -1;
40 break;
42 case 's':
43 sz = ACE_OS::atoi (get_opts.opt_arg ());
44 break;
46 case 'h':
47 do_dump_history = 1;
48 break;
50 case 'x':
51 do_shutdown = 0;
52 break;
54 case 'k':
55 ior = get_opts.opt_arg ();
56 break;
58 case 'i':
59 niterations = ACE_OS::atoi (get_opts.opt_arg ());
60 break;
62 case '?':
63 default:
64 ACE_ERROR_RETURN ((LM_ERROR,
65 "usage: %s "
66 "-k <ior> "
67 "-i <niterations> "
68 "-x (disable shutdown) "
69 "\n",
70 argv [0]),
71 -1);
73 // Indicates successful parsing of the command line
74 return 0;
77 void
78 test_octet_seq (Test::Roundtrip_ptr roundtrip)
80 ACE_Sample_History history (niterations);
82 Test::octet_load ol (sz);
83 ol.length (sz);
85 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
86 for (int i = 0; i < niterations; ++i)
88 ACE_hrtime_t start = ACE_OS::gethrtime ();
90 (void) roundtrip->test_octet_method (ol,
91 start);
93 ACE_hrtime_t now = ACE_OS::gethrtime ();
94 history.sample (now - start);
97 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
99 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
101 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
102 ACE_High_Res_Timer::global_scale_factor_type gsf =
103 ACE_High_Res_Timer::global_scale_factor ();
104 ACE_DEBUG ((LM_DEBUG, "done\n"));
106 if (do_dump_history)
108 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
111 ACE_Basic_Stats stats;
112 history.collect_basic_stats (stats);
113 stats.dump_results (ACE_TEXT("Total"), gsf);
115 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
116 test_end - test_start,
117 stats.samples_count ());
120 void
121 test_long_seq (Test::Roundtrip_ptr roundtrip)
123 ACE_Sample_History history (niterations);
125 Test::long_load ll (sz);
126 ll.length (sz);
128 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
129 for (int i = 0; i < niterations; ++i)
131 ACE_hrtime_t start = ACE_OS::gethrtime ();
133 (void) roundtrip->test_long_method (ll,
134 start);
136 ACE_hrtime_t now = ACE_OS::gethrtime ();
137 history.sample (now - start);
140 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
142 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
144 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
145 ACE_High_Res_Timer::global_scale_factor_type gsf =
146 ACE_High_Res_Timer::global_scale_factor ();
147 ACE_DEBUG ((LM_DEBUG, "done\n"));
149 if (do_dump_history)
151 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
154 ACE_Basic_Stats stats;
155 history.collect_basic_stats (stats);
156 stats.dump_results (ACE_TEXT("Total"), gsf);
158 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
159 test_end - test_start,
160 stats.samples_count ());
164 void
165 test_short_seq (Test::Roundtrip_ptr roundtrip)
167 ACE_Sample_History history (niterations);
169 Test::short_load sl (sz);
170 sl.length (sz);
172 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
173 for (int i = 0; i < niterations; ++i)
175 ACE_hrtime_t start = ACE_OS::gethrtime ();
177 (void) roundtrip->test_short_method (sl,
178 start);
180 ACE_hrtime_t now = ACE_OS::gethrtime ();
181 history.sample (now - start);
184 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
186 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
188 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
189 ACE_High_Res_Timer::global_scale_factor_type gsf =
190 ACE_High_Res_Timer::global_scale_factor ();
191 ACE_DEBUG ((LM_DEBUG, "done\n"));
193 if (do_dump_history)
195 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
198 ACE_Basic_Stats stats;
199 history.collect_basic_stats (stats);
200 stats.dump_results (ACE_TEXT("Total"), gsf);
202 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
203 test_end - test_start,
204 stats.samples_count ());
208 void
209 test_char_seq (Test::Roundtrip_ptr roundtrip)
211 ACE_Sample_History history (niterations);
213 Test::char_load cl (sz);
214 cl.length (sz);
216 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
217 for (int i = 0; i < niterations; ++i)
219 ACE_hrtime_t start = ACE_OS::gethrtime ();
221 (void) roundtrip->test_char_method (cl,
222 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,
266 start);
268 ACE_hrtime_t now = ACE_OS::gethrtime ();
269 history.sample (now - start);
272 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
274 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
276 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
277 ACE_High_Res_Timer::global_scale_factor_type gsf =
278 ACE_High_Res_Timer::global_scale_factor ();
279 ACE_DEBUG ((LM_DEBUG, "done\n"));
281 if (do_dump_history)
283 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
286 ACE_Basic_Stats stats;
287 history.collect_basic_stats (stats);
288 stats.dump_results (ACE_TEXT("Total"), gsf);
290 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
291 test_end - test_start,
292 stats.samples_count ());
296 void
297 test_double_seq (Test::Roundtrip_ptr roundtrip)
299 ACE_Sample_History history (niterations);
301 Test::double_load dl (sz);
302 dl.length (sz);
304 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
305 for (int i = 0; i < niterations; ++i)
307 ACE_hrtime_t start = ACE_OS::gethrtime ();
309 (void) roundtrip->test_double_method (dl,
310 start);
312 ACE_hrtime_t now = ACE_OS::gethrtime ();
313 history.sample (now - start);
316 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
318 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
320 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
321 ACE_High_Res_Timer::global_scale_factor_type gsf =
322 ACE_High_Res_Timer::global_scale_factor ();
323 ACE_DEBUG ((LM_DEBUG, "done\n"));
325 if (do_dump_history)
327 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
330 ACE_Basic_Stats stats;
331 history.collect_basic_stats (stats);
332 stats.dump_results (ACE_TEXT("Total"), gsf);
334 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
335 test_end - test_start,
336 stats.samples_count ());
341 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
343 int priority =
344 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
345 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
346 // Enable FIFO scheduling
348 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
349 priority,
350 ACE_SCOPE_PROCESS)) != 0)
352 if (ACE_OS::last_error () == EPERM)
354 ACE_DEBUG ((LM_DEBUG,
355 "client (%P|%t): user is not superuser, "
356 "test runs in time-shared class\n"));
358 else
359 ACE_ERROR ((LM_ERROR,
360 "client (%P|%t): sched_params failed\n"));
365 CORBA::ORB_var orb =
366 CORBA::ORB_init (argc, argv);
368 if (parse_args (argc, argv) != 0)
369 return 1;
371 CORBA::Object_var object =
372 orb->string_to_object (ior);
374 Test::Roundtrip_var roundtrip =
375 Test::Roundtrip::_narrow (object.in ());
377 if (CORBA::is_nil (roundtrip.in ()))
379 ACE_ERROR_RETURN ((LM_ERROR,
380 "Nil Test::Roundtrip reference <%s>\n",
381 ior),
386 Test::octet_load oc;
388 for (int j = 0; j < 100; ++j)
390 ACE_hrtime_t start = 0;
391 (void) roundtrip->test_octet_method (oc,
392 start);
395 if (ACE_OS::strcmp (data_type, ACE_TEXT( "octet")) == 0)
397 test_octet_seq (roundtrip.in ());
399 else if (ACE_OS::strcmp (data_type, ACE_TEXT("char")) == 0)
401 test_char_seq (roundtrip.in ());
403 else if (ACE_OS::strcmp (data_type, ACE_TEXT("long")) == 0)
405 test_long_seq (roundtrip.in ());
407 else if (ACE_OS::strcmp (data_type, ACE_TEXT("short")) == 0)
409 test_short_seq (roundtrip.in ());
411 else if (ACE_OS::strcmp (data_type, ACE_TEXT("double")) == 0)
413 test_double_seq (roundtrip.in ());
415 else if (ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) == 0)
417 test_longlong_seq (roundtrip.in ());
420 if (do_shutdown)
422 roundtrip->shutdown ();
425 catch (const CORBA::Exception& ex)
427 ex._tao_print_exception ("Exception caught:");
428 return 1;
431 return 0;