Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / Roundtrip / client.cpp
blob58f8003d5dc76703b6fed27d63a3647b9b9e974a
1 #include "RT_Class.h"
2 #include "ORB_Holder.h"
3 #include "Servant_var.h"
4 #include "RIR_Narrow.h"
5 #include "RTServer_Setup.h"
6 #include "Send_Task.h"
7 #include "Client_Group.h"
8 #include "ORB_Task.h"
9 #include "ORB_Task_Activator.h"
10 #include "Low_Priority_Setup.h"
11 #include "EC_Destroyer.h"
12 #include "Client_Options.h"
14 #include "orbsvcs/Event_Service_Constants.h"
16 #include "tao/Messaging/Messaging.h"
17 #include "tao/Strategies/advanced_resource.h"
18 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
19 #include "tao/RTCORBA/Continuous_Priority_Mapping.h"
20 #include "tao/RTPortableServer/RTPortableServer.h"
21 #include "ace/High_Res_Timer.h"
22 #include "ace/Sample_History.h"
23 #include "ace/Basic_Stats.h"
24 #include "ace/Stats.h"
25 #include "ace/Sched_Params.h"
26 #include "ace/Barrier.h"
29 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
31 const CORBA::Long experiment_id = 1;
33 RT_Class rt_class;
35 try
37 ORB_Holder orb (argc, argv, "");
39 Client_Options options (argc, argv);
40 if (argc != 1)
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "Usage: %s "
44 "-i iterations (iterations) "
45 "-h high_priority_period (usecs) "
46 "-l low_priority_period (usecs) "
47 "-w high_priority_workload (usecs) "
48 "-v low_priority_workload (usecs) "
49 "-r (enable RT-CORBA) "
50 "-n nthreads (low priority thread) "
51 "-d (dump history) "
52 "-z (disable low priority) "
53 "\n",
54 argv [0]),
55 1);
58 RTServer_Setup rtserver_setup (options.use_rt_corba,
59 orb,
60 rt_class,
61 1 // options.nthreads
64 PortableServer::POA_var root_poa =
65 RIR_Narrow<PortableServer::POA>::resolve (orb,
66 "RootPOA");
68 PortableServer::POAManager_var poa_manager =
69 root_poa->the_POAManager ();
71 poa_manager->activate ();
73 PortableServer::POA_var the_poa (rtserver_setup.poa ());
75 ACE_Thread_Manager my_thread_manager;
77 ORB_Task orb_task (orb);
78 orb_task.thr_mgr (&my_thread_manager);
79 ORB_Task_Activator orb_task_activator (rt_class.priority_high (),
80 rt_class.thr_sched_class (),
82 &orb_task);
84 ACE_DEBUG ((LM_DEBUG, "Finished ORB and POA configuration\n"));
86 CORBA::Object_var object =
87 orb->string_to_object (options.ior);
89 RtecEventChannelAdmin::EventChannel_var ec =
90 RtecEventChannelAdmin::EventChannel::_narrow (object.in ());
92 EC_Destroyer ec_destroyer (ec.in ());
94 CORBA::PolicyList_var inconsistent_policies;
95 (void) ec->_validate_connection (inconsistent_policies);
97 ACE_DEBUG ((LM_DEBUG, "Found EC, validated connection\n"));
99 int thread_count = 1 + options.nthreads;
101 ACE_Barrier the_barrier (thread_count);
103 ACE_DEBUG ((LM_DEBUG, "Calibrating high res timer ...."));
104 ACE_High_Res_Timer::calibrate ();
106 ACE_High_Res_Timer::global_scale_factor_type gsf =
107 ACE_High_Res_Timer::global_scale_factor ();
108 ACE_DEBUG ((LM_DEBUG, "Done (%d)\n", gsf));
110 CORBA::Long event_range = 1;
111 if (options.funky_supplier_publication)
113 if (options.unique_low_priority_event)
114 event_range = 1 + options.low_priority_consumers;
115 else
116 event_range = 2;
119 Client_Group high_priority_group;
120 high_priority_group.init (experiment_id,
121 ACE_ES_EVENT_UNDEFINED,
122 event_range,
123 options.iterations,
124 options.high_priority_workload,
125 gsf,
126 the_poa.in (),
127 the_poa.in ());
129 Auto_Disconnect<Client_Group> high_priority_disconnect;
131 if (!options.high_priority_is_last)
133 high_priority_group.connect (ec.in ());
134 high_priority_disconnect = &high_priority_group;
137 int per_thread_period = options.low_priority_period;
138 if (options.global_low_priority_rate)
139 per_thread_period = options.low_priority_period * options.nthreads;
141 Low_Priority_Setup<Client_Group> low_priority_setup (
142 options.low_priority_consumers,
143 0, // no limit on the number of iterations
144 options.unique_low_priority_event,
145 experiment_id,
146 ACE_ES_EVENT_UNDEFINED + 2,
147 options.low_priority_workload,
148 gsf,
149 options.nthreads,
150 rt_class.priority_low (),
151 rt_class.thr_sched_class (),
152 per_thread_period,
153 the_poa.in (),
154 the_poa.in (),
155 ec.in (),
156 &the_barrier);
158 if (options.high_priority_is_last)
160 high_priority_group.connect (ec.in ());
161 high_priority_disconnect = &high_priority_group;
163 Send_Task high_priority_task;
164 high_priority_task.init (options.iterations,
165 options.high_priority_period,
167 ACE_ES_EVENT_UNDEFINED,
168 experiment_id,
169 high_priority_group.supplier (),
170 &the_barrier);
171 high_priority_task.thr_mgr (&my_thread_manager);
173 // Artificial scope to wait for the high priority task...
174 Task_Activator<Send_Task> high_priority_act (rt_class.priority_high (),
175 rt_class.thr_sched_class (),
177 &high_priority_task);
180 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - high priority task completed\n"));
182 low_priority_setup.stop_all_threads ();
184 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - low priority task(s) stopped\n"));
186 ACE_Sample_History &history =
187 high_priority_group.consumer ()->sample_history ();
188 if (options.dump_history)
190 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
193 ACE_Basic_Stats high_priority_stats;
194 history.collect_basic_stats (high_priority_stats);
195 high_priority_stats.dump_results (ACE_TEXT("High Priority"), gsf);
197 ACE_Basic_Stats low_priority_stats;
198 low_priority_setup.collect_basic_stats (low_priority_stats);
199 low_priority_stats.dump_results (ACE_TEXT("Low Priority"), gsf);
201 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - starting cleanup\n"));
203 catch (const CORBA::Exception& ex)
205 ex._tao_print_exception ("Exception caught:");
206 return 1;
209 return 0;