Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Generic_Servant / client.cpp
blob66d24818a2438e39f0376aeec79dd9791f76bae8
1 #include "ace/Get_Opt.h"
2 #include "ace/Argv_Type_Converter.h"
3 #include "ace/Profile_Timer.h"
4 #include "ace/Read_Buffer.h"
5 #include "testC.h"
7 static ACE_TCHAR *IOR = 0;
8 static int iterations = 1;
9 static int oneway = 0;
10 static int shutdown_server = 0;
11 static CORBA::ULong timeout = 5;
12 static int timed_method = 0;
14 static int
15 parse_args (int argc, ACE_TCHAR **argv)
17 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("f:k:i:T:otx"));
18 int c;
20 while ((c = get_opts ()) != -1)
21 switch (c)
23 case 'k':
24 IOR = get_opts.opt_arg ();
25 break;
27 case 'o':
28 oneway = 1;
29 break;
31 case 't':
32 timed_method = 1;
33 break;
35 case 'i':
36 iterations = ACE_OS::atoi (get_opts.opt_arg ());
37 break;
39 case 'T':
40 timeout = static_cast<CORBA::ULong> (ACE_OS::atoi (get_opts.opt_arg ()));
41 break;
43 case 'x':
44 shutdown_server = 1;
45 break;
47 case '?':
48 default:
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "usage: %s "
51 "-k IOR "
52 "-o oneway "
53 "-t timed operations "
54 "-T timeout for timed operations "
55 "-i iterations "
56 "-x shutdown server "
57 "\n",
58 argv [0]),
59 -1);
62 if (IOR == 0)
63 ACE_ERROR_RETURN ((LM_ERROR,
64 "Please specify the IOR for the servant\n"), -1);
66 // Indicates successful parsing of command line.
67 return 0;
70 void
71 print_stats (ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time,
72 int iterations)
74 if (iterations > 0)
76 elapsed_time.real_time *= ACE_ONE_SECOND_IN_MSECS;
77 elapsed_time.user_time *= ACE_ONE_SECOND_IN_MSECS;
78 elapsed_time.system_time *= ACE_ONE_SECOND_IN_MSECS;
80 elapsed_time.real_time /= iterations;
81 elapsed_time.user_time /= iterations;
82 elapsed_time.system_time /= iterations;
84 double tmp = 1000 / elapsed_time.real_time;
86 ACE_DEBUG ((LM_DEBUG,
87 "\titerations\t = %d,\n"
88 "\treal_time\t = %0.06f ms,\n"
89 "\tuser_time\t = %0.06f ms,\n"
90 "\tsystem_time\t = %0.06f ms,\n"
91 "\t%0.00f calls/second\n",
92 iterations,
93 elapsed_time.real_time < 0.0 ? 0.0 : elapsed_time.real_time,
94 elapsed_time.user_time < 0.0 ? 0.0 : elapsed_time.user_time,
95 elapsed_time.system_time < 0.0 ? 0.0 : elapsed_time.system_time,
96 tmp < 0.0 ? 0.0 : tmp));
98 else
99 ACE_ERROR ((LM_ERROR,
100 "\tNo time stats printed. Zero iterations or error occurred.\n"));
104 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
108 // Initialize the ORB
109 CORBA::ORB_var orb =
110 CORBA::ORB_init (argc, argv);
112 // Initialize options based on command-line arguments.
113 int parse_args_result =
114 parse_args (argc, argv);
115 if (parse_args_result != 0)
116 return parse_args_result;
118 // Get an object reference from the argument string.
119 CORBA::Object_var object =
120 orb->string_to_object (IOR);
122 // Try to narrow the object reference to a test reference.
123 test_var test = test::_narrow (object.in ());
125 CORBA::String_var ior =
126 orb->object_to_string (test.in ());
128 ACE_DEBUG ((LM_DEBUG,
129 "\nConnecting to: %C\n\n",
130 ior.in ()));
132 ACE_Profile_Timer timer;
133 ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time;
135 // We start an ACE_Profile_Timer here...
136 timer.start ();
138 int i = 0;
140 for (i = 0; i < iterations; i++)
142 if (oneway && timed_method)
144 test->timed_oneway_method (timeout);
146 else if (oneway)
148 test->oneway_method ();
150 else if (!oneway && timed_method)
152 test->timed_method (timeout);
154 else
156 test->method ();
160 // stop the timer.
161 timer.stop ();
162 timer.elapsed_time (elapsed_time);
164 // compute average time.
165 print_stats (elapsed_time, i);
167 if (shutdown_server)
169 test->shutdown ();
172 orb->destroy ();
174 catch (const CORBA::Exception& ex)
176 ex._tao_print_exception ("Error!");
177 return -1;
180 return 0;