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
, priority
);
55 // Enable FIFO scheduling
56 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
58 ACE_SCOPE_PROCESS
)) != 0)
60 if (ACE_OS::last_error () == EPERM
)
63 "client (%P|%t): user is not superuser, "
64 "test runs in time-shared class\n"));
68 "client (%P|%t): sched_params failed\n"));
74 CORBA::ORB_init (argc
, argv
);
76 CORBA::Object_var manager_object
=
77 orb
->resolve_initial_references ("ORBPolicyManager");
79 CORBA::PolicyManager_var policy_manager
=
80 CORBA::PolicyManager::_narrow (manager_object
.in ());
82 CORBA::Any sync_scope
;
83 sync_scope
<<= Messaging::SYNC_WITH_TARGET
;
85 CORBA::PolicyList
policy_list (1);
86 policy_list
.length (1);
88 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
90 policy_manager
->set_policy_overrides (policy_list
,
93 CORBA::Object_var poa_object
=
94 orb
->resolve_initial_references("RootPOA");
96 if (CORBA::is_nil (poa_object
.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 " (%P|%t) Unable to initialize the POA.\n"),
101 PortableServer::POA_var root_poa
=
102 PortableServer::POA::_narrow (poa_object
.in ());
104 PortableServer::POAManager_var poa_manager
=
105 root_poa
->the_POAManager ();
107 poa_manager
->activate ();
109 if (parse_args (argc
, argv
) != 0)
112 // Get the event channel object reference
113 CORBA::Object_var object
=
114 orb
->string_to_object (ior
);
116 Test::Server_var server
=
117 Test::Server::_narrow (object
.in ());
118 if (CORBA::is_nil (server
.in ()))
120 ACE_ERROR ((LM_ERROR
,
121 "(%P|%t) Invalid or nil event channel\n"));
125 ACE_DEBUG ((LM_DEBUG
, "Resolved server\n"));
127 Callback_i
callback_i (iterations
);
129 Test::Callback_var callback
= callback_i
._this ();
131 server
->set_callback (callback
.in ());
133 ACE_DEBUG ((LM_DEBUG
, "Connected callback\n"));
135 Task
task (server
.in (), iterations
);
138 ACE_hrtime_t start
= ACE_OS::gethrtime ();
139 while (!callback_i
.done () || !task
.done ())
141 ACE_Time_Value
tv (1, 0);
144 ACE_hrtime_t end
= ACE_OS::gethrtime ();
146 ACE_Thread_Manager::instance ()->wait ();
148 // Calibrate the high resolution timer *before* starting the
150 ACE_DEBUG ((LM_DEBUG
, "Calibrating high res timer ...."));
151 ACE_High_Res_Timer::calibrate ();
153 ACE_High_Res_Timer::global_scale_factor_type gsf
=
154 ACE_High_Res_Timer::global_scale_factor ();
155 ACE_DEBUG ((LM_DEBUG
, "Done (%d)\n", gsf
));
157 ACE_Sample_History
&history
=
158 callback_i
.sample_history ();
161 history
.dump_samples (ACE_TEXT("HISTORY"), gsf
);
164 ACE_Basic_Stats stats
;
165 history
.collect_basic_stats (stats
);
166 stats
.dump_results (ACE_TEXT("Total"), gsf
);
168 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf
,
170 stats
.samples_count ());
174 PortableServer::ObjectId_var id
=
175 root_poa
->servant_to_id (&callback_i
);
176 root_poa
->deactivate_object (id
.in ());
179 catch (const CORBA::Exception
& ex
)
181 ex
._tao_print_exception (argv
[0]);
186 // ****************************************************************
189 parse_args (int argc
, ACE_TCHAR
*argv
[])
191 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("hi:k:"));
194 while ((c
= get_opts ()) != -1)
202 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
206 ior
= get_opts
.opt_arg ();
211 ACE_ERROR_RETURN ((LM_ERROR
,
213 "-h (dump full sample history) "
220 // Indicates successful parsing of the command line
224 // ****************************************************************
226 Task::Task (Test::Server_ptr server
,
228 : server_ (Test::Server::_duplicate (server
))
229 , remaining_messages_ (iterations
)
236 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, 1);
237 return this->remaining_messages_
== 0;
243 Test::Payload
payload(1024); payload
.length(1024);
248 Test::TimeStamp creation
= ACE_OS::gethrtime ();
249 this->server_
->request (creation
, payload
);
251 // ACE_Time_Value tv (0, 5000);
252 // ACE_OS::sleep (tv);
254 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, -1);
256 this->remaining_messages_
--;
257 if (this->remaining_messages_
== 0)
261 catch (const CORBA::SystemException
& ex
)
263 ex
._tao_print_exception ("Task::svc");
264 this->remaining_messages_
= 0;