1 #include "Client_Task.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/Sched_Params.h"
6 #include "ace/Throughput_Stats.h"
7 #include "ace/OS_NS_errno.h"
9 #include "tao/Strategies/advanced_resource.h"
11 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
12 int niterations
= 1000;
16 const ACE_TCHAR
*data_type
= ACE_TEXT("octet");
19 parse_args (int argc
, ACE_TCHAR
*argv
[])
21 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:s:xk:i:"));
24 while ((c
= get_opts ()) != -1)
28 data_type
= get_opts
.opt_arg ();
30 if (ACE_OS::strcmp (data_type
, ACE_TEXT("octet")) != 0 &&
31 ACE_OS::strcmp (data_type
, ACE_TEXT("char")) != 0 &&
32 ACE_OS::strcmp (data_type
, ACE_TEXT("long")) != 0 &&
33 ACE_OS::strcmp (data_type
, ACE_TEXT("short")) != 0 &&
34 ACE_OS::strcmp (data_type
, ACE_TEXT("double")) != 0 &&
35 ACE_OS::strcmp (data_type
, ACE_TEXT("longlong")) != 0)
40 sz
= ACE_OS::atoi (get_opts
.opt_arg ());
48 ior
= get_opts
.opt_arg ();
52 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
57 ACE_ERROR_RETURN ((LM_ERROR
,
63 "-x (disable shutdown) "
68 // Indicates successful parsing of the command line
74 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
77 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
78 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
79 // Enable FIFO scheduling
81 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
83 ACE_SCOPE_PROCESS
)) != 0)
85 if (ACE_OS::last_error () == EPERM
)
88 "client (%P|%t): user is not superuser, "
89 "test runs in time-shared class\n"));
93 "client (%P|%t): sched_params failed\n"));
99 CORBA::ORB_init (argc
, argv
);
101 if (parse_args (argc
, argv
) != 0)
104 CORBA::Object_var object
=
105 orb
->string_to_object (ior
);
107 Test::Roundtrip_var roundtrip
=
108 Test::Roundtrip::_narrow (object
.in ());
110 if (CORBA::is_nil (roundtrip
.in ()))
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "Nil Test::Roundtrip reference <%s>\n",
120 ACE_DEBUG ((LM_DEBUG
, "Starting threads\n"));
122 Client_Task
task0(data_type
, sz
, roundtrip
.in (), niterations
);
123 Client_Task
task1(data_type
, sz
, roundtrip
.in (), niterations
);
124 Client_Task
task2(data_type
, sz
, roundtrip
.in (), niterations
);
125 Client_Task
task3(data_type
, sz
, roundtrip
.in (), niterations
);
127 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
128 task0
.activate(THR_NEW_LWP
| THR_JOINABLE
);
129 task1
.activate(THR_NEW_LWP
| THR_JOINABLE
);
130 task2
.activate(THR_NEW_LWP
| THR_JOINABLE
);
131 task3
.activate(THR_NEW_LWP
| THR_JOINABLE
);
133 task0
.thr_mgr()->wait ();
134 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
136 ACE_DEBUG ((LM_DEBUG
, "Threads finished\n"));
138 ACE_DEBUG ((LM_DEBUG
, "High resolution timer calibration...."));
139 ACE_High_Res_Timer::global_scale_factor_type gsf
=
140 ACE_High_Res_Timer::global_scale_factor ();
141 ACE_DEBUG ((LM_DEBUG
, "done\n"));
143 ACE_Basic_Stats totals
;
144 task0
.accumulate_and_dump (totals
, ACE_TEXT("Task[0]"), gsf
);
145 task1
.accumulate_and_dump (totals
, ACE_TEXT("Task[1]"), gsf
);
146 task2
.accumulate_and_dump (totals
, ACE_TEXT("Task[2]"), gsf
);
147 task3
.accumulate_and_dump (totals
, ACE_TEXT("Task[3]"), gsf
);
149 totals
.dump_results (ACE_TEXT("Total"), gsf
);
151 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
153 test_end
- test_start
,
154 totals
.samples_count ());
158 roundtrip
->shutdown ();
161 catch (const CORBA::Exception
& ex
)
163 ex
._tao_print_exception ("Exception caught:");