3 #include "ace/Get_Opt.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Sched_Params.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;
19 const ACE_TCHAR
*data_type
= ACE_TEXT("octet");
22 parse_args (int argc
, ACE_TCHAR
*argv
[])
24 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:s:hxk:i:"));
27 while ((c
= get_opts ()) != -1)
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)
43 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
55 ior
= get_opts
.opt_arg ();
59 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
64 ACE_ERROR_RETURN ((LM_ERROR
,
68 "-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 ();
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"));
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 ());
121 test_long_seq (Test::Roundtrip_ptr roundtrip
)
123 ACE_Sample_History
history (niterations
);
125 Test::long_load
ll (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
,
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"));
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 ());
165 test_short_seq (Test::Roundtrip_ptr roundtrip
)
167 ACE_Sample_History
history (niterations
);
169 Test::short_load
sl (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
,
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"));
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 ());
209 test_char_seq (Test::Roundtrip_ptr roundtrip
)
211 ACE_Sample_History
history (niterations
);
213 Test::char_load
cl (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
,
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"));
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 ());
253 test_longlong_seq (Test::Roundtrip_ptr roundtrip
)
255 ACE_Sample_History
history (niterations
);
257 Test::longlong_load
ll (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
,
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"));
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 ());
297 test_double_seq (Test::Roundtrip_ptr roundtrip
)
299 ACE_Sample_History
history (niterations
);
301 Test::double_load
dl (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
,
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"));
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
[])
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
,
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"));
359 ACE_ERROR ((LM_ERROR
,
360 "client (%P|%t): sched_params failed\n"));
366 CORBA::ORB_init (argc
, argv
);
368 if (parse_args (argc
, argv
) != 0)
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",
388 for (int j
= 0; j
< 100; ++j
)
390 ACE_hrtime_t start
= 0;
391 (void) roundtrip
->test_octet_method (oc
,
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 ());
422 roundtrip
->shutdown ();
425 catch (const CORBA::Exception
& ex
)
427 ex
._tao_print_exception ("Exception caught:");