1 #include "ace/Get_Opt.h"
3 #include "tao/RTCORBA/RTCORBA.h"
4 #include "tao/ORB_Core.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/OS_NS_time.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT ("file://ior_1");
10 int iterations
= 1000;
11 int shutdown_server
= 0;
12 bool decreased
= false;
15 sched_policy_name (int sched_policy
)
36 parse_args (int argc
, ACE_TCHAR
*argv
[])
38 ACE_Get_Opt
get_opts (argc
, argv
, "xk:i:");
41 while ((c
= get_opts ()) != -1)
49 ior
= get_opts
.opt_arg ();
53 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
58 ACE_ERROR_RETURN ((LM_ERROR
,
62 "-x [shutdown server] "
68 // Indicates successful parsing of the command line
72 class Task
: public ACE_Task_Base
76 Task (ACE_Thread_Manager
&thread_manager
,
85 Task::Task (ACE_Thread_Manager
&thread_manager
,
87 : ACE_Task_Base (&thread_manager
),
88 orb_ (CORBA::ORB::_duplicate (orb
))
97 CORBA::Object_var object
=
98 this->orb_
->string_to_object (ior
);
101 test::_narrow (object
.in ());
108 struct timespec millis
;
110 millis
.tv_nsec
= 50 * 1000000L; // 1e6 nanos per milli
112 ACE_hrtime_t start
= ACE_OS::gethrtime();
114 for (int i
= 0; i
!= iterations
; ++i
)
116 // ~20 req/sec means to sleep 50 millis between each
117 ACE_OS::nanosleep(&millis
); // ignore signals
126 // Assert disappears on with optimizations on.
131 // Number of threads increased, so store this.
132 ACE_DEBUG ((LM_DEBUG
, "Thread count increased to %d\n", mtc
));
137 // Number of threads decreased!
138 ACE_DEBUG ((LM_DEBUG
, "Thread count decreased to %d\n", mtc
));
143 ACE_hrtime_t duration
= ACE_OS::gethrtime() - start
;
144 double tp
= ((double) iterations
) / (duration
/ 1000000);
146 ACE_DEBUG ((LM_DEBUG
, "Throughput: %d\n", tp
));
156 ACE_ASSERT (re
== 0);
157 // Assert disappears on with optimizations on.
162 ACE_ERROR ((LM_ERROR
, "Dynamic thread count should be 0, not %d\n", end
));
170 catch (const CORBA::Exception
& ex
)
172 ex
._tao_print_exception ("Exception caught:");
180 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
185 CORBA::ORB_init (argc
, argv
);
188 parse_args (argc
, argv
);
192 // Thread Manager for managing task.
193 ACE_Thread_Manager thread_manager
;
196 Task
task (thread_manager
,
199 // Task activation flags.
203 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
206 result
= task
.activate (flags
);
212 ACE_ERROR_RETURN ((LM_ERROR
,
213 "Cannot create thread with scheduling policy %s\n"
214 "because the user does not have the appropriate privileges, terminating program....\n"
215 "Check svc.conf options and/or run as root\n",
216 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
224 // Wait for task to exit.
226 thread_manager
.wait ();
227 ACE_ASSERT (result
!= -1);
229 if (decreased
== false)
231 ACE_ERROR_RETURN ((LM_ERROR
, "ERROR: Number of threads didn't decrease\n"), -1);
234 catch (const CORBA::Exception
& ex
)
236 ex
._tao_print_exception ("Exception caught");