Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / POA / Create_Reference / create_reference.cpp
blob174255b5bf5dabb13b8e76d21938cd2f5e9e21e6
1 #include "tao/PortableServer/PortableServer.h"
2 #include "tao/ORB_Constants.h"
3 #include "tao/ORB.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/Sched_Params.h"
6 #include "ace/High_Res_Timer.h"
7 #include "ace/Sched_Params.h"
8 #include "ace/Stats.h"
9 #include "ace/Sample_History.h"
10 #include "ace/OS_NS_stdio.h"
11 #include "ace/OS_NS_errno.h"
13 int niterations = 10000;
14 int do_dump_history = 0;
15 ACE_High_Res_Timer::global_scale_factor_type gsf;
17 int
18 parse_args (int argc, ACE_TCHAR *argv[])
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hi:"));
21 int c;
23 while ((c = get_opts ()) != -1)
24 switch (c)
26 case 'h':
27 do_dump_history = 1;
28 break;
30 case 'i':
31 niterations = ACE_OS::atoi (get_opts.opt_arg ());
32 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-i <niterations> "
39 "-h "
40 "\n",
41 argv [0]),
42 -1);
44 // Indicates successful parsing of the command line
45 return 0;
48 void
49 set_rt_scheduling (void)
51 int priority =
52 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
53 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
54 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
55 priority);
56 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
58 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
59 priority,
60 ACE_SCOPE_PROCESS)) != 0)
62 if (ACE_OS::last_error () == EPERM)
64 ACE_DEBUG ((LM_DEBUG,
65 "server (%P|%t): user is not superuser, "
66 "test runs in time-shared class\n"));
68 else
69 ACE_ERROR ((LM_ERROR,
70 "server (%P|%t): sched_params failed\n"));
74 void
75 object_creation_test (PortableServer::POA_ptr poa,
76 int create_reference_with_id)
78 ACE_DEBUG ((LM_DEBUG,
79 "\nCreating %d object references with %s\n",
80 niterations,
81 create_reference_with_id ?
82 "create_reference_with_id" :
83 "create_reference"));
85 ACE_Sample_History creation (niterations);
87 for (int i = 0; i != niterations; ++i)
89 char buf[16];
90 ACE_OS::sprintf (buf, "Object_%8.8x", i);
91 PortableServer::ObjectId_var oid
92 (PortableServer::string_to_ObjectId (buf));
94 ACE_hrtime_t start =
95 ACE_OS::gethrtime ();
97 CORBA::Object_var object;
98 if (create_reference_with_id)
100 object =
101 poa->create_reference_with_id (oid.in (),
102 "IDL:Test/Simple:1.0");
104 else
106 object =
107 poa->create_reference ("IDL:Test/Simple:1.0");
110 ACE_hrtime_t now = ACE_OS::gethrtime ();
111 creation.sample (now - start);
114 if (do_dump_history)
116 creation.dump_samples (ACE_TEXT("HISTORY"), gsf);
119 ACE_Basic_Stats creation_stats;
120 creation.collect_basic_stats (creation_stats);
121 creation_stats.dump_results (ACE_TEXT("Creation"), gsf);
125 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
127 set_rt_scheduling ();
131 CORBA::ORB_var orb =
132 CORBA::ORB_init (argc, argv);
134 CORBA::Object_var poa_object =
135 orb->resolve_initial_references ("RootPOA");
137 if (CORBA::is_nil (poa_object.in ()))
138 ACE_ERROR_RETURN ((LM_ERROR,
139 " (%P|%t) Unable to initialize the POA.\n"),
142 PortableServer::POA_var root_poa =
143 PortableServer::POA::_narrow (poa_object.in ());
145 PortableServer::POAManager_var poa_manager =
146 root_poa->the_POAManager ();
148 poa_manager->activate ();
150 if (parse_args (argc, argv) != 0)
151 return 1;
153 CORBA::PolicyList policies(1); policies.length (1);
155 policies[0] =
156 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
158 PortableServer::POA_var child_poa =
159 root_poa->create_POA ("TestPOA",
160 poa_manager.in (),
161 policies);
163 gsf = ACE_High_Res_Timer::global_scale_factor ();
165 object_creation_test (root_poa.in (),
166 0 // POA::create_reference
169 object_creation_test (child_poa.in (),
170 1 // POA::create_reference_with_id
173 root_poa->destroy (1, 1);
175 orb->destroy ();
177 catch (const CORBA::Exception& ex)
179 ex._tao_print_exception ("Exception caught:");
180 return 1;
183 return 0;