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;
14 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("t:s:hxk:i:"));
26 while ((c
= get_opts ()) != -1)
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)
42 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
54 ior
= get_opts
.opt_arg ();
58 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
63 ACE_ERROR_RETURN ((LM_ERROR
,
69 "-x (disable shutdown) "
75 // Indicates successful parsing of the command line
81 test_octet_seq (Test::Roundtrip_ptr roundtrip
)
83 ACE_Sample_History
history (niterations
);
85 Test::octet_load
ol (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"));
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 ());
124 test_long_seq (Test::Roundtrip_ptr roundtrip
)
126 ACE_Sample_History
history (niterations
);
128 Test::long_load
ll (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"));
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 ());
167 test_short_seq (Test::Roundtrip_ptr roundtrip
)
169 ACE_Sample_History
history (niterations
);
171 Test::short_load
sl (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"));
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 ());
210 test_char_seq (Test::Roundtrip_ptr roundtrip
)
212 ACE_Sample_History
history (niterations
);
214 Test::char_load
cl (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"));
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
, 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"));
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 ());
296 test_double_seq (Test::Roundtrip_ptr roundtrip
)
298 ACE_Sample_History
history (niterations
);
300 Test::double_load
dl (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"));
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
[])
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
,
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"));
357 ACE_ERROR ((LM_ERROR
,
358 "client (%P|%t): sched_params failed\n"));
364 CORBA::ORB_init (argc
, argv
);
366 if (parse_args (argc
, argv
) != 0)
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",
385 for (int j
= 0; j
< 100; ++j
)
387 ACE_hrtime_t start
= 0;
388 (void) roundtrip
->test_octet_method (oc
,
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 ());
419 roundtrip
->shutdown ();
422 catch (const CORBA::Exception
& ex
)
424 ex
._tao_print_exception ("Exception caught:");