📄 task_client.cpp
字号:
ACE_ENV_ARG_PARAMETER);
STOP_QUANTIFY;
ACE_TRY_CHECK;
// Perform the cube operation.
arg_octet = arg_octet * arg_octet * arg_octet;
if (arg_octet != ret_octet)
{
this->error_count_++;
ACE_ERROR_RETURN ((LM_ERROR,
"** cube_octet (%d) (--> %d)\n",
arg_octet,
ret_octet),
-1);
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "call to cube_octet()\n");
return -1;
}
ACE_ENDTRY;
return 0;
}
int
Client::cube_short (void)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
this->call_count_++;
CORBA::Short arg_short = func (this->num_);
CORBA::Short ret_short;
START_QUANTIFY;
ret_short = this->cubit_->cube_short (arg_short
ACE_ENV_ARG_PARAMETER);
STOP_QUANTIFY;
ACE_TRY_CHECK;
arg_short = arg_short * arg_short * arg_short;
if (arg_short != ret_short)
{
this->error_count_++;
ACE_ERROR_RETURN ((LM_ERROR,
"** cube_short (%d) (--> %d)\n",
arg_short ,
ret_short),
-1);
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "call to cube_short\n");
return -1;
}
ACE_ENDTRY;
return 0;
}
int
Client::cube_long (void)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
this->call_count_++;
CORBA::Long arg_long = func (this->num_);
CORBA::Long ret_long;
START_QUANTIFY;
ret_long = this->cubit_->cube_long (arg_long
ACE_ENV_ARG_PARAMETER);
STOP_QUANTIFY;
ACE_TRY_CHECK;
arg_long = arg_long * arg_long * arg_long;
if (arg_long != ret_long)
{
this->error_count_++;
ACE_ERROR ((LM_ERROR,
"** cube_long (%d) (--> %d)\n",
arg_long,
ret_long));
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "call to cube_long()\n");
return -1;
}
ACE_ENDTRY;
return 0;
}
int
Client::cube_struct (void)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
Cubit::Many arg_struct;
Cubit::Many ret_struct;
this->call_count_++;
arg_struct.l = func (this->num_);
arg_struct.s = func (this->num_);
arg_struct.o = func (this->num_);
START_QUANTIFY;
ret_struct = this->cubit_->cube_struct (arg_struct
ACE_ENV_ARG_PARAMETER);
STOP_QUANTIFY;
ACE_TRY_CHECK;
arg_struct.l = arg_struct.l * arg_struct.l * arg_struct.l ;
arg_struct.s = arg_struct.s * arg_struct.s * arg_struct.s ;
arg_struct.o = arg_struct.o * arg_struct.o * arg_struct.o ;
if (arg_struct.l != ret_struct.l
|| arg_struct.s != ret_struct.s
|| arg_struct.o != ret_struct.o )
{
this->error_count_++;
ACE_ERROR ((LM_ERROR,
"**cube_struct error!\n"));
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "call to cube_struct()\n");
return -1;
}
ACE_ENDTRY;
return 0;
}
int
Client::make_request (void)
{
int result;
if (this->ts_->oneway_ == 0)
{
switch (this->ts_->datatype_)
{
case CB_OCTET:
result = this->cube_octet ();
break;
// Cube a short.
case CB_SHORT:
result = this->cube_short ();
break;
// Cube a long.
case CB_LONG:
result = this->cube_long ();
break;
// Cube a "struct" ...
case CB_STRUCT:
result = this->cube_struct ();
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t); %s:%d; unexpected datatype: %d\n",
this->ts_->datatype_), -1);
}
if (result != 0)
return result;
}
else
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
this->call_count_++;
START_QUANTIFY;
this->cubit_->noop (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
STOP_QUANTIFY;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "oneway call noop()\n");
return -1;
}
ACE_ENDTRY;
}
// return success.
return 0;
}
void
Client::print_stats (void)
{
// Perform latency stats only if we are not running the utilization
// tests.
if (this->call_count_ > 0
&& this->ts_->use_utilization_test_ == 0)
{
if (this->error_count_ == 0)
{
// Latency is in usecs.
ACE_timer_t calls_per_second =
(this->call_count_ * ACE_ONE_SECOND_IN_USECS) / this->latency_;
// Calculate average (per-call) latency in usecs.
this->latency_ = this->latency_/this->call_count_;
if (this->latency_ > 0)
{
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) cube average call ACE_OS::time\t= %A msec, \t"
"%A calls/second\n",
this->latency_ / ACE_ONE_SECOND_IN_MSECS,
calls_per_second));
this->put_latency (this->my_jitter_array_,
this->latency_,
this->id_,
this->call_count_);
}
else
{
// Still we have to call this function to store a valid
// array pointer.
this->put_latency (this->my_jitter_array_,
0,
this->id_,
this->call_count_);
ACE_DEBUG ((LM_DEBUG,
"*** Warning: Latency, %f, is less than or equal to zero."
" Precision may have been lost.\n, this->latency_"));
}
}
ACE_DEBUG ((LM_DEBUG,
"%d calls, %d errors\n",
this->call_count_,
this->error_count_));
}
}
ACE_timer_t
Client::calc_delta (ACE_timer_t real_time,
ACE_timer_t delta)
{
ACE_timer_t new_delta;
#if defined (ACE_LACKS_FLOATING_POINT)
new_delta = 40 * real_time / 100 + 60 * delta / 100;
#else /* !ACE_LACKS_FLOATING_POINT */
new_delta = 0.4 * fabs (real_time) + 0.6 * delta;
#endif /* ACE_LACKS_FLOATING_POINT */
return new_delta;
}
int
Client::do_test (void)
{
ACE_timer_t delta = 0;
u_int low_priority_client_count = this->ts_->thread_count_ - 1;
ACE_timer_t sleep_time = // usec
(ACE_ONE_SECOND_IN_USECS * this->ts_->granularity_)/this->frequency_;
u_int i;
int result = 0;
for (i = 0;
// keep running for loop count, OR
i < this->ts_->loop_count_
// keep running if we are the highest priority thread and at
// least another lower client thread is running, OR
|| (id_ == 0 && this->ts_->thread_count_ > 1)
// keep running if test is thread_per_rate and we're not the
// lowest frequency thread.
|| (this->ts_->thread_per_rate_ == 1
&& id_ < (this->ts_->thread_count_ - 1));
i++)
{
// Start timing a call.
if ((i % this->ts_->granularity_) == 0 &&
this->ts_->use_utilization_test_ == 0)
{
// Delay a sufficient amount of time to be able to enforce
// the calling frequency, e.g., 20Hz, 10Hz, 5Hz, 1Hz.
ACE_Time_Value tv (0,
(u_long) (sleep_time < delta
? 0
: sleep_time - delta));
ACE_OS::sleep (tv);
this->timer_->start ();
}
this->num_ = i;
// make a request to the server object depending on the datatype.
result = this->make_request ();
if (result != 0)
return 2;
// Stop the timer.
if (i % this->ts_->granularity_ == this->ts_->granularity_ - 1
&& this->ts_->use_utilization_test_ == 0)
{
this->timer_->stop ();
// Calculate time elapsed.
ACE_timer_t real_time;
real_time = this->timer_->get_elapsed ();
// Recalculate delta = 0.4 * elapsed_time + 0.6 *
// delta. This is used to adjust the sleeping time so that
// we make calls at the required frequency.
delta = this->calc_delta (real_time,delta);
this->latency_ += real_time * this->ts_->granularity_;
if ((result = this->my_jitter_array_->enqueue_tail (real_time)) != 0)
ACE_DEBUG ((LM_DEBUG, "(%t) Error: my_jitter_array->enqueue_tail() returned %d\n", result));
}
if (this->ts_->thread_per_rate_ == 1
&& id_ < (this->ts_->thread_count_ - 1))
{
if (this->ts_->semaphore_->tryacquire () != -1)
break;
}
else
// If we are the high priority client. If tryacquire()
// succeeded then a client must have done a release () on it,
// thus we decrement the client counter.
if (id_ == 0
&& this->ts_->thread_count_ > 1)
{
if (this->ts_->semaphore_->tryacquire () != -1)
{
low_priority_client_count --;
// If all clients are done then break out of loop.
if (low_priority_client_count <= 0)
break;
}
}
} /* end of for () */
ACE_DEBUG ((LM_DEBUG, "(%t; %D) do_test executed %u iterations\n", i));
return 0;
}
int
Client::run_tests (void)
{
int result;
ACE_NEW_RETURN (this->my_jitter_array_,
JITTER_ARRAY,
-1);
ACE_NEW_RETURN (this->timer_,
MT_Cubit_Timer (this->ts_->granularity_),
-1);
if (this->ts_->use_utilization_test_ == 1)
this->timer_->start ();
// Make the calls in a loop.
result = this->do_test ();
if (result != 0)
return result;
if (id_ == 0)
this->ts_->high_priority_loop_count_ =
this->call_count_;
if (this->ts_->use_utilization_test_ == 1)
{
this->timer_->stop ();
this->ts_->util_test_time_ = this->timer_->get_elapsed ();
}
// Print the latency results.
this->print_stats ();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -