Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Benchmark / client.cpp
blobffbb009c40bead77705b204b7cc35307ea235131
1 #include "testC.h"
2 #include "marker.h"
3 #include "Client_ORBInitializer.h"
4 #include "Interceptor_Type.h"
6 #include "tao/debug.h"
7 #include "tao/ORBInitializer_Registry.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/OS_NS_errno.h"
12 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
13 int niterations = 5;
14 int register_interceptor = 1;
16 int
17 parse_args (int argc, ACE_TCHAR *argv[])
19 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ef:n:"));
20 int c;
22 while ((c = get_opts ()) != -1)
23 switch (c)
25 case 'e':
26 break;
27 case 'f':
28 ior = get_opts.opt_arg ();
29 break;
30 case 'n':
31 niterations = ACE_OS::atoi (get_opts.opt_arg ());
32 break;
33 case '?':
34 default:
35 ACE_ERROR_RETURN ((LM_ERROR,
36 "usage: %s "
37 "-v -r <register_interceptor> "
38 "\n",
39 argv [0]),
40 -1);
42 return 0;
46 void
47 run_test (Test_Interceptors::Secure_Vault_ptr server)
49 int i = 0;
50 const char user[] = "root";
51 Marker marker;
52 ACE_Throughput_Stats throughput;
54 ACE_DEBUG ((LM_DEBUG, "High res. timer calibration...."));
55 ACE_High_Res_Timer::global_scale_factor_type gsf =
56 ACE_High_Res_Timer::global_scale_factor ();
57 ACE_DEBUG ((LM_DEBUG, "done\n"));
59 marker.accumulate_into (throughput, 1);
60 ACE_hrtime_t throughput_base = ACE_OS::gethrtime ();
61 for (i = 0; i < niterations ; ++i)
63 // Record current time.
64 ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
66 server->ready ();
68 // Grab timestamp again.
69 ACE_hrtime_t now = ACE_OS::gethrtime ();
71 // Record statistics.
72 marker.sample (now - throughput_base,
73 now - latency_base,
74 1);
76 if (TAO_debug_level > 0 && i % 100 == 0)
77 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n", i));
80 marker.dump_stats (ACE_TEXT ("Ready method "), gsf, 1);
82 try
84 marker.accumulate_into (throughput, 2);
85 throughput_base = ACE_OS::gethrtime ();
87 for (i = 0; i < niterations ; ++i)
89 // Record current time.
90 ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
92 server->authenticate (user);
94 // Grab timestamp again.
95 ACE_hrtime_t now = ACE_OS::gethrtime ();
97 // Record statistics.
98 marker.sample (now - throughput_base,
99 now - latency_base,
102 if (TAO_debug_level > 0 && i % 100 == 0)
103 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n", i));
105 marker.dump_stats (ACE_TEXT ("Authenticate method "), gsf, 2);
107 catch (const Test_Interceptors::Invalid&)
109 ACE_DEBUG ((LM_DEBUG, "Invalid user\n"));
112 Test_Interceptors::Secure_Vault::Record record;
113 record.check_num = 1;
114 record.amount = 1000;
115 CORBA::Long id = 1;
117 marker.accumulate_into (throughput, 3);
118 throughput_base = ACE_OS::gethrtime ();
120 for (i = 0; i < niterations ; ++i)
122 // Record current time.
123 ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
125 server->update_records (id,
126 record);
128 // Grab timestamp again.
129 ACE_hrtime_t now = ACE_OS::gethrtime ();
131 // Record statistics.
132 marker.sample (now - throughput_base,
133 now - latency_base,
136 if (TAO_debug_level > 0 && i % 100 == 0)
137 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n", i));
140 marker.dump_stats (ACE_TEXT ("update records method "), gsf, 3);
145 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
147 int priority =
148 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
149 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
150 // Enable FIFO scheduling
152 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
153 priority,
154 ACE_SCOPE_PROCESS)) != 0)
156 if (ACE_OS::last_error () == EPERM)
158 ACE_DEBUG ((LM_DEBUG,
159 "client (%P|%t): user is not superuser, "
160 "test runs in time-shared class\n"));
162 else
163 ACE_ERROR ((LM_ERROR,
164 "client (%P|%t): sched_params failed\n"));
167 int interceptor_type;
168 get_interceptor_type (argc, argv, interceptor_type);
172 PortableInterceptor::ORBInitializer_ptr temp_initializer;
174 ACE_NEW_RETURN (temp_initializer,
175 Client_ORBInitializer (interceptor_type),
176 -1); // No exceptions yet!
177 PortableInterceptor::ORBInitializer_var initializer =
178 temp_initializer;
180 PortableInterceptor::register_orb_initializer (initializer.in ());
182 CORBA::ORB_var orb =
183 CORBA::ORB_init (argc, argv);
185 if (parse_args (argc, argv) != 0)
186 return 1;
188 CORBA::Object_var object =
189 orb->string_to_object (ior);
191 Test_Interceptors::Secure_Vault_var server =
192 Test_Interceptors::Secure_Vault::_narrow (object.in ());
194 if (CORBA::is_nil (server.in ()))
196 ACE_ERROR_RETURN ((LM_ERROR,
197 "Object reference <%s> is nil.\n",
198 ior),
202 ACE_DEBUG ((LM_DEBUG, "\nFunctionality test begins now...\n"));
204 // This test is useful for benchmarking the differences when
205 // the same method is intercepted by different interceptors
206 // wanting to achieve different functionality.
207 run_test (server.in ());
209 server->shutdown ();
211 catch (const CORBA::Exception& ex)
213 ex._tao_print_exception ("Caught exception:");
214 return 1;
217 return 0;