2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/Sched_Params.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;
15 int do_dump_history
= 0;
18 const ACE_TCHAR
*data_type
= ACE_TEXT("octet");
21 parse_args (int argc
, ACE_TCHAR
*argv
[])
23 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("ht:xs:k:i:"));
26 while ((c
= get_opts ()) != -1)
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)
50 ior
= get_opts
.opt_arg ();
54 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
58 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
63 ACE_ERROR_RETURN ((LM_ERROR
,
67 "-x (disable shutdown) "
73 // Indicates successful parsing of the command line
78 test_octet_seq (Test::Roundtrip_ptr roundtrip
)
80 ACE_Sample_History
history (niterations
);
82 Test::octet_load
ol (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
,
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"));
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 ());
122 test_long_seq (Test::Roundtrip_ptr roundtrip
)
124 ACE_Sample_History
history (niterations
);
126 Test::long_load
ll (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
,
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"));
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 ());
165 test_short_seq (Test::Roundtrip_ptr roundtrip
)
167 ACE_Sample_History
history (niterations
);
169 Test::short_load
sl (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
,
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"));
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 ());
207 test_char_seq (Test::Roundtrip_ptr roundtrip
)
209 ACE_Sample_History
history (niterations
);
211 Test::char_load
cl (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
,
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"));
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 ());
250 test_longlong_seq (Test::Roundtrip_ptr roundtrip
)
252 ACE_Sample_History
history (niterations
);
254 Test::longlong_load
ll (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
,
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"));
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 ());
294 test_double_seq (Test::Roundtrip_ptr roundtrip
)
296 ACE_Sample_History
history (niterations
);
298 Test::double_load
dl (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
,
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"));
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
[])
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
,
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"));
356 ACE_ERROR ((LM_ERROR
,
357 "client (%P|%t): sched_params failed\n"));
363 CORBA::ORB_init (argc
, argv
);
365 if (parse_args (argc
, argv
) != 0)
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",
384 for (int j
= 0; j
< 100; ++j
)
386 ACE_hrtime_t start
= 0;
387 (void) roundtrip
->test_octet_method (oc
,
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 ());
418 roundtrip
->shutdown ();
421 catch (const CORBA::Exception
& ex
)
423 ex
._tao_print_exception ("Exception caught:");