Esempio n. 1
0
/// send a data frame.
int
TimeStamp_Protocol_Object::send_frame (ACE_Message_Block *frame,
                                       TAO_AV_frame_info *)
{
  ACE_DEBUG ((LM_DEBUG,
              "TimeStamp_Protocol_Object::send_frame\n"));

  ACE_Message_Block* timestamp;
  ACE_NEW_RETURN (timestamp,
                  ACE_Message_Block (BUFSIZ),
                  -1);

  ACE_hrtime_t now = ACE_OS::gethrtime ();

  ACE_UINT64 usec = now;
  ACE_UINT32 val_1 = ACE_CU64_TO_CU32 (usec);
  ACE_DEBUG ((LM_DEBUG,
              "Time Stamp %u usecs\n",
              val_1));

  ACE_OS_String::memcpy (timestamp->wr_ptr (), &now, sizeof (now));
  timestamp->wr_ptr (sizeof (now));

  frame->cont (timestamp);

  ssize_t result = this->transport_->send (frame);
  if (result < 0)
    return result;
  return 0;
}
Esempio n. 2
0
void
Task_Stats::dump_samples (
  const ACE_TCHAR *file_name,
  const ACE_TCHAR *msg,
  ACE_High_Res_Timer::global_scale_factor_type scale_factor)
{
  FILE* output_file = ACE_OS::fopen (file_name, "w");

  // first dump what the caller has to say.
  ACE_OS::fprintf (output_file, "%s\n", ACE_TEXT_ALWAYS_CHAR (msg));

  // next, compose and dump what we want to say.

  // calc throughput.

  ACE_TCHAR out_msg[BUFSIZ];

  ACE_hrtime_t elapsed_microseconds = (end_time_ - base_time_) / scale_factor;
  double elapsed_seconds =
    ACE_CU64_TO_CU32(elapsed_microseconds) / 1000000.0;
  double throughput =
    double(samples_count_) / elapsed_seconds;

  ACE_OS::sprintf (out_msg, ACE_TEXT("#Throughtput: %f\n"), throughput);
  ACE_OS::fprintf (output_file, ACE_TEXT("%s\n"),out_msg);

  // dump latency stats.
  this->dump_latency_stats (out_msg, scale_factor);
  ACE_OS::fprintf (output_file, "%s\n", ACE_TEXT_ALWAYS_CHAR (out_msg));
  ACE_OS::fprintf (output_file, "#Invocation time \t Execution time\n");

  // dump the samples recorded.
  for (size_t i = 0; i != this->samples_count_; ++i)
    {
      ACE_UINT64 x = this->time_inv_[i] / scale_factor;
      ACE_UINT32 val_1 = ACE_CU64_TO_CU32 (x);

      ACE_UINT64 y = this->time_exec_[i] / scale_factor;
      ACE_UINT32 val_2 = ACE_CU64_TO_CU32 (y);

      ACE_OS::fprintf (output_file, "%u \t %u\n",val_1, val_2);
    }

  ACE_OS::fclose (output_file);
}
Esempio n. 3
0
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// function per_iteration
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Given an elapsed time in nanoseconds, returns the time per iteration
// in microseconds.
static
inline
double
per_iteration (const ACE_hrtime_t elapsed /* nanoseconds */)
{
  double ms_per_iteration = (double) ACE_CU64_TO_CU32 (elapsed) / 1000.0 /
                            (double) iterations;

  // Don't print out "-0.000" or "-0.001" . . .
  return -0.002 < ms_per_iteration  &&  ms_per_iteration < 0.0
           ?  0.0
           :  ms_per_iteration;
}
Esempio n. 4
0
void
Receiver_Stats::dump_results (const ACE_TCHAR *msg,
                              FILE *file,
                              ACE_UINT32 sf) const
{
  if (this->samples_count () == 0u)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s : no data collected\n"), msg));
      return;
    }

  ACE_UINT64 avg = this->sum_ / this->samples_count_;
  ACE_UINT64 dev =
    this->sum2_ / this->samples_count_ - avg * avg;

  double l_min = ACE_CU64_TO_CU32 (this->min_) / sf;
  double l_max = ACE_CU64_TO_CU32 (this->max_) / sf;
  double l_avg = ACE_CU64_TO_CU32 (avg) / sf;
  double l_dev = ACE_CU64_TO_CU32 (dev) / (sf * sf);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%s latency   : %.2f[%d]/%.2f/%.2f[%d]/%.2f (min/avg/max/var^2)\n"),
              msg,
              l_min, this->min_at_,
              l_avg,
              l_max, this->max_at_,
              l_dev));

  ACE_OS::fprintf (file,
       ACE_TEXT ("Inter Frame Arrival Time Statistics in msecs  : %.2f[%d]/%.2f/%.2f[%d]/%.2f (min/avg/max/var^2)\n"),
        l_min, this->min_at_,
        l_avg,
        l_max, this->max_at_,
        l_dev);
}
Esempio n. 5
0
int
Receiver_Callback::receive_frame (ACE_Message_Block *frame,
                                  TAO_AV_frame_info *,
                                  const ACE_Addr &)
{
  //
  // Upcall from the AVStreams when there is data to be received from
  // the sender.
  //
  ACE_DEBUG ((LM_DEBUG,
              "Receiver_Callback::receive_frame for frame %d\n",
              this->frame_count_++));

  int frame_size = BUFSIZ;

  // Write the received data to the file.
  size_t result =
    ACE_OS::fwrite (frame->rd_ptr (),
                    frame_size,
                    1,
                    output_file);

  if (result == frame->length ())
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Receiver_Callback::fwrite failed\n"),
                      -1);
  frame->rd_ptr (frame_size);

  ACE_hrtime_t stamp;
  ACE_OS_String::memcpy (&stamp, frame->rd_ptr (), sizeof (stamp));

  ACE_UINT64 usec = stamp;
  ACE_UINT32 val_1 = ACE_CU64_TO_CU32 (usec);

  ACE_DEBUG ((LM_DEBUG,
              "Time Stamp %u\n",
              val_1));

  frame->reset ();
  return 0;
}
Esempio n. 6
0
void
Task_Stats::dump_latency_stats (
  ACE_TCHAR *out_msg,
  ACE_High_Res_Timer::global_scale_factor_type sf)
{
  if (this->samples_count_ == 0u)
    {
      ACE_OS::sprintf (out_msg,
                       ACE_TEXT ("# no data collected\n"));
      return;
    }

  ACE_UINT64 avg = this->sum_ / this->samples_count_;
  ACE_UINT64 dev =
  this->sum2_ / this->samples_count_ - avg * avg;

  ACE_UINT64 l_min_ = this->exec_time_min_ / sf;
  ACE_UINT32 l_min = ACE_CU64_TO_CU32 (l_min_);

  ACE_UINT64 l_max_ = this->exec_time_max_ / sf;
  ACE_UINT32 l_max = ACE_CU64_TO_CU32 (l_max_);

  ACE_UINT32 l_avg = ACE_CU64_TO_CU32(avg / sf);
  ACE_UINT32 l_dev = ACE_CU64_TO_CU32(dev / (sf * sf));

  ACE_UINT64 tmin_ = this->time_inv_[0] / sf;
  ACE_UINT32 tmin = ACE_CU64_TO_CU32 (tmin_);

  ACE_UINT64 tmax_ = this->time_inv_[samples_count_-1] / sf;
  ACE_UINT32 tmax = ACE_CU64_TO_CU32 (tmax_);

  ACE_OS::sprintf(out_msg,
                ACE_TEXT ("#latency   : %u[%d]/%u/%u[%d]/%u (min/avg/max/var^2)\n #first invocation time = %u, last invocation time = %u\n"),
                l_min, this->exec_time_min_at_,
                l_avg,
                l_max, this->exec_time_max_at_,
                l_dev,
                tmin,tmax);
}
Esempio n. 7
0
void
ACE_Throughput_Stats::dump_results (const ACE_TCHAR* msg,
                                    ACE_UINT32 sf)
{
  if (this->samples_count () == 0u)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%s : no data collected\n"), msg));
      return;
    }

  this->ACE_Basic_Stats::dump_results (msg, sf);

  ACE_Throughput_Stats::dump_throughput (msg, sf,
                                         this->throughput_last_,
                                         this->samples_count ());

#if 0
  // @@TODO: This is what I really wanted to generate, but it just
  // doesn't work.
  double t_sum_x =
    ACE_CU64_TO_CU32 (this->throughput_sum_x_);// / sf);
  //t_sum_x /= 1000000.0;
  double t_sum_y =
    ACE_CU64_TO_CU32 (this->throughput_sum_y_);
  double t_sum_x2 =
    ACE_CU64_TO_CU32 (this->throughput_sum_x2_);// / (sf*sf));
  //t_sum_x2 /= 1000000.0;
  //t_sum_x2 /= 1000000.0;
  double t_sum_y2 =
    ACE_CU64_TO_CU32 (this->throughput_sum_y2_);
  double t_sum_xy =
    ACE_CU64_TO_CU32 (this->throughput_sum_xy_);// / sf);
  //t_sum_xy /= 1000000.0;
  double t_avgx = t_sum_x / this->samples_count ();
  double t_avgy = t_sum_y / this->samples_count ();

  double t_a =
    (this->samples_count () * t_sum_xy - t_sum_x * t_sum_y)
    / (this->samples_count () * t_sum_x2 - t_sum_x * t_sum_x);
  double t_b = (t_avgy - t_a * t_avgx);

  t_a *= 1000000.0;

  double d_r =
    (t_sum_xy - t_avgx * t_sum_y - t_avgy * t_sum_x
     + this->samples_count () * t_avgx * t_avgy);
  double n_r =
    (t_sum_x2
     - this->samples_count () * t_avgx * t_avgx)
    * (t_sum_y2
       - this->samples_count () * t_avgy * t_avgy);
  double t_r = d_r * d_r / n_r;

  //  ACE_DEBUG ((LM_DEBUG,
  //              "%s throughput: %.2f/%.2f/%.2f/%.6f/%.2f (avg/a/b/r/elapsed)\n",
  //              msg, t_avg, t_a, t_b, t_r, seconds));
  //  ACE_DEBUG ((LM_DEBUG,
  //              "%s        data: %.2f/%.2f/%.2f/%.6f/%.2f (x/x2/y/y2/xy)\n",
  //              msg, t_sum_x, t_sum_x2, t_sum_y, t_sum_y2, t_sum_xy));
#endif
}