1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "ace/OS_NS_string.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "ace/Sample_History.h"
6 #include "ace/High_Res_Timer.h"
8 #include "ace/Throughput_Stats.h"
12 static const ACE_TCHAR
*ior_file
= ACE_TEXT ("receiver.ior");
13 static int do_dump_history
= 0;
14 static int print_missed_invocations
= 0;
15 static ACE_High_Res_Timer::global_scale_factor_type gsf
= 0;
18 parse_args (int argc
, ACE_TCHAR
**argv
)
20 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("d:f:m:"));
23 while ((c
= get_opts ()) != -1)
27 do_dump_history
= ACE_OS::atoi (get_opts
.opt_arg ());
31 ior_file
= get_opts
.opt_arg ();
35 print_missed_invocations
= ACE_OS::atoi (get_opts
.opt_arg ());
39 ACE_ERROR_RETURN ((LM_ERROR
,
41 "\t-d <show history> (defaults to %d)\n"
42 "\t-f <ior_file> (defaults to %s)\n"
43 "\t-m <print missed invocations for paced workers> (defaults to %d)\n"
48 print_missed_invocations
),
59 test_i (CORBA::ORB_ptr orb
,
60 PortableServer::POA_ptr poa
);
64 void start_test (CORBA::Long session_id
,
66 CORBA::ULong invocation_rate
,
67 CORBA::ULong message_size
,
68 CORBA::ULong iterations
);
76 void oneway_method (CORBA::Long session_id
,
77 CORBA::ULong iteration
,
78 const ::test::octets
&payload
);
80 void twoway_method (CORBA::Long
&session_id
,
81 CORBA::ULong
&iteration
,
82 ::test::octets
&payload
);
84 //FUZZ: disable check_for_lack_ACE_OS
86 //FUZZ: enable check_for_lack_ACE_OS
88 PortableServer::POA_ptr
_default_POA ();
92 PortableServer::POA_var poa_
;
93 typedef ACE_Array_Base
<CORBA::Boolean
> Invocations
;
94 Invocations invocations_received_
;
95 ACE_hrtime_t time_of_last_call_
;
96 ACE_hrtime_t test_start_
;
97 ACE_hrtime_t test_end_
;
98 CORBA::Boolean first_invocation_
;
99 ACE_Sample_History
*inter_arrival_times_
;
100 CORBA::ULong iterations_
;
101 CORBA::ULong number_of_invocations_received_
;
102 CORBA::Long session_id_
;
105 test_i::test_i (CORBA::ORB_ptr orb
,
106 PortableServer::POA_ptr poa
)
107 : orb_ (CORBA::ORB::_duplicate (orb
)),
108 poa_ (PortableServer::POA::_duplicate (poa
)),
109 inter_arrival_times_ (0),
120 test_i::start_test (CORBA::Long session_id
,
121 const char *protocol
,
122 CORBA::ULong invocation_rate
,
123 CORBA::ULong message_size
,
124 CORBA::ULong iterations
)
126 if (TAO_debug_level
> 0)
128 ACE_DEBUG ((LM_DEBUG
,
129 "Session id starts %d\n",
133 ACE_DEBUG ((LM_DEBUG
,
134 "Protocol = %5s Invocation Rate = %3d Message Size = %5d Expected Latency = %4d ",
135 ACE_TEXT_CHAR_TO_TCHAR (protocol
),
138 1000 / invocation_rate
));
140 // Remember test parameters.
141 this->session_id_
= session_id
;
142 this->iterations_
= iterations
;
143 this->number_of_invocations_received_
= 0;
146 // Initialize counters and tables.
148 this->inter_arrival_times_
=
149 new ACE_Sample_History (iterations
);
151 this->first_invocation_
= 1;
153 this->invocations_received_
.size (iterations
);
154 for (CORBA::ULong i
= 0;
157 this->invocations_received_
[i
] = 0;
159 // Record start time.
161 ACE_OS::gethrtime ();
169 ACE_OS::gethrtime ();
173 this->inter_arrival_times_
->dump_samples (ACE_TEXT("Inter-arrival times"), gsf
);
176 ACE_Basic_Stats stats
;
177 this->inter_arrival_times_
->collect_basic_stats (stats
);
179 ACE_DEBUG ((LM_DEBUG
,
180 "Max Latency = %6d ",
181 stats
.max_
/ gsf
/ 1000));
183 ACE_DEBUG ((LM_DEBUG
,
184 "Invocations expected / received / missed / missed %% = %6d / %6d / %6d / %5.2f\n",
186 this->number_of_invocations_received_
,
187 this->iterations_
- this->number_of_invocations_received_
,
188 (this->iterations_
- this->number_of_invocations_received_
) / (double) this->iterations_
* 100));
190 if (print_missed_invocations
)
192 ACE_DEBUG ((LM_DEBUG
, "\nFollowing invocations were never received:\n"));
194 for (CORBA::ULong i
= 0;
195 i
< this->iterations_
;
198 if (this->invocations_received_
[i
] == 0)
200 ACE_DEBUG ((LM_DEBUG
,
206 ACE_DEBUG ((LM_DEBUG
, "\n"));
209 if (TAO_debug_level
> 0)
211 ACE_DEBUG ((LM_DEBUG
,
212 "Session id ends %d\n",
215 stats
.dump_results (ACE_TEXT("Inter-arrival times"), gsf
);
217 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Inter-arrival times"),
219 this->test_end_
- this->test_start_
,
220 stats
.samples_count ());
223 this->session_id_
= -1;
225 delete this->inter_arrival_times_
;
229 test_i::oneway_sync ()
234 test_i::twoway_sync ()
239 test_i::oneway_method (CORBA::Long session_id
,
240 CORBA::ULong iteration
,
241 const ::test::octets
&payload
)
243 if (this->session_id_
!= session_id
)
245 ACE_DEBUG ((LM_DEBUG
,
246 "Late message with iteration id = %d: will not count message\n",
251 if (TAO_debug_level
> 0)
253 ACE_DEBUG ((LM_DEBUG
,
254 "test_i::oneway_method -> session id = %d iteration = %d payload size = %d\n",
260 this->invocations_received_
[iteration
] = 1;
261 ++this->number_of_invocations_received_
;
263 ACE_hrtime_t time_of_current_call
=
264 ACE_OS::gethrtime ();
266 if (this->first_invocation_
)
267 this->first_invocation_
= 0;
269 this->inter_arrival_times_
->sample (time_of_current_call
- this->time_of_last_call_
);
271 this->time_of_last_call_
= time_of_current_call
;
275 test_i::twoway_method (CORBA::Long
&session_id
,
276 CORBA::ULong
&iteration
,
277 ::test::octets
&payload
)
279 if (this->session_id_
!= session_id
)
281 ACE_DEBUG ((LM_DEBUG
,
282 "Late message with iteration id = %d: will not count message\n",
287 if (TAO_debug_level
> 0)
289 ACE_DEBUG ((LM_DEBUG
,
290 "test_i::twoway_method -> session id = %d iteration = %d payload size = %d\n",
296 this->invocations_received_
[iteration
] = 1;
297 ++this->number_of_invocations_received_
;
299 ACE_hrtime_t time_of_current_call
=
300 ACE_OS::gethrtime ();
302 if (this->first_invocation_
)
303 this->first_invocation_
= 0;
305 this->inter_arrival_times_
->sample (time_of_current_call
- this->time_of_last_call_
);
307 this->time_of_last_call_
= time_of_current_call
;
310 PortableServer::POA_ptr
311 test_i::_default_POA ()
313 return PortableServer::POA::_duplicate (this->poa_
.in ());
319 ACE_DEBUG ((LM_DEBUG
,
320 "test_i::shutdown\n"));
322 this->orb_
->shutdown (false);
326 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
328 gsf
= ACE_High_Res_Timer::global_scale_factor ();
333 CORBA::ORB_init (argc
, argv
);
335 int parse_args_result
=
336 parse_args (argc
, argv
);
337 if (parse_args_result
!= 0)
338 return parse_args_result
;
340 CORBA::Object_var object
=
341 orb
->resolve_initial_references ("RootPOA");
343 PortableServer::POA_var root_poa
=
344 PortableServer::POA::_narrow (object
.in ());
346 PortableServer::POAManager_var poa_manager
=
347 root_poa
->the_POAManager ();
350 new test_i (orb
.in (),
353 PortableServer::ServantBase_var
safe_servant (servant
);
358 CORBA::String_var ior
=
359 orb
->object_to_string (test
.in ());
362 ACE_OS::fopen (ior_file
, "w");
363 ACE_ASSERT (output_file
!= 0);
366 ACE_OS::fprintf (output_file
,
369 ACE_ASSERT (result
== ACE_OS::strlen (ior
.in ()));
370 ACE_UNUSED_ARG (result
);
372 ACE_OS::fclose (output_file
);
374 poa_manager
->activate ();
379 catch (const CORBA::Exception
& ex
)
381 ex
._tao_print_exception ("Exception caught");