Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / LoadBalancing / LBPerf / RPS / client.cpp
blobdebd4a3316ac35b2aa9f23a6f46eb715ec0ea82c
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/Throughput_Stats.h"
7 #include "ace/Sample_History.h"
8 #include "ace/OS_NS_errno.h"
10 #include "tao/Strategies/advanced_resource.h"
12 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
13 int niterations = 100;
14 int do_dump_history = 0;
15 int do_shutdown = 1;
16 float rate = 0;
17 int number;
18 int
19 parse_args (int argc, ACE_TCHAR *argv[])
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hxk:i:n:r:"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 'h':
28 do_dump_history = 1;
29 break;
31 case 'x':
32 do_shutdown = 0;
33 break;
35 case 'k':
36 ior = get_opts.opt_arg ();
37 break;
39 case 'i':
40 niterations = ACE_OS::atoi (get_opts.opt_arg ());
41 break;
43 case 'r':
44 rate =
45 static_cast<float> (ACE_OS::atoi (get_opts.opt_arg ()));
46 break;
48 case 'n':
49 number = ACE_OS::atoi (get_opts.opt_arg ());
50 break;
52 case '?':
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "usage: %s "
56 "-k <ior> "
57 "-i <niterations> "
58 "-x (disable shutdown) "
59 "-h (dump history) "
60 "-r (rate [Hz])"
61 "\n",
62 argv [0]),
63 -1);
65 // Indicates successful parsing of the command line
66 return 0;
69 int
70 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
72 int priority =
73 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
74 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
75 // Enable FIFO scheduling
76 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
77 priority,
78 ACE_SCOPE_PROCESS)) != 0)
80 if (ACE_OS::last_error () == EPERM)
82 ACE_DEBUG ((LM_DEBUG,
83 "client (%P|%t): user is not superuser, "
84 "test runs in time-shared class\n"));
86 else
87 ACE_ERROR ((LM_ERROR,
88 "client (%P|%t): sched_params failed\n"));
91 try
93 CORBA::ORB_var orb =
94 CORBA::ORB_init (argc, argv);
96 if (parse_args (argc, argv) != 0)
97 return 1;
99 CORBA::Object_var object =
100 orb->string_to_object (ior);
102 Test::Roundtrip_var roundtrip =
103 Test::Roundtrip::_narrow (object.in ());
105 if (CORBA::is_nil (roundtrip.in ()))
107 ACE_ERROR_RETURN ((LM_ERROR,
108 "Nil Test::Roundtrip reference <%s>\n",
109 ior),
112 for (int j = 0; j < 100; ++j)
114 ACE_hrtime_t start = 0;
115 (void) roundtrip->test_method (start, number);
118 ACE_Sample_History history (niterations);
120 // const float usecs = 1.0 / rate * 1e6;
122 // ACE_Time_Value tv (0, static_cast<const long> (usecs));
124 // const timespec ts = tv;
126 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
127 for (int i = 0; i < niterations; ++i)
129 ACE_hrtime_t start = ACE_OS::gethrtime ();
132 if (rate)
134 //(void) ACE_OS::nanosleep (&ts, 0);
135 //prime_number = ACE::is_prime (699999, 2, 349999);
139 (void) roundtrip->test_method (start, number);
141 ACE_hrtime_t now = ACE_OS::gethrtime ();
142 history.sample (now - start);
145 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
147 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
149 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
150 ACE_High_Res_Timer::global_scale_factor_type gsf =
151 ACE_High_Res_Timer::global_scale_factor ();
152 ACE_DEBUG ((LM_DEBUG, "done\n"));
154 if (do_dump_history)
156 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
159 ACE_Basic_Stats stats;
160 history.collect_basic_stats (stats);
161 stats.dump_results (ACE_TEXT("Total"), gsf);
163 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
164 test_end - test_start,
165 stats.samples_count ());
167 if (do_shutdown)
169 roundtrip->shutdown ();
172 catch (const CORBA::Exception& ex)
174 ex._tao_print_exception ("Exception caught:");
175 return 1;
178 return 0;