Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / TAO / performance-tests / Latency / Single_Threaded / client.cpp
blobe2e51c13a181977b26693a78ed613dbd0edbd5ab
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 "-h (dump history) "
50 "\n",
51 argv [0]),
52 -1);
54 // Indicates successful parsing of the command line
55 return 0;
58 int
59 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
61 int priority =
62 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
63 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
64 // 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 Test::Roundtrip_var roundtrip =
93 Test::Roundtrip::_narrow (object.in ());
95 if (CORBA::is_nil (roundtrip.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "Nil Test::Roundtrip reference <%s>\n",
99 ior),
103 for (int j = 0; j < 100; ++j)
105 ACE_hrtime_t start = 0;
106 (void) roundtrip->test_method (start);
109 ACE_Sample_History history (niterations);
111 ACE_hrtime_t test_start = ACE_OS::gethrtime ();
112 for (int i = 0; i < niterations; ++i)
114 ACE_hrtime_t start = ACE_OS::gethrtime ();
116 (void) roundtrip->test_method (start);
118 ACE_hrtime_t now = ACE_OS::gethrtime ();
119 history.sample (now - start);
122 ACE_hrtime_t test_end = ACE_OS::gethrtime ();
124 ACE_DEBUG ((LM_DEBUG, "test finished\n"));
126 ACE_DEBUG ((LM_DEBUG, "High resolution timer calibration...."));
127 ACE_High_Res_Timer::global_scale_factor_type gsf =
128 ACE_High_Res_Timer::global_scale_factor ();
129 ACE_DEBUG ((LM_DEBUG, "done\n"));
131 if (do_dump_history)
133 history.dump_samples (ACE_TEXT("HISTORY"), gsf);
136 ACE_Basic_Stats stats;
137 history.collect_basic_stats (stats);
138 stats.dump_results (ACE_TEXT("Total"), gsf);
140 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"), gsf,
141 test_end - test_start,
142 stats.samples_count ());
144 if (do_shutdown)
146 roundtrip->shutdown ();
149 catch (const CORBA::Exception& ex)
151 ex._tao_print_exception ("Exception caught:");
152 return 1;
155 return 0;