2 //=============================================================================
6 * This is the client program that tests TAO's Smart Proxy extension.
8 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
10 //=============================================================================
14 #include "Smart_Proxy_Impl.h"
15 #include "tao/debug.h"
16 #include "ace/High_Res_Timer.h"
17 #include "ace/Sched_Params.h"
18 #include "ace/Stats.h"
19 #include "ace/Throughput_Stats.h"
20 #include "ace/Get_Opt.h"
21 #include "ace/OS_NS_string.h"
22 #include "ace/OS_NS_errno.h"
24 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
26 int register_smart_proxy
= 1;
31 void accumulate_into (ACE_Throughput_Stats
&throughput
) const
33 // Accumulate the throughput statistics into <throughput>
34 throughput
.accumulate (this->throughput_
);
36 void dump_stats (const ACE_TCHAR
* msg
,
37 ACE_High_Res_Timer::global_scale_factor_type gsf
)
40 this->throughput_
.dump_results (msg
, gsf
);
42 void sample (ACE_hrtime_t throughput_diff
,
43 ACE_hrtime_t latency_diff
)
46 this->throughput_
.sample (throughput_diff
,
50 /// Keep throughput statistics on a per-thread basis
51 ACE_Throughput_Stats throughput_
;
56 parse_args (int argc
, ACE_TCHAR
*argv
[])
58 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("i:n:r:"));
61 while ((c
= get_opts ()) != -1)
65 ior
= get_opts
.opt_arg ();
68 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
71 register_smart_proxy
= ACE_OS::atoi (get_opts
.opt_arg ());
75 ACE_ERROR_RETURN ((LM_ERROR
,
87 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
90 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
91 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
92 // Enable FIFO scheduling
94 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
96 ACE_SCOPE_PROCESS
)) != 0)
98 if (ACE_OS::last_error () == EPERM
)
100 ACE_DEBUG ((LM_DEBUG
,
101 "client (%P|%t): user is not superuser, "
102 "test runs in time-shared class\n"));
105 ACE_ERROR ((LM_ERROR
,
106 "client (%P|%t): sched_params failed\n"));
112 CORBA::ORB_init (argc
,
115 if (parse_args (argc
, argv
) != 0)
118 CORBA::Object_var object
=
119 orb
->string_to_object (ior
);
120 if (register_smart_proxy
== 1)
122 // To use the smart proxy it is necessary to allocate the
123 // user-defined smart factory on the heap as the smart proxy
124 // generated classes take care of destroying the object. This
125 // way it a win situation for the application developer who
126 // doesnt have to make sure to destroy it and also for the smart
127 // proxy designer who now can manage the lifetime of the object
130 Smart_Test_Factory
*test_factory
= 0;
131 ACE_NEW_RETURN (test_factory
,
135 ACE_UNUSED_ARG (test_factory
);
139 Test::_narrow (object
.in ());
141 if (CORBA::is_nil (server
.in ()))
142 ACE_ERROR_RETURN ((LM_ERROR
,
143 "Object reference <%s> is nil.\n",
147 ACE_Throughput_Stats throughput
;
149 ACE_DEBUG ((LM_DEBUG
, "High res. timer calibration...."));
150 ACE_High_Res_Timer::global_scale_factor_type gsf
=
151 ACE_High_Res_Timer::global_scale_factor ();
152 ACE_DEBUG ((LM_DEBUG
, "done\n"));
154 marker
.accumulate_into (throughput
);
155 CORBA::Short price
=0;
157 ACE_hrtime_t throughput_base
= ACE_OS::gethrtime ();
158 for (i
= 0; i
< niterations
; ++i
)
160 // Record current time.
161 ACE_hrtime_t latency_base
= ACE_OS::gethrtime ();
163 price
= server
->box_prices ();
166 cost
= server
->tickets (5);
168 // Grab timestamp again.
169 ACE_hrtime_t now
= ACE_OS::gethrtime ();
171 // Record statistics.
172 marker
.sample (now
- throughput_base
,
175 if (TAO_debug_level
> 0 && i
% 100 == 0)
176 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) iteration <%d> - price <%d> - cost <%d>\n",
180 marker
.dump_stats (ACE_TEXT("buying tickets "), gsf
);
186 Test::_narrow (object.in ());
188 if (CORBA::is_nil (server1.in ()))
189 ACE_ERROR_RETURN ((LM_ERROR,
190 "Object reference <%C> is nil.\n",
194 ACE_Throughput_Stats throughput1;
196 ACE_DEBUG ((LM_DEBUG, "High res. timer calibration...."));
197 ACE_High_Res_Timer::global_scale_factor_type gsf1 =
198 ACE_High_Res_Timer::global_scale_factor ();
199 ACE_DEBUG ((LM_DEBUG, "done\n"));
201 marker1.accumulate_into (throughput1);
202 CORBA::Short price1 =0;
203 CORBA::Long cost1 =0;
204 ACE_hrtime_t throughput_base1 = ACE_OS::gethrtime ();
205 for (i = 0; i < niterations ; ++i)
207 // Record current time.
208 ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
210 price1 = server1->box_prices ();
213 cost = server1->tickets (5);
215 // Grab timestamp again.
216 ACE_hrtime_t now = ACE_OS::gethrtime ();
218 // Record statistics.
219 marker.sample (now - throughput_base1,
222 if (TAO_debug_level > 0 && i % 100 == 0)
223 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n", i));
226 marker1.dump_stats (ACE_TEXT("buying tickets using a default proxy "), gsf1);
228 server1->shutdown ();
232 catch (const CORBA::Exception
& ex
)
234 ex
._tao_print_exception ("Client-side exception:");