Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / Latency / DII / client.cpp
blob2273992983e4eb9ae4f8afa631a13c1d352e309b
1 #include "tao/DynamicInterface/Request.h"
2 #include "tao/Strategies/advanced_resource.h"
3 #include "tao/AnyTypeCode/TypeCode_Constants.h"
4 #include "tao/AnyTypeCode/Any.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/High_Res_Timer.h"
8 #include "ace/Sched_Params.h"
9 #include "ace/Stats.h"
10 #include "ace/Throughput_Stats.h"
11 #include "ace/Sample_History.h"
12 #include "ace/OS_NS_errno.h"
14 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
15 int niterations = 100;
16 int do_dump_history = 0;
17 int do_shutdown = 1;
19 int
20 parse_args (int argc, ACE_TCHAR *argv[])
22 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hxk:i:"));
23 int c;
25 while ((c = get_opts ()) != -1)
26 switch (c)
28 case 'h':
29 do_dump_history = 1;
30 break;
32 case 'x':
33 do_shutdown = 0;
34 break;
36 case 'k':
37 ior = get_opts.opt_arg ();
38 break;
40 case 'i':
41 niterations = ACE_OS::atoi (get_opts.opt_arg ());
42 break;
44 case '?':
45 default:
46 ACE_ERROR_RETURN ((LM_ERROR,
47 "usage: %s "
48 "-k <ior> "
49 "-i <niterations> "
50 "-x (disable shutdown) "
51 "\n",
52 argv [0]),
53 -1);
55 // Indicates successful parsing of the command line
56 return 0;
59 int
60 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
62 int priority =
63 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
64 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
65 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
67 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
68 priority,
69 ACE_SCOPE_PROCESS)) != 0)
71 if (ACE_OS::last_error () == EPERM)
73 ACE_DEBUG ((LM_DEBUG,
74 "client (%P|%t): user is not superuser, "
75 "test runs in time-shared class\n"));
77 else
78 ACE_ERROR ((LM_ERROR,
79 "client (%P|%t): sched_params failed\n"));
82 try
84 CORBA::ORB_var orb =
85 CORBA::ORB_init (argc, argv);
87 if (parse_args (argc, argv) != 0)
88 return 1;
90 CORBA::Object_var object =
91 orb->string_to_object (ior);
93 if (CORBA::is_nil (object.in ()))
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "Nil CORBA::Object reference <%s>\n",
97 ior),
98 1);
101 for (int j = 0; j < 100; ++j)
103 CORBA::Request_var request =
104 object->_request ("test_method");
106 CORBA::ULongLong dummy = 0;
107 request->add_in_arg("send_time") <<= dummy;
109 request->set_return_type (CORBA::_tc_ulonglong);
110 request->invoke ();
113 ACE_Sample_History history (niterations);
115 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
116 for (int i = 0; i < niterations; ++i)
118 ACE_hrtime_t start = ACE_OS::gethrtime ();
120 CORBA::Request_var request =
121 object->_request ("test_method");
123 CORBA::ULongLong start_time = static_cast <CORBA::ULongLong> (start);
124 request->add_in_arg("send_time") <<= start_time;
126 request->set_return_type (CORBA::_tc_ulonglong);
127 request->invoke ();
129 ACE_hrtime_t now = ACE_OS::gethrtime ();
130 history.sample (now - start);
133 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
135 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
137 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
138 ACE_High_Res_Timer::global_scale_factor_type gsf =
139 ACE_High_Res_Timer::global_scale_factor ();
140 ACE_DEBUG ((LM_DEBUG, "done\n"));
142 if (do_dump_history)
144 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
147 ACE_Basic_Stats stats;
148 history.collect_basic_stats (stats);
149 stats.dump_results (ACE_TEXT("Total"), gsf);
151 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
152 test_end - test_start,
153 stats.samples_count ());
155 if (do_shutdown)
157 CORBA::Request_var request =
158 object->_request ("shutdown");
160 request->invoke ();
164 catch (const CORBA::Exception& ex)
166 ex._tao_print_exception ("Exception caught:");
167 return 1;
170 return 0;