Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / Single_Threaded / client.cpp
blob2b48adf7df44f63e5eb97d9e6c6175d835ef5a94
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 sz = 512;
15 int do_dump_history = 0;
16 int do_shutdown = 1;
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("ht:xs:k:i:"));
24 int c;
26 while ((c = get_opts ()) != -1)
27 switch (c)
29 case 'h':
30 do_dump_history = 1;
31 break;
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 'x':
46 do_shutdown = 0;
47 break;
49 case 'k':
50 ior = get_opts.opt_arg ();
51 break;
53 case 'i':
54 niterations = ACE_OS::atoi (get_opts.opt_arg ());
55 break;
57 case 's':
58 sz = ACE_OS::atoi (get_opts.opt_arg ());
59 break;
61 case '?':
62 default:
63 ACE_ERROR_RETURN ((LM_ERROR,
64 "usage: %s "
65 "-k <ior> "
66 "-i <niterations> "
67 "-x (disable shutdown) "
68 "-h (dump history) "
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 ();
95 history.sample (now - start);
98 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
100 ACE_DEBUG ((LM_DEBUG, "Octet test finished\n"));
102 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
103 ACE_High_Res_Timer::global_scale_factor_type gsf =
104 ACE_High_Res_Timer::global_scale_factor ();
105 ACE_DEBUG ((LM_DEBUG, "done\n"));
107 if (do_dump_history)
109 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
112 ACE_Basic_Stats stats;
113 history.collect_basic_stats (stats);
114 stats.dump_results (ACE_TEXT("Total"), gsf);
116 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
117 test_end - test_start,
118 stats.samples_count ());
121 void
122 test_long_seq (Test::Roundtrip_ptr roundtrip)
124 ACE_Sample_History history (niterations);
126 Test::long_load ll (sz);
127 ll.length (sz);
129 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
130 for (int i = 0; i < niterations; ++i)
132 ACE_hrtime_t start = ACE_OS::gethrtime ();
134 (void) roundtrip->test_long_method (ll,
135 start);
137 ACE_hrtime_t now = ACE_OS::gethrtime ();
138 history.sample (now - start);
141 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
143 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
145 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
146 ACE_High_Res_Timer::global_scale_factor_type gsf =
147 ACE_High_Res_Timer::global_scale_factor ();
148 ACE_DEBUG ((LM_DEBUG, "done\n"));
150 if (do_dump_history)
152 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
155 ACE_Basic_Stats stats;
156 history.collect_basic_stats (stats);
157 stats.dump_results (ACE_TEXT("Total"), gsf);
159 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
160 test_end - test_start,
161 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);
171 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
172 for (int i = 0; i < niterations; ++i)
174 ACE_hrtime_t start = ACE_OS::gethrtime ();
176 (void) roundtrip->test_short_method (sl,
177 start);
179 ACE_hrtime_t now = ACE_OS::gethrtime ();
180 history.sample (now - start);
183 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
185 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
187 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
188 ACE_High_Res_Timer::global_scale_factor_type gsf =
189 ACE_High_Res_Timer::global_scale_factor ();
190 ACE_DEBUG ((LM_DEBUG, "done\n"));
192 if (do_dump_history)
194 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
197 ACE_Basic_Stats stats;
198 history.collect_basic_stats (stats);
199 stats.dump_results (ACE_TEXT("Total"), gsf);
201 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
202 test_end - test_start,
203 stats.samples_count ());
206 void
207 test_char_seq (Test::Roundtrip_ptr roundtrip)
209 ACE_Sample_History history (niterations);
211 Test::char_load cl (sz);
212 cl.length (sz);
214 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
215 for (int i = 0; i < niterations; ++i)
217 ACE_hrtime_t start = ACE_OS::gethrtime ();
219 (void) roundtrip->test_char_method (cl,
220 start);
222 ACE_hrtime_t now = ACE_OS::gethrtime ();
223 history.sample (now - start);
226 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
228 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
230 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
231 ACE_High_Res_Timer::global_scale_factor_type gsf =
232 ACE_High_Res_Timer::global_scale_factor ();
233 ACE_DEBUG ((LM_DEBUG, "done\n"));
235 if (do_dump_history)
237 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
240 ACE_Basic_Stats stats;
241 history.collect_basic_stats (stats);
242 stats.dump_results (ACE_TEXT("Total"), gsf);
244 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
245 test_end - test_start,
246 stats.samples_count ());
249 void
250 test_longlong_seq (Test::Roundtrip_ptr roundtrip)
252 ACE_Sample_History history (niterations);
254 Test::longlong_load ll (sz);
255 ll.length (sz);
258 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
259 for (int i = 0; i < niterations; ++i)
261 ACE_hrtime_t start = ACE_OS::gethrtime ();
263 (void) roundtrip->test_longlong_method (ll,
264 start);
266 ACE_hrtime_t now = ACE_OS::gethrtime ();
267 history.sample (now - start);
270 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
272 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
274 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
275 ACE_High_Res_Timer::global_scale_factor_type gsf =
276 ACE_High_Res_Timer::global_scale_factor ();
277 ACE_DEBUG ((LM_DEBUG, "done\n"));
279 if (do_dump_history)
281 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
284 ACE_Basic_Stats stats;
285 history.collect_basic_stats (stats);
286 stats.dump_results (ACE_TEXT("Total"), gsf);
288 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
289 test_end - test_start,
290 stats.samples_count ());
293 void
294 test_double_seq (Test::Roundtrip_ptr roundtrip)
296 ACE_Sample_History history (niterations);
298 Test::double_load dl (sz);
299 dl.length (sz);
302 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
303 for (int i = 0; i < niterations; ++i)
305 ACE_hrtime_t start = ACE_OS::gethrtime ();
307 (void) roundtrip->test_double_method (dl,
308 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 ());
338 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
340 int priority =
341 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
342 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
343 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
345 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
346 priority,
347 ACE_SCOPE_PROCESS)) != 0)
349 if (ACE_OS::last_error () == EPERM)
351 ACE_DEBUG ((LM_DEBUG,
352 "client (%P|%t): user is not superuser, "
353 "test runs in time-shared class\n"));
355 else
356 ACE_ERROR ((LM_ERROR,
357 "client (%P|%t): sched_params failed\n"));
362 CORBA::ORB_var orb =
363 CORBA::ORB_init (argc, argv);
365 if (parse_args (argc, argv) != 0)
366 return 1;
368 CORBA::Object_var object =
369 orb->string_to_object (ior);
371 Test::Roundtrip_var roundtrip =
372 Test::Roundtrip::_narrow (object.in ());
374 if (CORBA::is_nil (roundtrip.in ()))
376 ACE_ERROR_RETURN ((LM_ERROR,
377 "Nil Test::Roundtrip reference <%s>\n",
378 ior),
382 Test::octet_load oc;
384 for (int j = 0; j < 100; ++j)
386 ACE_hrtime_t start = 0;
387 (void) roundtrip->test_octet_method (oc,
388 start);
391 if (ACE_OS::strcmp (data_type, ACE_TEXT("octet")) == 0)
393 test_octet_seq (roundtrip.in ());
395 else if (ACE_OS::strcmp (data_type, ACE_TEXT("char")) == 0)
397 test_char_seq (roundtrip.in ());
399 else if (ACE_OS::strcmp (data_type, ACE_TEXT("long")) == 0)
401 test_long_seq (roundtrip.in ());
403 else if (ACE_OS::strcmp (data_type, ACE_TEXT("short")) == 0)
405 test_short_seq (roundtrip.in ());
407 else if (ACE_OS::strcmp (data_type, ACE_TEXT("double")) == 0)
409 test_double_seq (roundtrip.in ());
411 else if (ACE_OS::strcmp (data_type, ACE_TEXT("longlong")) == 0)
413 test_longlong_seq (roundtrip.in ());
416 if (do_shutdown)
418 roundtrip->shutdown ();
421 catch (const CORBA::Exception& ex)
423 ex._tao_print_exception ("Exception caught:");
424 return 1;
427 return 0;