Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / Colocated_Roundtrip / driver.cpp
blob13aa7bbbe5ef906401ba78db4bc7095d13f6d854
1 #include "RT_Class.h"
2 #include "ORB_Holder.h"
3 #include "Servant_var.h"
4 #include "RIR_Narrow.h"
5 #include "RTEC_Initializer.h"
6 #include "RTServer_Setup.h"
7 #include "Low_Priority_Setup.h"
8 #include "EC_Destroyer.h"
9 #include "Auto_Disconnect.h"
10 #include "ORB_Task.h"
11 #include "ORB_Task_Activator.h"
12 #include "Client_Group.h"
13 #include "Client_Options.h"
15 #include "orbsvcs/Event_Service_Constants.h"
17 #include "orbsvcs/Event/EC_Event_Channel.h"
18 #include "orbsvcs/Event/EC_Default_Factory.h"
20 #include "tao/PortableServer/PortableServer.h"
21 #include "tao/RTPortableServer/RTPortableServer.h"
22 #include "tao/Strategies/advanced_resource.h"
23 #include "tao/Messaging/Messaging.h"
24 #include "ace/Get_Opt.h"
25 #include "ace/High_Res_Timer.h"
26 #include "ace/Sample_History.h"
27 #include "ace/Basic_Stats.h"
28 #include "ace/Barrier.h"
31 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
33 const CORBA::Long experiment_id = 1;
35 TAO_EC_Default_Factory::init_svcs ();
37 /// Move the test to the real-time class if it is possible.
38 RT_Class rt_class;
40 try
42 ORB_Holder orb (argc, argv, "");
44 Client_Options options (argc, argv);
45 if (argc != 1)
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "Usage: %s "
49 "-i iterations (iterations) "
50 "-h high_priority_period (usecs) "
51 "-l low_priority_period (usecs) "
52 "-w high_priority_workload (usecs) "
53 "-v low_priority_workload (usecs) "
54 "-r (enable RT-CORBA) "
55 "-n nthreads (low priority thread) "
56 "-d (dump history) "
57 "-z (disable low priority) "
58 "\n",
59 argv [0]),
60 1);
63 RTServer_Setup rtserver_setup (options.use_rt_corba,
64 orb,
65 rt_class,
66 1 // options.nthreads
69 PortableServer::POA_var root_poa =
70 RIR_Narrow<PortableServer::POA>::resolve (orb,
71 "RootPOA");
73 PortableServer::POAManager_var poa_manager =
74 root_poa->the_POAManager ();
76 poa_manager->activate ();
78 PortableServer::POA_var ec_poa (rtserver_setup.poa ());
80 ACE_Thread_Manager my_thread_manager;
82 ORB_Task orb_task (orb);
83 orb_task.thr_mgr (&my_thread_manager);
84 ORB_Task_Activator orb_task_activator (rt_class.priority_high (),
85 rt_class.thr_sched_class (),
87 &orb_task);
89 ACE_DEBUG ((LM_DEBUG, "Finished ORB and POA configuration\n"));
91 Servant_var<TAO_EC_Event_Channel> ec_impl (
92 RTEC_Initializer::create (ec_poa.in (),
93 ec_poa.in (),
94 rtserver_setup.rtcorba_setup ())
97 ec_impl->activate ();
99 PortableServer::ObjectId_var ec_id =
100 ec_poa->activate_object (ec_impl.in ());
101 CORBA::Object_var ec_object =
102 ec_poa->id_to_reference (ec_id.in ());
104 RtecEventChannelAdmin::EventChannel_var ec =
105 RtecEventChannelAdmin::EventChannel::_narrow (ec_object.in ());
107 EC_Destroyer ec_destroyer (ec.in ());
109 ACE_DEBUG ((LM_DEBUG, "Finished EC configuration and activation\n"));
111 int thread_count = 1 + options.nthreads;
113 ACE_Barrier the_barrier (thread_count);
115 ACE_DEBUG ((LM_DEBUG, "Calibrating high res timer ...."));
116 ACE_High_Res_Timer::calibrate ();
118 ACE_High_Res_Timer::global_scale_factor_type gsf =
119 ACE_High_Res_Timer::global_scale_factor ();
120 ACE_DEBUG ((LM_DEBUG, "Done (%d)\n", gsf));
122 CORBA::Long event_range = 1;
123 if (options.funky_supplier_publication)
125 if (options.unique_low_priority_event)
126 event_range = 1 + options.low_priority_consumers;
127 else
128 event_range = 2;
131 Client_Group high_priority_group;
132 high_priority_group.init (experiment_id,
133 ACE_ES_EVENT_UNDEFINED,
134 event_range,
135 options.iterations,
136 options.high_priority_workload,
137 gsf,
138 ec_poa.in (),
139 ec_poa.in ());
141 Auto_Disconnect<Client_Group> high_priority_disconnect;
143 if (!options.high_priority_is_last)
145 high_priority_group.connect (ec.in ());
146 high_priority_disconnect = &high_priority_group;
149 int per_thread_period = options.low_priority_period;
150 if (options.global_low_priority_rate)
151 per_thread_period = options.low_priority_period * options.nthreads;
153 Low_Priority_Setup<Client_Group> low_priority_setup (
154 options.low_priority_consumers,
155 0, // no limit on the number of iterations
156 options.unique_low_priority_event,
157 experiment_id,
158 ACE_ES_EVENT_UNDEFINED + 2,
159 options.low_priority_workload,
160 gsf,
161 options.nthreads,
162 rt_class.priority_low (),
163 rt_class.thr_sched_class (),
164 per_thread_period,
165 ec_poa.in (),
166 ec_poa.in (),
167 ec.in (),
168 &the_barrier);
170 if (options.high_priority_is_last)
172 high_priority_group.connect (ec.in ());
173 high_priority_disconnect = &high_priority_group;
175 Send_Task high_priority_task;
176 high_priority_task.init (options.iterations,
177 options.high_priority_period,
179 ACE_ES_EVENT_UNDEFINED,
180 experiment_id,
181 high_priority_group.supplier (),
182 &the_barrier);
183 high_priority_task.thr_mgr (&my_thread_manager);
185 // Artificial scope to wait for the high priority task...
186 Task_Activator<Send_Task> high_priority_act (rt_class.priority_high (),
187 rt_class.thr_sched_class (),
189 &high_priority_task);
192 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - high priority task completed\n"));
194 low_priority_setup.stop_all_threads ();
196 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - low priority task(s) stopped\n"));
198 ACE_Sample_History &history =
199 high_priority_group.consumer ()->sample_history ();
200 if (options.dump_history)
202 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
205 ACE_Basic_Stats high_priority_stats;
206 history.collect_basic_stats (high_priority_stats);
207 high_priority_stats.dump_results (ACE_TEXT("High Priority"), gsf);
209 ACE_Basic_Stats low_priority_stats;
210 low_priority_setup.collect_basic_stats (low_priority_stats);
211 low_priority_stats.dump_results (ACE_TEXT("Low Priority"), gsf);
213 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - starting cleanup\n"));
215 catch (const CORBA::Exception& ex)
217 ex._tao_print_exception ("Exception caught:");
218 return 1;
221 return 0;