Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / Thread_Per_Connection / client.cpp
blob8e896f6c93458b38a06f1e3c338f567f9b2f0117
1 #include "Client_Task.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/Stats.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;
13 int do_shutdown = 1;
14 int sz = 512;
16 const ACE_TCHAR *data_type = ACE_TEXT("octet");
18 int
19 parse_args (int argc, ACE_TCHAR *argv[])
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:s:xk:i:"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 't':
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)
36 return -1;
37 break;
39 case 's':
40 sz = ACE_OS::atoi (get_opts.opt_arg ());
41 break;
43 case 'x':
44 do_shutdown = 0;
45 break;
47 case 'k':
48 ior = get_opts.opt_arg ();
49 break;
51 case 'i':
52 niterations = ACE_OS::atoi (get_opts.opt_arg ());
53 break;
55 case '?':
56 default:
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "usage: %s "
59 "-t <datatype> "
60 "-s <size> "
61 "-k <ior> "
62 "-i <niterations> "
63 "-x (disable shutdown) "
64 "\n",
65 argv [0]),
66 -1);
68 // Indicates successful parsing of the command line
69 return 0;
73 int
74 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
76 int priority =
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,
82 priority,
83 ACE_SCOPE_PROCESS)) != 0)
85 if (ACE_OS::last_error () == EPERM)
87 ACE_DEBUG ((LM_DEBUG,
88 "client (%P|%t): user is not superuser, "
89 "test runs in time-shared class\n"));
91 else
92 ACE_ERROR ((LM_ERROR,
93 "client (%P|%t): sched_params failed\n"));
96 try
98 CORBA::ORB_var orb =
99 CORBA::ORB_init (argc, argv);
101 if (parse_args (argc, argv) != 0)
102 return 1;
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",
114 ior),
118 /// Begin the test
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"),
152 gsf,
153 test_end - test_start,
154 totals.samples_count ());
156 if (do_shutdown)
158 roundtrip->shutdown ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("Exception caught:");
164 return 1;
167 return 0;