Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / TAO / performance-tests / POA / Implicit_Activation / collocated.cpp
blob8587cedfeedff13fb977c4542a7358c1e09c79ca
1 #include "Simple.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Sched_Params.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/Sched_Params.h"
6 #include "ace/Stats.h"
7 #include "ace/Sample_History.h"
8 #include "ace/OS_NS_errno.h"
10 int niterations = 10000;
11 int do_dump_history = 0;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hi:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'h':
23 do_dump_history = 1;
24 break;
26 case 'i':
27 niterations = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
30 case '?':
31 default:
32 ACE_ERROR_RETURN ((LM_ERROR,
33 "usage: %s "
34 "-i <niterations> "
35 "-h "
36 "\n",
37 argv [0]),
38 -1);
40 // Indicates successful parsing of the command line
41 return 0;
44 int
45 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
47 int priority =
48 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
49 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
50 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
51 priority);
52 // Enable FIFO scheduling
54 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
55 priority,
56 ACE_SCOPE_PROCESS)) != 0)
58 if (ACE_OS::last_error () == EPERM)
60 ACE_DEBUG ((LM_DEBUG,
61 "server (%P|%t): user is not superuser, "
62 "test runs in time-shared class\n"));
64 else
65 ACE_ERROR ((LM_ERROR,
66 "server (%P|%t): sched_params failed\n"));
69 try
71 CORBA::ORB_var orb =
72 CORBA::ORB_init (argc, argv);
74 CORBA::Object_var poa_object =
75 orb->resolve_initial_references("RootPOA");
77 if (CORBA::is_nil (poa_object.in ()))
78 ACE_ERROR_RETURN ((LM_ERROR,
79 " (%P|%t) Unable to initialize the POA.\n"),
80 1);
82 PortableServer::POA_var root_poa =
83 PortableServer::POA::_narrow (poa_object.in ());
85 PortableServer::POAManager_var poa_manager =
86 root_poa->the_POAManager ();
88 poa_manager->activate ();
90 if (parse_args (argc, argv) != 0)
91 return 1;
93 Test::Simple_Sequence references (niterations);
94 references.length (niterations);
96 ACE_Sample_History activation (niterations);
98 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
99 ACE_High_Res_Timer::global_scale_factor_type gsf =
100 ACE_High_Res_Timer::global_scale_factor ();
101 ACE_DEBUG ((LM_DEBUG, "done\n"));
103 ACE_DEBUG ((LM_DEBUG, "Activating %d objects\n", niterations));
104 for (int i = 0; i != niterations; ++i)
106 ACE_hrtime_t start = ACE_OS::gethrtime ();
108 Simple *simple_impl;
109 ACE_NEW_RETURN (simple_impl,
110 Simple,
112 PortableServer::ServantBase_var owner_transfer(simple_impl);
114 references[i] =
115 simple_impl->_this ();
117 ACE_hrtime_t now = ACE_OS::gethrtime ();
118 activation.sample (now - start);
120 ACE_DEBUG ((LM_DEBUG, "Activations completed\n"));
122 if (do_dump_history)
124 activation.dump_samples (ACE_TEXT("ACTIVATION_HISTORY"), gsf);
127 ACE_Basic_Stats activation_stats;
128 activation.collect_basic_stats (activation_stats);
129 activation_stats.dump_results (ACE_TEXT("Activation"), gsf);
131 ACE_Sample_History destruction (niterations);
133 ACE_DEBUG ((LM_DEBUG, "Destroying %d objects\n", niterations));
134 for (int j = 0; j != niterations; ++j)
136 ACE_hrtime_t start = ACE_OS::gethrtime ();
138 references[j]->destroy ();
140 ACE_hrtime_t now = ACE_OS::gethrtime ();
141 destruction.sample (now - start);
143 ACE_DEBUG ((LM_DEBUG, "Destructions completed\n"));
145 if (do_dump_history)
147 destruction.dump_samples (ACE_TEXT("DESTRUCTION_HISTORY"), gsf);
150 ACE_Basic_Stats destruction_stats;
151 destruction.collect_basic_stats (destruction_stats);
152 destruction_stats.dump_results (ACE_TEXT("Destruction"), gsf);
154 root_poa->destroy (true, true);
156 orb->destroy ();
158 catch (const CORBA::Exception& ex)
160 ex._tao_print_exception ("Exception caught:");
161 return 1;
164 return 0;