2 //=============================================================================
6 * This is the client for the UDP simple performance test.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
13 #include "ace/Get_Opt.h"
15 #include "ace/High_Res_Timer.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__)
24 # define ACE_MAIN testClient
27 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
30 parse_args (int argc
, ACE_TCHAR
*argv
[])
32 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
35 while ((c
= get_opts ()) != -1)
39 ior
= get_opts
.opt_arg ();
44 ACE_ERROR_RETURN ((LM_ERROR
,
51 // Indicates successful parsing of the command line
55 ACE_UINT32 niter
= 10;
56 ACE_UINT32 SIZE_BLOCK
= 256;
61 * @brief Run the client thread
63 * Use the ACE_Task_Base class to run the client threads.
69 Client (Simple_Server_ptr server
, ACE_UINT32 niterations
);
71 virtual ~Client (void) {};
73 /// The thread entry point.
74 virtual int svc (void);
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
[])
91 CORBA::ORB_init (argc
,
95 if (parse_args (argc
, argv
) != 0)
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",
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",
119 Client
client (server
.in (), niter
);
123 //ACE_DEBUG ((LM_DEBUG, "threads finished\n"));
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Caught exception:");
137 // ****************************************************************
139 Client::Client (Simple_Server_ptr server
,
140 ACE_UINT32 niterations
)
141 : server_ (Simple_Server::_duplicate (server
)),
142 niterations_ (niterations
)
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
);
166 ACE_UINT32 client_count
= 0;
167 for (ACE_UINT32 i
= 0; i
< this->niterations_
; ++i
)
171 server_
->sendCharSeq (charSeq
);
173 //server_->sendOctetSeq (octetSeq);
175 //ACE_DEBUG ((LM_DEBUG, "."));
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"));
189 ACE_DEBUG ((LM_DEBUG
,
190 "Time for %u Msgs: %u usec\n",
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");