2 //=============================================================================
4 * @file registration.cpp
6 * This test is used to measure the time it takes to register and
7 * activate an object in the POA.
9 * @author Irfan Pyarali
11 //=============================================================================
15 #include "tao/Server_Strategy_Factory.h"
16 #include "tao/ORB_Core.h"
17 #include "ace/Profile_Timer.h"
18 #include "ace/Get_Opt.h"
19 #include "ace/Truncate.h"
22 // The following macros help take a very precise look into the
23 // different object creations and registration calls through
24 // Quantify. You'll have to define USING_QUANTIFY and define any of
25 // the other specific defines that you are interested in to be 1.
27 // Compilation: Add the directory where pure.h is (usually C:\Program
28 // Files\Rational\Quantify) to the list of include directories. In
29 // addition, add pure_api.c to the source file compilation list.
32 //#define USING_QUANTIFY
33 #define QUANTIFY_DEACTIVATE_OBJECT 0
34 #define QUANTIFY_ACTIVATE_OBJECT_WITH_ID 0
35 #define QUANTIFY_CREATE_REFERENCE_WITH_ID 0
36 #define QUANTIFY_SERVANT_TO_ID 0
37 #define QUANTIFY_UNDERBAR_THIS 0
39 #if defined (USING_QUANTIFY)
40 #if defined (ACE_WIN32)
46 inline int QuantifyClearData ()
48 return quantify_clear_data ();
51 inline int QuantifyStartRecordingData ()
53 return quantify_start_recording_data ();
56 inline int QuantifyStopRecordingData ()
58 return quantify_stop_recording_data ();
61 #endif /* ACE_WIN32 */
62 #endif /* USING_QUANTIFY */
67 * @brief Oversimplified servant class
69 class test_i
: public POA_test
74 static int measure_reverse_map_effectiveness
= 0;
75 static u_long iterations
= 1000;
78 parse_args (int argc
, ACE_TCHAR
**argv
)
80 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("i:r"));
83 while ((c
= get_opts ()) != -1)
87 iterations
= static_cast<u_long
> (ACE_OS::atoi (get_opts
.opt_arg ()));
91 measure_reverse_map_effectiveness
= 1;
96 ACE_ERROR_RETURN ((LM_ERROR
,
98 "[-r [measure reverse map effectiveness]] "
105 // Indicates successful parsing of command line.
110 // Code for printing stats
113 print_stats (ACE_Profile_Timer::ACE_Elapsed_Time
&elapsed_time
)
117 elapsed_time
.real_time
*= ACE_ONE_SECOND_IN_MSECS
;
118 elapsed_time
.user_time
*= ACE_ONE_SECOND_IN_MSECS
;
119 elapsed_time
.system_time
*= ACE_ONE_SECOND_IN_MSECS
;
121 elapsed_time
.real_time
/= iterations
;
122 elapsed_time
.user_time
/= iterations
;
123 elapsed_time
.system_time
/= iterations
;
125 double tmp
= 1000 / elapsed_time
.real_time
;
127 ACE_DEBUG ((LM_DEBUG
,
128 "\titerations\t = %d,\n"
129 "\treal_time\t = %0.06f ms,\n"
130 "\tuser_time\t = %0.06f ms,\n"
131 "\tsystem_time\t = %0.06f ms,\n"
132 "\t%0.00f calls/second\n",
134 elapsed_time
.real_time
< 0.0 ? 0.0 : elapsed_time
.real_time
,
135 elapsed_time
.user_time
< 0.0 ? 0.0 : elapsed_time
.user_time
,
136 elapsed_time
.system_time
< 0.0 ? 0.0 : elapsed_time
.system_time
,
137 tmp
< 0.0 ? 0.0 : tmp
));
140 ACE_ERROR ((LM_ERROR
,
141 "\tNo time stats printed. Zero iterations or error occurred.\n"));
146 // Measures how well the reverse hash map works.
149 reverse_map_effectiveness (test_i
*servants
)
151 // Size of the active object map
152 const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters
¶meters
=
153 TAO_ORB_Core_instance ()->server_factory ()->active_object_map_creation_parameters ();
155 u_long active_object_map_size
= parameters
.active_object_map_size_
;
158 u_long
*hash_counter
= new u_long
[active_object_map_size
];
163 // Initialize the hash counters
164 for (i
= 0; i
< active_object_map_size
; i
++)
169 // Calculate the effectiveness of the hash.
170 for (i
= 0; i
< iterations
; i
++)
172 u_long hash_index
= ACE_Utils::truncate_cast
<u_long
> ((intptr_t)&servants
[i
]) % active_object_map_size
;
173 hash_counter
[hash_index
]++;
176 for (i
= 0; i
< active_object_map_size
; i
++)
180 ACE_DEBUG ((LM_DEBUG
, "\n"));
182 ACE_DEBUG ((LM_DEBUG
, "%d = %d, ", i
, hash_counter
[i
]));
184 ACE_DEBUG ((LM_DEBUG
, "\n\n"));
186 delete[] hash_counter
;
193 const char *test_name
)
194 : quantify_ (quantify
),
195 test_name_ (test_name
)
197 this->timer_
.start ();
201 #if defined (USING_QUANTIFY)
202 // Reset Quantify data recording; whatever happened before this
203 // point is not relevant anymore.
204 QuantifyClearData ();
205 QuantifyStartRecordingData ();
206 #endif /* USING_QUANTIFY */
214 #if defined (USING_QUANTIFY)
215 // Stop recording data here; whatever happens after this is
217 QuantifyStopRecordingData ();
218 #endif /* USING_QUANTIFY */
222 this->timer_
.stop ();
224 ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time
;
225 this->timer_
.elapsed_time (elapsed_time
);
227 // compute average time.
228 ACE_DEBUG ((LM_DEBUG
, "\n%C stats...\n",
230 print_stats (elapsed_time
);
235 ACE_Profile_Timer timer_
;
237 const char *test_name_
;
241 child_poa_testing (PortableServer::POA_ptr root_poa
)
243 // Policies for the child POA.
244 CORBA::PolicyList
policies (1);
247 // Id Assignment Policy
249 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
251 // Create the child POA under the RootPOA.
252 PortableServer::POA_var child_poa
=
253 root_poa
->create_POA ("child POA",
254 PortableServer::POAManager::_nil (),
257 // Create an array of servants
259 new test_i
[iterations
];
261 // Create an array of objects
262 CORBA::Object_var
*objects
=
263 new CORBA::Object_var
[iterations
];
265 // Create an array of object ids
266 PortableServer::ObjectId_var
*object_ids
=
267 new PortableServer::ObjectId_var
[iterations
];
269 // Buffer for the id string.
276 // Record and quantify stats.
277 stats
s (QUANTIFY_CREATE_REFERENCE_WITH_ID
,
278 "create_reference_with_id");
281 for (i
= 0; i
< iterations
; i
++)
283 ACE_OS::sprintf (id_buffer
,
288 PortableServer::string_to_ObjectId (id_buffer
);
291 child_poa
->create_reference_with_id (object_ids
[i
].in (),
297 // Record and quantify stats.
298 stats
s (QUANTIFY_ACTIVATE_OBJECT_WITH_ID
,
299 "activate_object_with_id");
302 for (i
= 0; i
< iterations
; i
++)
304 child_poa
->activate_object_with_id (object_ids
[i
].in (),
310 // Record and quantify stats.
311 stats
s (QUANTIFY_DEACTIVATE_OBJECT
,
312 "deactivate_object");
315 for (i
= 0; i
< iterations
; i
++)
317 child_poa
->deactivate_object (object_ids
[i
].in ());
328 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
332 // Initialize the ORB first.
333 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
335 int result
= parse_args (argc
, argv
);
339 // Obtain the RootPOA.
340 CORBA::Object_var obj
= orb
->resolve_initial_references ("RootPOA");
342 // Get the POA_var object from Object_var.
343 PortableServer::POA_var root_poa
=
344 PortableServer::POA::_narrow (obj
.in ());
346 // Create an array of servants
348 new test_i
[iterations
];
350 // Create an array of objects
351 CORBA::Object_var
*objects
=
352 new CORBA::Object_var
[iterations
];
354 // Create an array of object ids
355 PortableServer::ObjectId_var
*object_ids
=
356 new PortableServer::ObjectId_var
[iterations
];
358 if (measure_reverse_map_effectiveness
)
360 reverse_map_effectiveness (servants
);
367 stats
s (QUANTIFY_UNDERBAR_THIS
,
371 for (i
= 0; i
< iterations
; i
++)
373 PortableServer::ObjectId_var id
=
374 root_poa
->activate_object (&servants
[i
]);
375 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
376 objects
[i
] = test::_narrow (object
.in ());
381 stats
s (QUANTIFY_SERVANT_TO_ID
,
385 for (i
= 0; i
< iterations
; i
++)
387 object_ids
[i
] = root_poa
->servant_to_id (&servants
[i
]);
391 // Create the child POA.
392 child_poa_testing (root_poa
.in ());
395 root_poa
->destroy (true, true);
402 catch (const CORBA::Exception
& ex
)
404 ex
._tao_print_exception ("Exception caught");