More tests update
[ACE_TAO.git] / TAO / examples / PluggableUDP / tests / SimplePerformance / client.cpp
blobae03fd9da69824e679fd3b934822934402795ea2
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * This is the client for the UDP simple performance test.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
13 #include "ace/Get_Opt.h"
14 #include "ace/Task.h"
15 #include "ace/High_Res_Timer.h"
16 #include "testC.h"
18 // The following include file forces DIOP to be linked into the
19 // executable and initialized for static builds.
20 #include "tao/Strategies/advanced_resource.h"
22 #if defined (ACE_VXWORKS) && !defined (__RTP__)
23 # undef ACE_MAIN
24 # define ACE_MAIN testClient
25 #endif
27 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
29 int
30 parse_args (int argc, ACE_TCHAR *argv[])
32 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
33 int c;
35 while ((c = get_opts ()) != -1)
36 switch (c)
38 case 'k':
39 ior = get_opts.opt_arg ();
40 break;
42 case '?':
43 default:
44 ACE_ERROR_RETURN ((LM_ERROR,
45 "usage: %s "
46 "-k <ior> "
47 "\n",
48 argv [0]),
49 -1);
51 // Indicates successful parsing of the command line
52 return 0;
55 ACE_UINT32 niter = 10;
56 ACE_UINT32 SIZE_BLOCK= 256;
58 /**
59 * @class Client
61 * @brief Run the client thread
63 * Use the ACE_Task_Base class to run the client threads.
65 class Client
67 public:
68 /// ctor
69 Client (Simple_Server_ptr server, ACE_UINT32 niterations);
71 virtual ~Client (void) {};
73 /// The thread entry point.
74 virtual int svc (void);
76 private:
77 /// The server.
78 Simple_Server_var server_;
80 /// The number of iterations on each client thread.
81 ACE_UINT32 niterations_;
85 //int testClient (char* orbName, char* ior)
86 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
88 try
90 CORBA::ORB_var orb =
91 CORBA::ORB_init (argc,
92 argv,
93 "ORB_Test_Client");
95 if (parse_args (argc, argv) != 0)
96 return 1;
98 CORBA::Object_var object =
99 orb->string_to_object (ior);
101 Simple_Server_var server =
102 Simple_Server::_narrow (object.in ());
104 if (CORBA::is_nil (server.in ()))
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "Object reference <%s> is nil.\n",
108 ior),
112 CORBA::String_var string =
113 orb->object_to_string (server.in ());
115 ACE_DEBUG ((LM_DEBUG,
116 "Client: orb->object_to_string: <%C>\n",
117 string.in ()));
119 Client client (server.in (), niter);
121 client.svc ();
123 //ACE_DEBUG ((LM_DEBUG, "threads finished\n"));
125 orb->destroy ();
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Caught exception:");
130 return 1;
133 return 0;
137 // ****************************************************************
139 Client::Client (Simple_Server_ptr server,
140 ACE_UINT32 niterations)
141 : server_ (Simple_Server::_duplicate (server)),
142 niterations_ (niterations)
148 Client::svc (void)
152 Octet_Seq octetSeq(SIZE_BLOCK);
153 Char_Seq charSeq(SIZE_BLOCK);
154 ACE_High_Res_Timer timer;
155 ACE_OS::printf("Start sending %d Msgs...\n",this->niterations_);
157 charSeq.length(SIZE_BLOCK);
158 octetSeq.length(SIZE_BLOCK);
160 // This sets up the connector, so that we do not incur
161 // the overhead on the first call in the loop.
162 server_->sendCharSeq (charSeq);
164 timer.start ();
166 ACE_UINT32 client_count = 0;
167 for (ACE_UINT32 i = 0; i < this->niterations_; ++i)
169 client_count++;
171 server_->sendCharSeq (charSeq);
173 //server_->sendOctetSeq (octetSeq);
175 //ACE_DEBUG ((LM_DEBUG, "."));
177 timer.stop ();
179 ACE_Time_Value measured;
180 timer.elapsed_time (measured);
182 //ACE_DEBUG ((LM_DEBUG, "...finished\n"));
184 time_t dur = measured.sec () * 1000000 + measured.usec ();
185 if (dur == 0 || this->niterations_ == 0)
186 ACE_DEBUG ((LM_DEBUG, "Time not measurable, calculation skipped\n"));
187 else
189 ACE_DEBUG ((LM_DEBUG,
190 "Time for %u Msgs: %u usec\n",
191 this->niterations_,
192 dur));
194 ACE_DEBUG ((LM_DEBUG, "Time for 1 Msg: %u usec, %u calls/sec\n",
195 dur / this->niterations_,
196 1000000 / (dur / this->niterations_)));
199 for (int c = 0; c < 10; ++c)
200 server_->shutdown ();
203 catch (const CORBA::Exception& ex)
205 ex._tao_print_exception ("MT_Client: exception raised");
207 return 0;