1 #include "Callback_i.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/PortableServer/PortableServer.h"
5 #include "tao/Strategies/advanced_resource.h"
6 #include "tao/AnyTypeCode/Any.h"
7 #include "ace/High_Res_Timer.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/Basic_Stats.h"
10 #include "ace/Stats.h"
11 #include "ace/Throughput_Stats.h"
12 #include "ace/Sched_Params.h"
14 #include "ace/OS_NS_errno.h"
16 int iterations
= 1000;
17 int do_dump_history
= 0;
18 const ACE_TCHAR
*ior
= ACE_TEXT("file://server.ior");
20 /// Parse the arguments.
21 static int parse_args (int argc
, ACE_TCHAR
*argv
[]);
23 /// Send events in another thread
24 class Task
: public ACE_Task_Base
28 Task (Test::Server_ptr server
, int iterations
);
30 /// Return 1 when all the messages have been sent
33 /// Run the experiment
38 Test::Server_var server_
;
40 /// Number of messages that have to be sent
41 int remaining_messages_
;
43 /// Synchronize access to remaining_messages_
44 TAO_SYNCH_MUTEX mutex_
;
48 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
51 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
52 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
53 priority
= ACE_Sched_Params::next_priority (ACE_SCHED_FIFO
,
55 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
57 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
59 ACE_SCOPE_PROCESS
)) != 0)
61 if (ACE_OS::last_error () == EPERM
)
64 "client (%P|%t): user is not superuser, "
65 "test runs in time-shared class\n"));
69 "client (%P|%t): sched_params failed\n"));
75 CORBA::ORB_init (argc
, argv
);
77 CORBA::Object_var manager_object
=
78 orb
->resolve_initial_references ("ORBPolicyManager");
80 CORBA::PolicyManager_var policy_manager
=
81 CORBA::PolicyManager::_narrow (manager_object
.in ());
83 CORBA::Any sync_scope
;
84 sync_scope
<<= Messaging::SYNC_WITH_TARGET
;
86 CORBA::PolicyList
policy_list (1);
87 policy_list
.length (1);
89 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
91 policy_manager
->set_policy_overrides (policy_list
,
94 CORBA::Object_var poa_object
=
95 orb
->resolve_initial_references("RootPOA");
97 if (CORBA::is_nil (poa_object
.in ()))
98 ACE_ERROR_RETURN ((LM_ERROR
,
99 " (%P|%t) Unable to initialize the POA.\n"),
102 PortableServer::POA_var root_poa
=
103 PortableServer::POA::_narrow (poa_object
.in ());
105 PortableServer::POAManager_var poa_manager
=
106 root_poa
->the_POAManager ();
108 poa_manager
->activate ();
110 if (parse_args (argc
, argv
) != 0)
113 // Get the event channel object reference
114 CORBA::Object_var object
=
115 orb
->string_to_object (ior
);
117 Test::Server_var server
=
118 Test::Server::_narrow (object
.in ());
119 if (CORBA::is_nil (server
.in ()))
121 ACE_ERROR ((LM_ERROR
,
122 "(%P|%t) Invalid or nil event channel\n"));
126 ACE_DEBUG ((LM_DEBUG
, "Resolved server\n"));
128 Callback_i
callback_i (iterations
);
130 Test::Callback_var callback
= callback_i
._this ();
132 server
->set_callback (callback
.in ());
134 ACE_DEBUG ((LM_DEBUG
, "Connected callback\n"));
136 Task
task (server
.in (), iterations
);
139 ACE_hrtime_t start
= ACE_OS::gethrtime ();
140 while (!callback_i
.done () || !task
.done ())
142 ACE_Time_Value
tv (1, 0);
145 ACE_hrtime_t end
= ACE_OS::gethrtime ();
147 ACE_Thread_Manager::instance ()->wait ();
149 // Calibrate the high resolution timer *before* starting the
151 ACE_DEBUG ((LM_DEBUG
, "Calibrating high res timer ...."));
152 ACE_High_Res_Timer::calibrate ();
154 ACE_High_Res_Timer::global_scale_factor_type gsf
=
155 ACE_High_Res_Timer::global_scale_factor ();
156 ACE_DEBUG ((LM_DEBUG
, "Done (%d)\n", gsf
));
158 ACE_Sample_History
&history
=
159 callback_i
.sample_history ();
162 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
165 ACE_Basic_Stats stats
;
166 history
.collect_basic_stats (stats
);
167 stats
.dump_results (ACE_TEXT("Total"), gsf
);
169 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
171 stats
.samples_count ());
175 PortableServer::ObjectId_var id
=
176 root_poa
->servant_to_id (&callback_i
);
177 root_poa
->deactivate_object (id
.in ());
180 catch (const CORBA::Exception
& ex
)
182 ex
._tao_print_exception (argv
[0]);
187 // ****************************************************************
190 parse_args (int argc
, ACE_TCHAR
*argv
[])
192 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hi:k:"));
195 while ((c
= get_opts ()) != -1)
203 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
207 ior
= get_opts
.opt_arg ();
212 ACE_ERROR_RETURN ((LM_ERROR
,
214 "-h (dump full sample history) "
221 // Indicates successful parsing of the command line
225 // ****************************************************************
227 Task::Task (Test::Server_ptr server
,
229 : server_ (Test::Server::_duplicate (server
))
230 , remaining_messages_ (iterations
)
237 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, 1);
238 return this->remaining_messages_
== 0;
244 Test::Payload
payload(1024); payload
.length(1024);
249 Test::TimeStamp creation
= ACE_OS::gethrtime ();
250 this->server_
->request (creation
, payload
);
252 // ACE_Time_Value tv (0, 5000);
253 // ACE_OS::sleep (tv);
255 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, -1);
257 this->remaining_messages_
--;
258 if (this->remaining_messages_
== 0)
262 catch (const CORBA::SystemException
& ex
)
264 ex
._tao_print_exception ("Task::svc");
265 this->remaining_messages_
= 0;