Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / Roundtrip / client.cpp
blobd29ccb9964f7f08f8810449c75bb7a486f2be83d
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"
30 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
32 const CORBA::Long experiment_id = 1;
34 RT_Class rt_class;
36 try
38 ORB_Holder orb (argc, argv, "");
40 Client_Options options (argc, argv);
41 if (argc != 1)
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "Usage: %s "
45 "-i iterations (iterations) "
46 "-h high_priority_period (usecs) "
47 "-l low_priority_period (usecs) "
48 "-w high_priority_workload (usecs) "
49 "-v low_priority_workload (usecs) "
50 "-r (enable RT-CORBA) "
51 "-n nthreads (low priority thread) "
52 "-d (dump history) "
53 "-z (disable low priority) "
54 "\n",
55 argv [0]),
56 1);
59 RTServer_Setup rtserver_setup (options.use_rt_corba,
60 orb,
61 rt_class,
62 1 // options.nthreads
65 PortableServer::POA_var root_poa =
66 RIR_Narrow<PortableServer::POA>::resolve (orb,
67 "RootPOA");
69 PortableServer::POAManager_var poa_manager =
70 root_poa->the_POAManager ();
72 poa_manager->activate ();
74 PortableServer::POA_var the_poa (rtserver_setup.poa ());
76 ACE_Thread_Manager my_thread_manager;
78 ORB_Task orb_task (orb);
79 orb_task.thr_mgr (&my_thread_manager);
80 ORB_Task_Activator orb_task_activator (rt_class.priority_high (),
81 rt_class.thr_sched_class (),
83 &orb_task);
85 ACE_DEBUG ((LM_DEBUG, "Finished ORB and POA configuration\n"));
87 CORBA::Object_var object =
88 orb->string_to_object (options.ior);
90 RtecEventChannelAdmin::EventChannel_var ec =
91 RtecEventChannelAdmin::EventChannel::_narrow (object.in ());
93 EC_Destroyer ec_destroyer (ec.in ());
95 CORBA::PolicyList_var inconsistent_policies;
96 (void) ec->_validate_connection (inconsistent_policies);
98 ACE_DEBUG ((LM_DEBUG, "Found EC, validated connection\n"));
100 int thread_count = 1 + options.nthreads;
102 ACE_Barrier the_barrier (thread_count);
104 ACE_DEBUG ((LM_DEBUG, "Calibrating high res timer ...."));
105 ACE_High_Res_Timer::calibrate ();
107 ACE_High_Res_Timer::global_scale_factor_type gsf =
108 ACE_High_Res_Timer::global_scale_factor ();
109 ACE_DEBUG ((LM_DEBUG, "Done (%d)\n", gsf));
111 CORBA::Long event_range = 1;
112 if (options.funky_supplier_publication)
114 if (options.unique_low_priority_event)
115 event_range = 1 + options.low_priority_consumers;
116 else
117 event_range = 2;
120 Client_Group high_priority_group;
121 high_priority_group.init (experiment_id,
122 ACE_ES_EVENT_UNDEFINED,
123 event_range,
124 options.iterations,
125 options.high_priority_workload,
126 gsf,
127 the_poa.in (),
128 the_poa.in ());
130 Auto_Disconnect<Client_Group> high_priority_disconnect;
132 if (!options.high_priority_is_last)
134 high_priority_group.connect (ec.in ());
135 high_priority_disconnect = &high_priority_group;
138 int per_thread_period = options.low_priority_period;
139 if (options.global_low_priority_rate)
140 per_thread_period = options.low_priority_period * options.nthreads;
142 Low_Priority_Setup<Client_Group> low_priority_setup (
143 options.low_priority_consumers,
144 0, // no limit on the number of iterations
145 options.unique_low_priority_event,
146 experiment_id,
147 ACE_ES_EVENT_UNDEFINED + 2,
148 options.low_priority_workload,
149 gsf,
150 options.nthreads,
151 rt_class.priority_low (),
152 rt_class.thr_sched_class (),
153 per_thread_period,
154 the_poa.in (),
155 the_poa.in (),
156 ec.in (),
157 &the_barrier);
159 if (options.high_priority_is_last)
161 high_priority_group.connect (ec.in ());
162 high_priority_disconnect = &high_priority_group;
164 Send_Task high_priority_task;
165 high_priority_task.init (options.iterations,
166 options.high_priority_period,
168 ACE_ES_EVENT_UNDEFINED,
169 experiment_id,
170 high_priority_group.supplier (),
171 &the_barrier);
172 high_priority_task.thr_mgr (&my_thread_manager);
174 // Artificial scope to wait for the high priority task...
175 Task_Activator<Send_Task> high_priority_act (rt_class.priority_high (),
176 rt_class.thr_sched_class (),
178 &high_priority_task);
181 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - high priority task completed\n"));
183 low_priority_setup.stop_all_threads ();
185 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - low priority task(s) stopped\n"));
187 ACE_Sample_History &history =
188 high_priority_group.consumer ()->sample_history ();
189 if (options.dump_history)
191 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
194 ACE_Basic_Stats high_priority_stats;
195 history.collect_basic_stats (high_priority_stats);
196 high_priority_stats.dump_results (ACE_TEXT("High Priority"), gsf);
198 ACE_Basic_Stats low_priority_stats;
199 low_priority_setup.collect_basic_stats (low_priority_stats);
200 low_priority_stats.dump_results (ACE_TEXT("Low Priority"), gsf);
202 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - starting cleanup\n"));
204 catch (const CORBA::Exception& ex)
206 ex._tao_print_exception ("Exception caught:");
207 return 1;
210 return 0;