Cleanup Solaris support
[ACE_TAO.git] / TAO / performance-tests / Callback / client.cpp
blobdf0df95f20c805505dc42f0a1e2246fb77520b10
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"
13 #include "ace/Task.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
26 public:
27 /// Constructor
28 Task (Test::Server_ptr server, int iterations);
30 /// Return 1 when all the messages have been sent
31 int done ();
33 /// Run the experiment
34 int svc ();
36 private:
37 /// The consumer
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_;
47 int
48 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
50 int priority =
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,
57 priority,
58 ACE_SCOPE_PROCESS)) != 0)
60 if (ACE_OS::last_error () == EPERM)
62 ACE_DEBUG ((LM_DEBUG,
63 "client (%P|%t): user is not superuser, "
64 "test runs in time-shared class\n"));
66 else
67 ACE_ERROR ((LM_ERROR,
68 "client (%P|%t): sched_params failed\n"));
71 try
73 CORBA::ORB_var orb =
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);
87 policy_list[0] =
88 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
89 sync_scope);
90 policy_manager->set_policy_overrides (policy_list,
91 CORBA::SET_OVERRIDE);
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"),
99 1);
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)
110 return 1;
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"));
122 return 1;
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);
136 task.activate ();
138 ACE_hrtime_t start = ACE_OS::gethrtime ();
139 while (!callback_i.done () || !task.done ())
141 ACE_Time_Value tv (1, 0);
142 orb->run (tv);
144 ACE_hrtime_t end = ACE_OS::gethrtime ();
146 ACE_Thread_Manager::instance ()->wait ();
148 // Calibrate the high resolution timer *before* starting the
149 // test.
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 ();
159 if (do_dump_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,
169 end - start,
170 stats.samples_count ());
172 server->shutdown ();
174 PortableServer::ObjectId_var id =
175 root_poa->servant_to_id (&callback_i);
176 root_poa->deactivate_object (id.in ());
177 orb->destroy ();
179 catch (const CORBA::Exception& ex)
181 ex._tao_print_exception (argv[0]);
183 return 0;
186 // ****************************************************************
189 parse_args (int argc, ACE_TCHAR *argv[])
191 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hi:k:"));
192 int c;
194 while ((c = get_opts ()) != -1)
195 switch (c)
197 case 'h':
198 do_dump_history = 1;
199 break;
201 case 'i':
202 iterations = ACE_OS::atoi (get_opts.opt_arg ());
203 break;
205 case 'k':
206 ior = get_opts.opt_arg ();
207 break;
209 case '?':
210 default:
211 ACE_ERROR_RETURN ((LM_ERROR,
212 "usage: %s "
213 "-h (dump full sample history) "
214 "-i <iterations> "
215 "-k <IOR> "
216 "\n",
217 argv [0]),
218 -1);
220 // Indicates successful parsing of the command line
221 return 0;
224 // ****************************************************************
226 Task::Task (Test::Server_ptr server,
227 int iterations)
228 : server_ (Test::Server::_duplicate (server))
229 , remaining_messages_ (iterations)
234 Task::done ()
236 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, 1);
237 return this->remaining_messages_ == 0;
241 Task::svc ()
243 Test::Payload payload(1024); payload.length(1024);
246 for (;;)
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)
258 return 0;
261 catch (const CORBA::SystemException& ex)
263 ex._tao_print_exception ("Task::svc");
264 this->remaining_messages_ = 0;
266 return 0;