Cleanup Solaris support
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / LoadBalancing / LBPerf / CPU / client.cpp
blob508ca8cf8f813164cfbb070963c8b3c6e92ac663
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 #include "tao/Strategies/advanced_resource.h"
11 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
12 int niterations = 100;
13 int do_dump_history = 0;
14 int do_shutdown = 1;
15 float rate = 0;
16 int number;
17 int
18 parse_args (int argc, ACE_TCHAR *argv[])
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hxk:i:n:r:"));
21 int c;
23 while ((c = get_opts ()) != -1)
24 switch (c)
26 case 'h':
27 do_dump_history = 1;
28 break;
30 case 'x':
31 do_shutdown = 0;
32 break;
34 case 'k':
35 ior = get_opts.opt_arg ();
36 break;
38 case 'i':
39 niterations = ACE_OS::atoi (get_opts.opt_arg ());
40 break;
42 case 'r':
43 rate = ACE_OS::atoi (get_opts.opt_arg ());
44 break;
46 case 'n':
47 number = ACE_OS::atoi (get_opts.opt_arg ());
48 break;
50 case '?':
51 default:
52 ACE_ERROR_RETURN ((LM_ERROR,
53 "usage: %s "
54 "-k <ior> "
55 "-i <niterations> "
56 "-x (disable shutdown) "
57 "-h (dump history) "
58 "-r (rate [Hz])"
59 "\n",
60 argv [0]),
61 -1);
63 // Indicates successful parsing of the command line
64 return 0;
67 int
68 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
70 int priority =
71 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
72 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
73 // Enable FIFO scheduling
74 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
75 priority,
76 ACE_SCOPE_PROCESS)) != 0)
78 if (ACE_OS::last_error () == EPERM)
80 ACE_DEBUG ((LM_DEBUG,
81 "client (%P|%t): user is not superuser, "
82 "test runs in time-shared class\n"));
84 else
85 ACE_ERROR ((LM_ERROR,
86 "client (%P|%t): sched_params failed\n"));
89 try
91 CORBA::ORB_var orb =
92 CORBA::ORB_init (argc, argv);
94 if (parse_args (argc, argv) != 0)
95 return 1;
97 CORBA::Object_var object =
98 orb->string_to_object (ior);
100 Test::Roundtrip_var roundtrip =
101 Test::Roundtrip::_narrow (object.in ());
103 if (CORBA::is_nil (roundtrip.in ()))
105 ACE_ERROR_RETURN ((LM_ERROR,
106 "Nil Test::Roundtrip reference <%s>\n",
107 ior),
111 for (int j = 0; j < 100; ++j)
113 ACE_hrtime_t start = 0;
114 (void) roundtrip->test_method (start, number);
117 ACE_Sample_History history (niterations);
119 const float usecs = 1.0 / rate * 1e6;
121 ACE_Time_Value tv (0, static_cast<const long> (usecs));
123 // const timespec ts = tv;
125 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
126 for (int i = 0; i < niterations; ++i)
128 ACE_hrtime_t start = ACE_OS::gethrtime ();
131 if (rate)
133 //(void) ACE_OS::nanosleep (&ts, 0);
134 //prime_number = ACE::is_prime (699999, 2, 349999);
138 (void) roundtrip->test_method (start, number);
140 ACE_hrtime_t now = ACE_OS::gethrtime ();
141 history.sample (now - start);
144 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
146 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
148 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
149 ACE_High_Res_Timer::global_scale_factor_type gsf =
150 ACE_High_Res_Timer::global_scale_factor ();
151 ACE_DEBUG ((LM_DEBUG, "done\n"));
153 if (do_dump_history)
155 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
158 ACE_Basic_Stats stats;
159 history.collect_basic_stats (stats);
160 stats.dump_results (ACE_TEXT("Total"), gsf);
162 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
163 test_end - test_start,
164 stats.samples_count ());
166 if (do_shutdown)
168 roundtrip->shutdown ();
171 catch (const CORBA::Exception& ex)
173 ex._tao_print_exception ("Exception caught:");
174 return 1;
177 return 0;