Merge pull request #2218 from jwillemsen/jwi-pthreadsigmask
[ACE_TAO.git] / TAO / performance-tests / Latency / DSI / client.cpp
blobffe3425aa61a5435d778676367d268fd76d01bf1
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;
17 int
18 parse_args (int argc, ACE_TCHAR *argv[])
20 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("hxk:i:"));
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 '?':
43 default:
44 ACE_ERROR_RETURN ((LM_ERROR,
45 "usage: %s "
46 "-k <ior> "
47 "-i <niterations> "
48 "-x (disable shutdown) "
49 "\n",
50 argv [0]),
51 -1);
53 // Indicates successful parsing of the command line
54 return 0;
57 int
58 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
60 int priority =
61 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
62 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
63 // Enable FIFO scheduling
65 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
66 priority,
67 ACE_SCOPE_PROCESS)) != 0)
69 if (ACE_OS::last_error () == EPERM)
71 ACE_DEBUG ((LM_DEBUG,
72 "client (%P|%t): user is not superuser, "
73 "test runs in time-shared class\n"));
75 else
76 ACE_ERROR ((LM_ERROR,
77 "client (%P|%t): sched_params failed\n"));
80 try
82 CORBA::ORB_var orb =
83 CORBA::ORB_init (argc, argv);
85 if (parse_args (argc, argv) != 0)
86 return 1;
88 CORBA::Object_var object =
89 orb->string_to_object (ior);
91 Test::Roundtrip_var roundtrip =
92 Test::Roundtrip::_narrow (object.in ());
94 if (CORBA::is_nil (roundtrip.in ()))
96 ACE_ERROR_RETURN ((LM_ERROR,
97 "Nil Test::Roundtrip reference <%s>\n",
98 ior),
99 1);
102 for (int j = 0; j < 100; ++j)
104 ACE_hrtime_t start = 0;
105 (void) roundtrip->test_method (start);
108 ACE_Sample_History history (niterations);
110 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
111 for (int i = 0; i < niterations; ++i)
113 ACE_hrtime_t start = ACE_OS::gethrtime ();
115 (void) roundtrip->test_method (start);
117 ACE_hrtime_t now = ACE_OS::gethrtime ();
118 history.sample (now - start);
121 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
123 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
125 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
126 ACE_High_Res_Timer::global_scale_factor_type gsf =
127 ACE_High_Res_Timer::global_scale_factor ();
128 ACE_DEBUG ((LM_DEBUG, "done\n"));
130 if (do_dump_history)
132 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
135 ACE_Basic_Stats stats;
136 history.collect_basic_stats (stats);
137 stats.dump_results (ACE_TEXT("Total"), gsf);
139 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
140 test_end - test_start,
141 stats.samples_count ());
143 if (do_shutdown)
145 roundtrip->shutdown ();
148 catch (const CORBA::Exception& ex)
150 ex._tao_print_exception ("Exception caught:");
151 return 1;
154 return 0;