Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / performance-tests / Latency / DII / client.cpp
blobf7fbd361812415511cea44965ff444c38fdcbaef
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
66 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
67 priority,
68 ACE_SCOPE_PROCESS)) != 0)
70 if (ACE_OS::last_error () == EPERM)
72 ACE_DEBUG ((LM_DEBUG,
73 "client (%P|%t): user is not superuser, "
74 "test runs in time-shared class\n"));
76 else
77 ACE_ERROR ((LM_ERROR,
78 "client (%P|%t): sched_params failed\n"));
81 try
83 CORBA::ORB_var orb =
84 CORBA::ORB_init (argc, argv);
86 if (parse_args (argc, argv) != 0)
87 return 1;
89 CORBA::Object_var object =
90 orb->string_to_object (ior);
92 if (CORBA::is_nil (object.in ()))
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Nil CORBA::Object reference <%s>\n",
96 ior),
97 1);
100 for (int j = 0; j < 100; ++j)
102 CORBA::Request_var request =
103 object->_request ("test_method");
105 CORBA::ULongLong dummy = 0;
106 request->add_in_arg("send_time") <<= dummy;
108 request->set_return_type (CORBA::_tc_ulonglong);
109 request->invoke ();
112 ACE_Sample_History history (niterations);
114 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
115 for (int i = 0; i < niterations; ++i)
117 ACE_hrtime_t start = ACE_OS::gethrtime ();
119 CORBA::Request_var request =
120 object->_request ("test_method");
122 CORBA::ULongLong start_time = static_cast <CORBA::ULongLong> (start);
123 request->add_in_arg("send_time") <<= start_time;
125 request->set_return_type (CORBA::_tc_ulonglong);
126 request->invoke ();
128 ACE_hrtime_t now = ACE_OS::gethrtime ();
129 history.sample (now - start);
132 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
134 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
136 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
137 ACE_High_Res_Timer::global_scale_factor_type gsf =
138 ACE_High_Res_Timer::global_scale_factor ();
139 ACE_DEBUG ((LM_DEBUG, "done\n"));
141 if (do_dump_history)
143 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
146 ACE_Basic_Stats stats;
147 history.collect_basic_stats (stats);
148 stats.dump_results (ACE_TEXT("Total"), gsf);
150 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
151 test_end - test_start,
152 stats.samples_count ());
154 if (do_shutdown)
156 CORBA::Request_var request =
157 object->_request ("shutdown");
159 request->invoke ();
162 catch (const CORBA::Exception& ex)
164 ex._tao_print_exception ("Exception caught:");
165 return 1;
168 return 0;