Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / performance-tests / POA / Implicit_Activation / client.cpp
blobe8188c08c68ff481cbcd6957b55ad038215e8e31
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/Stats.h"
6 #include "ace/Sample_History.h"
7 #include "ace/OS_NS_errno.h"
9 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
10 int niterations = 100;
11 int do_dump_history = 0;
12 int do_shutdown = 1;
14 int
15 parse_args (int argc, ACE_TCHAR *argv[])
17 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hxk:i:"));
18 int c;
20 while ((c = get_opts ()) != -1)
21 switch (c)
23 case 'h':
24 do_dump_history = 1;
25 break;
27 case 'x':
28 do_shutdown = 0;
29 break;
31 case 'k':
32 ior = get_opts.opt_arg ();
33 break;
35 case 'i':
36 niterations = ACE_OS::atoi (get_opts.opt_arg ());
37 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-k <ior> "
44 "-i <niterations> "
45 "-x (disable shutdown) "
46 "\n",
47 argv [0]),
48 -1);
50 // Indicates successful parsing of the command line
51 return 0;
54 int
55 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
57 int priority =
58 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
59 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
60 // Enable FIFO scheduling
62 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
63 priority,
64 ACE_SCOPE_PROCESS)) != 0)
66 if (ACE_OS::last_error () == EPERM)
68 ACE_DEBUG ((LM_DEBUG,
69 "client (%P|%t): user is not superuser, "
70 "test runs in time-shared class\n"));
72 else
73 ACE_ERROR ((LM_ERROR,
74 "client (%P|%t): sched_params failed\n"));
77 try
79 CORBA::ORB_var orb =
80 CORBA::ORB_init (argc, argv);
82 if (parse_args (argc, argv) != 0)
83 return 1;
85 CORBA::Object_var object =
86 orb->string_to_object (ior);
88 Test::Factory_var factory =
89 Test::Factory::_narrow (object.in ());
91 if (CORBA::is_nil (factory.in ()))
93 ACE_ERROR_RETURN ((LM_ERROR,
94 "Nil Test::Factory reference <%s>\n",
95 ior),
96 1);
99 Test::Simple_Sequence references (niterations);
100 references.length (niterations);
102 ACE_Sample_History activation (niterations);
104 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
105 ACE_High_Res_Timer::global_scale_factor_type gsf =
106 ACE_High_Res_Timer::global_scale_factor ();
107 ACE_DEBUG ((LM_DEBUG, "done\n"));
109 ACE_DEBUG ((LM_DEBUG, "Activating %d objects\n", niterations));
110 for (int i = 0; i != niterations; ++i)
112 ACE_hrtime_t start = ACE_OS::gethrtime ();
114 references[i] =
115 factory->create_simple_object ();
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 if (do_shutdown)
156 factory->shutdown ();
159 catch (const CORBA::Exception& ex)
161 ex._tao_print_exception ("Exception caught:");
162 return 1;
165 return 0;