📄 client.cpp
字号:
// client.cpp,v 1.30 2003/12/24 17:46:34 bala Exp
#include "testC.h"
#include "tao/Messaging/Messaging.h"
#include "tao/TAOC.h"
#include "tao/TAOA.h"
#include "ace/Get_Opt.h"
#include "ace/Sched_Params.h"
#include "ace/Stats.h"
#include "ace/High_Res_Timer.h"
#include "ace/OS_NS_errno.h"
ACE_RCSID (Reliable,
client,
"client.cpp,v 1.30 2003/12/24 17:46:34 bala Exp")
#define USING_TIMERS
//#define USING_QUANTIFY
#if defined (USING_QUANTIFY)
#if defined (ACE_WIN32)
#include "pure.h"
#else /* !ACE_WIN32 */
#include "quantify.h"
inline int QuantifyClearData ()
{
return quantify_clear_data ();
}
inline int QuantifyStartRecordingData ()
{
return quantify_start_recording_data ();
}
inline int QuantifyStopRecordingData ()
{
return quantify_stop_recording_data ();
}
#endif /* ACE_WIN32 */
#endif /* USING_QUANTIFY */
// Default IOR.
static const char *ior = "file://test.ior";
// Levels at which syncscope policy can be set.
enum LEVEL {ORB_LEVEL, THREAD_LEVEL, OBJECT_LEVEL};
// Default is OBJECT level.
static LEVEL level = OBJECT_LEVEL;
// Default iterations.
static CORBA::ULong iterations = 100;
// Default amount of work.
static CORBA::ULong work = 0;
// Benchmark payload based operations?
static int payload_test = 0;
// Default payload size.
static CORBA::ULong payload_size = 0;
// Default number of invocations to buffer before flushing.
static CORBA::ULong buffering_queue_size = iterations / 2;
// Benchmark the twoway operation?
static int test_twoway = 0;
// Shut down server after test?
static int shutdown_server = 0;
// Default SyncScope value.
static Messaging::SyncScope sync_scope = Messaging::SYNC_WITH_TRANSPORT;
// Global scale factor.
static ACE_UINT32 gsf = 0;
static void
print_params (void)
{
if (test_twoway)
{
ACE_DEBUG ((LM_DEBUG,
"\nTesting twoway requests\n"));
}
else
{
const char *one_way_style = 0;
if (sync_scope == Messaging::SYNC_NONE)
one_way_style = "SYNC_NONE";
else if (sync_scope == Messaging::SYNC_WITH_TRANSPORT)
one_way_style = "SYNC_WITH_TRANSPORT";
else if (sync_scope == Messaging::SYNC_WITH_SERVER)
one_way_style = "SYNC_WITH_SERVER";
else if (sync_scope == Messaging::SYNC_WITH_TARGET)
one_way_style = "SYNC_WITH_TARGET";
const char *payload_style = 0;
if (payload_test)
payload_style = "Payload based";
else
payload_style = "Work based";
ACE_DEBUG ((LM_DEBUG,
"\nTesting oneway requests: %s : %s\n",
one_way_style,
payload_style));
if (sync_scope == Messaging::SYNC_NONE)
{
ACE_DEBUG ((LM_DEBUG,
"Request queue limited to %d messages\n",
buffering_queue_size));
}
if (payload_test)
{
ACE_DEBUG ((LM_DEBUG,
"Payload size %d bytes\n",
payload_size));
}
}
ACE_DEBUG ((LM_DEBUG,
"%d invocations\n",
iterations));
}
static void
twoway_work_test (Test_ptr server
ACE_ENV_ARG_DECL)
{
#if defined (USING_TIMERS)
ACE_Throughput_Stats latency;
ACE_hrtime_t base = ACE_OS::gethrtime ();
#endif /* USING_TIMERS */
#if defined (USING_QUANTIFY)
// Reset Quantify data recording; whatever happened in the past is
// not relevant to this test.
QuantifyClearData ();
QuantifyStartRecordingData ();
#endif /* USING_QUANTIFY */
for (CORBA::ULong i = 0; i != iterations; ++i)
{
#if defined (USING_TIMERS)
ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
#endif /* USING_TIMERS */
server->twoway_work_test (work
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
#if defined (USING_TIMERS)
ACE_hrtime_t now = ACE_OS::gethrtime ();
latency.sample (now - base,
now - latency_base);
#endif /* USING_TIMERS */
}
#if defined (USING_QUANTIFY)
// Stop recording data here; whatever happens after this in the test
// is not relevant to this test.
QuantifyStopRecordingData ();
#endif /* USING_QUANTIFY */
#if defined (USING_TIMERS)
latency.dump_results ("Twoway", gsf);
#endif /* USING_TIMERS */
}
static void
oneway_work_test (Test_ptr server
ACE_ENV_ARG_DECL)
{
#if defined (USING_TIMERS)
ACE_Throughput_Stats latency;
ACE_hrtime_t base = ACE_OS::gethrtime ();
#endif /* USING_TIMERS */
#if defined (USING_QUANTIFY)
// Reset Quantify data recording; whatever happened in the past is
// not relevant to this test.
QuantifyClearData ();
QuantifyStartRecordingData ();
#endif /* USING_QUANTIFY */
for (CORBA::ULong i = 0; i != iterations; ++i)
{
#if defined (USING_TIMERS)
ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
#endif /* USING_TIMERS */
server->oneway_work_test (work
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
#if defined (USING_TIMERS)
ACE_hrtime_t now = ACE_OS::gethrtime ();
latency.sample (now - base,
now - latency_base);
#endif /* USING_TIMERS */
}
#if defined (USING_QUANTIFY)
// Stop recording data here; whatever happens after this in the test
// is not relevant to this test.
QuantifyStopRecordingData ();
#endif /* USING_QUANTIFY */
#if defined (USING_TIMERS)
latency.dump_results ("Oneway (work based)", gsf);
#endif /* USING_TIMERS */
}
static void
oneway_payload_test (Test_ptr server
ACE_ENV_ARG_DECL)
{
#if defined (USING_TIMERS)
ACE_Throughput_Stats latency;
ACE_hrtime_t base = ACE_OS::gethrtime ();
#endif /* USING_TIMERS */
#if defined (USING_QUANTIFY)
// Reset Quantify data recording; whatever happened in the past is
// not relevant to this test.
QuantifyClearData ();
QuantifyStartRecordingData ();
#endif /* USING_QUANTIFY */
Test::data the_data (payload_size);
the_data.length (payload_size);
for (CORBA::ULong i = 0; i != iterations; ++i)
{
#if defined (USING_TIMERS)
ACE_hrtime_t latency_base = ACE_OS::gethrtime ();
#endif /* USING_TIMERS */
server->oneway_payload_test (the_data
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
#if defined (USING_TIMERS)
ACE_hrtime_t now = ACE_OS::gethrtime ();
latency.sample (now - base,
now - latency_base);
#endif /* USING_TIMERS */
}
#if defined (USING_QUANTIFY)
// Stop recording data here; whatever happens after this in the test
// is not relevant to this test.
QuantifyStopRecordingData ();
#endif /* USING_QUANTIFY */
#if defined (USING_TIMERS)
latency.dump_results ("Oneway (payload based)", gsf);
#endif /* USING_TIMERS */
}
static int
parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv, "ps:k:i:t:l:m:w:x");
int error = 0;
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 's':
payload_size = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'p':
payload_test = 1;
break;
case 'i':
iterations = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'k':
ior = get_opts.opt_arg ();
break;
case 't':
{
char *tmp = get_opts.opt_arg ();
if (!ACE_OS::strcmp (tmp, "none"))
sync_scope = Messaging::SYNC_NONE;
else if (!ACE_OS::strcmp (tmp, "transport"))
sync_scope = Messaging::SYNC_WITH_TRANSPORT;
else if (!ACE_OS::strcmp (tmp, "server"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -