Ejemplo n.º 1
0
void
ACE_Throughput_Stats::dump_throughput (const ACE_TCHAR *msg,
                                       ACE_UINT32 sf,
                                       ACE_UINT64 elapsed_time,
                                       ACE_UINT32 samples_count)
{
#ifndef ACE_NLOGGING
  double seconds =
# if defined ACE_LACKS_LONGLONG_T
    elapsed_time / sf;
#elif  defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
    static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (
                           ACE_U_LongLong(elapsed_time / sf)));
# else  /* ! ACE_LACKS_LONGLONG_T */
    static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (elapsed_time / sf));
# endif /* ! ACE_LACKS_LONGLONG_T */
  seconds /= ACE_HR_SCALE_CONVERSION;

  const double t_avg = samples_count / seconds;

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%s throughput: %.2f (events/second)\n"),
              msg, t_avg));
#else
  ACE_UNUSED_ARG (msg);
  ACE_UNUSED_ARG (sf);
  ACE_UNUSED_ARG (elapsed_time);
  ACE_UNUSED_ARG (samples_count);
#endif /* ACE_NLOGGING */
}
Ejemplo n.º 2
0
void
TAO_Log_i::reset_capacity_alarm_threshold (void)
{
  const CORBA::ULongLong max_size =
    this->recordstore_->get_max_size ();

  if (max_size != 0 && this->thresholds_.length() > 0)
    {
      const DsLogAdmin::LogFullActionType log_full_action =
        this->recordstore_->get_log_full_action ();

      if (log_full_action == DsLogAdmin::halt)
        {
          const CORBA::ULongLong current_size =
            this->recordstore_->get_current_size ();

          const CORBA::UShort percent =
            static_cast<CORBA::UShort> (((double) ACE_UINT64_DBLCAST_ADAPTER (current_size * 100U)) /
                                         (double) ACE_UINT64_DBLCAST_ADAPTER (max_size));

          this->current_threshold_ = 0;

          while (this->current_threshold_ < this->thresholds_.length ()
                 && this->thresholds_[this->current_threshold_] <= percent)
            ++this->current_threshold_;
        }
    }
}
Ejemplo n.º 3
0
void
TAO_Log_i::check_capacity_alarm_threshold (void)
{
  const CORBA::ULongLong max_size =
    this->recordstore_->get_max_size ();

  if (max_size != 0 && this->thresholds_.length () > 0)
    {
      const DsLogAdmin::LogFullActionType log_full_action =
        this->recordstore_->get_log_full_action ();

      CORBA::ULongLong current_size =
        ((log_full_action == DsLogAdmin::wrap)
        ? this->recordstore_->get_gauge ()
        : this->recordstore_->get_current_size ());

      const CORBA::UShort percent =
        static_cast<CORBA::UShort> (((double) ACE_UINT64_DBLCAST_ADAPTER (current_size * 100U) /
                                     (double) ACE_UINT64_DBLCAST_ADAPTER (max_size)));

      while (current_threshold_ < this->thresholds_.length ()
             && this->thresholds_[this->current_threshold_] <= percent)
        {
          if (notifier_)
            {
              const DsLogNotification::PerceivedSeverityType severity =
                ((percent == 100)
                ? DsLogNotification::critical
                : DsLogNotification::minor);

              notifier_->threshold_alarm (
                this->log_.in (),
                logid_,
                this->thresholds_[this->current_threshold_],
                percent,
                severity);
            }
          else
            {
              if (TAO_debug_level > 0)
                ORBSVCS_DEBUG ((LM_DEBUG,
                            "threshold of %d breached\n",
                            this->thresholds_[this->current_threshold_]));
            }

          ++this->current_threshold_;
        }

      // "When a log object is created with the wrap option, the
      // capacity threshold alarms are triggered as if coupled to a
      // gauge that counts from zero to the highest capacity threshold
      // value defined and then resets to zero."
      if (log_full_action == DsLogAdmin::wrap
          && this->current_threshold_ == this->thresholds_.length ())
        {
          this->recordstore_->reset_gauge ();
          this->current_threshold_ = 0;
        }
    }
}
Ejemplo n.º 4
0
void
ACE_Throughput_Stats::dump_throughput (const ACE_TCHAR *msg,
                                       ACE_Basic_Stats::scale_factor_type sf,
                                       ACE_UINT64 elapsed_time,
                                       ACE_UINT32 samples_count)
{
#ifndef ACE_NLOGGING
  double seconds =
    static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (elapsed_time / sf));
  seconds /= ACE_HR_SCALE_CONVERSION;

  double t_avg = 0.0;
  if (seconds > 0.0)
    {
      t_avg = samples_count / seconds;
    }

  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%s throughput: %.2f (events/second)\n"),
              msg, t_avg));
#else
  ACE_UNUSED_ARG (msg);
  ACE_UNUSED_ARG (sf);
  ACE_UNUSED_ARG (elapsed_time);
  ACE_UNUSED_ARG (samples_count);
#endif /* ACE_NLOGGING */
}
Ejemplo n.º 5
0
double
to_seconds (ACE_UINT64 hrtime,
            ACE_High_Res_Timer::global_scale_factor_type sf)
{
  double seconds =
    static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER (hrtime / sf));
  seconds /= ACE_HR_SCALE_CONVERSION;

  return seconds;
}
Ejemplo n.º 6
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  ACE_LOG_MSG->open (argv[0] != 0  ?  argv[0] : ACE_TEXT("context_switch_time"));

  if (get_options (argc, argv))
    ACE_OS::exit (-1);

  // Disable LM_DEBUG.
  ACE_Log_Msg::instance ()->priority_mask (ACE_LOG_MSG->priority_mask () ^
                                           LM_DEBUG);

#if defined (ACE_HAS_PENTIUM)  &&  \
    !defined (ACE_HAS_HI_RES_TIMER)  &&  !defined (ACE_WIN32)
  // Just to verify that ACE_High_Res_Timer::global_scale_factor ()
  // correctly determines the clock speed.
  ACE_DEBUG ((LM_INFO, "clock speed: %u MHz\n",
              ACE_High_Res_Timer::global_scale_factor ()));
#endif /* ACE_HAS_PENTIUM && ! ACE_HAS_HI_RES_TIMER && ! ACE_WIN32 */

  if (ACE_OS::sched_params (
        ACE_Sched_Params (
          ACE_SCHED_FIFO,
          ACE_Sched_Params::priority_min (ACE_SCHED_FIFO),
          ACE_SCOPE_PROCESS)) != 0)
    {
      if (ACE_OS::last_error () == EPERM)
        {
          ACE_DEBUG ((LM_MAX, "context_switch_time: user is not superuser, "
                              "so remain in time-sharing class\n"));
        }
      else
        {
          ACE_OS::perror (ACE_TEXT("context_switch_time"));
          ACE_OS::exit (-1);
        }
    }

  HIGH_PRIORITY = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
                                                   LOW_PRIORITY);
  ACE_DEBUG ((LM_INFO, "low priority: %d, high priority: %d\n",
              LOW_PRIORITY, HIGH_PRIORITY));

  // Set the priority of this thread so that it's higher than any of
  // the test threads.  That might help avoid problems when waiting on
  // those threads, below.  It also seems to help the times
  // significantly on LynxOS.
  ACE_hthread_t self;
  ACE_OS::thr_self (self);
  ACE_OS::thr_setprio (ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
                                                        HIGH_PRIORITY));

  bool forever = counter == 0;

  ACE_Stats context_switch_test_stats;
  ACE_Stats yield_test_stats;
  ACE_Stats synchronized_suspend_resume_test_stats;

  int suspend_resume_supported = 0;
  // Check to see if thr_continue (), and therefore thr_suspend (),
  // probably, are supported.
  if (ACE_OS::thr_continue (self) == 0  ||  errno != ENOTSUP)
    suspend_resume_supported = 1;

 while (forever  ||  counter-- > 0)
    {
      if (suspend_resume_supported)
        {
          // Run suspend/resume test first . . .
          Suspend_Resume_Test suspend_resume_test (num_iterations);
          // Wait for all tasks to exit.
          ACE_Thread_Manager::instance ()->wait ();

          // Then Ping Suspend/Resume test.
          Ping_Suspend_Resume_Test ping_suspend_resume_test (num_iterations);
          // Wait for all tasks to exit.
          ACE_Thread_Manager::instance ()->wait ();

          if (ping_suspend_resume_test.elapsed_time () >
               suspend_resume_test.elapsed_time ())
            {
              context_switch_test_stats.
                sample (ACE_U64_TO_U32 (
                  ping_suspend_resume_test.elapsed_time () -
                  suspend_resume_test.elapsed_time ()));

              ACE_DEBUG ((LM_INFO, "context switch time is (%.3f - %.3f)/2 = "
                                   "%.3f microseconds\n",
                          (double) ACE_UINT64_DBLCAST_ADAPTER (
                            ping_suspend_resume_test.elapsed_time ()) /
                              num_iterations,
                          (double) ACE_UINT64_DBLCAST_ADAPTER (
                            suspend_resume_test.elapsed_time ()) /
                              num_iterations,
                          (double) ACE_UINT64_DBLCAST_ADAPTER (
                            ping_suspend_resume_test.elapsed_time () -
                            suspend_resume_test.elapsed_time ()) /
                              num_iterations / 2u));
            }
          else
            {
              ACE_DEBUG ((LM_INFO, "ping suspend/resume time of %u usec was "
                                   "less than suspend/resume time of %u\n",
                                   ping_suspend_resume_test.elapsed_time () /
                                      num_iterations,
                                   suspend_resume_test.elapsed_time () /
                                      num_iterations));
            }
        }

      // Then Yield test.
      Yield_Test yield_test (num_iterations);
      // Wait for all tasks to exit.
      ACE_Thread_Manager::instance ()->wait ();

      yield_test_stats.sample (ACE_U64_TO_U32 (yield_test.elapsed_time ()));

      // Try _really_ hard not to use floating point.
      ACE_DEBUG ((LM_INFO, "context switch time from yield test is %u.%03u "
                           "microseconds\n",
                  (ACE_UINT32)
                    (yield_test.elapsed_time () / num_iterations / 2u),
                  (ACE_UINT32)
                    (yield_test.elapsed_time () % (num_iterations * 2u)) *
                      1000u / num_iterations / 2u));

      Synchronized_Suspend_Resume_Test
        synchronized_suspend_resume_test (num_iterations);
      // Wait for all tasks to exit.
      ACE_Thread_Manager::instance ()->wait ();

      synchronized_suspend_resume_test_stats.sample (
        synchronized_suspend_resume_test.average_context_switch_time ());

      ACE_DEBUG ((LM_INFO, "context switch time from synch susp/resume test "
                           "is %u.%03u microseconds\n",
                  synchronized_suspend_resume_test.
                    average_context_switch_time () / 1000u,
                  synchronized_suspend_resume_test.
                    average_context_switch_time () % 1000u));

      // Give, e.g., Draft 4 Posix platforms a chance to cleanup threads.
      const ACE_Time_Value half_sec (0L, 500000L);
      ACE_OS::sleep (half_sec);
    }

  if (suspend_resume_supported)
    {
      ACE_OS::printf ("suspend-resume test: ");
      context_switch_test_stats.print_summary (3, num_iterations * 2u);
    }

  ACE_OS::printf ("\nyield_test: ");
  yield_test_stats.print_summary (3, num_iterations * 2u);

  ACE_OS::printf ("\nsynchronized suspend-resume test: ");
  synchronized_suspend_resume_test_stats.print_summary (3,
                                                        1000u /* nsec/usec */);

  return 0;
}
Ejemplo n.º 7
0
// conduct the UnMarshalled Octet performance test using separate
// send_n calls with Nagle's algorithm disabled
ACE_SCTP::HIST runUnmarshalledOctetTest(ACE_CDR::Octet *buf, size_t seqLen, ACE_SOCK_Stream & stream){

  ACE_CDR::ULong const testIterations = Options_Manager::test_iterations;

  size_t bt;
  ACE_CDR::ULong cnt = 0;
  // variables for the timing measurements
  ACE_hrtime_t startTime, endTime;
  ACE_CDR::Double messageLatency_usec = 0.0;
  ACE_CDR::ULong msgLen = seqLen*ACE_CDR::OCTET_SIZE;

  // explicity configure Nagling. Default is
  // Options_Manager::test_enable_nagle=0 so default configurations is
  // NO NAGLING
  ACE_CDR::Long nagle;
  if (Options_Manager::test_enable_nagle)
    nagle=0;
  else
    nagle=1;
  if (Options_Manager::test_transport_protocol == IPPROTO_SCTP){
    // default - sctp case
    if (-1 == stream.set_option(IPPROTO_SCTP, SCTP_NODELAY, &nagle, sizeof nagle))
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "set_option"),
                        0);
  } else {
    // tcp case
    if (-1 == stream.set_option(IPPROTO_TCP, TCP_NODELAY, &nagle, sizeof nagle))
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "set_option"),
                        0);
  }

  // prime the client and server before starting the test
  for(cnt=0;cnt<primerIterations;++cnt){

    // send message size
    // TODO : The message length should be CDR encoded
    ACE_CDR::ULong msgLenExpressed = ACE_HTONL(msgLen);
    if (-1 == stream.send_n (&msgLenExpressed, ACE_CDR::LONG_SIZE, 0, &bt))
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "send_n"),
                        0);

    // send a message
    if (-1 == stream.send_n (buf, msgLen, 0, &bt))
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "send_n"),
                        0);

    // block for a Short reply
    ACE_CDR::Short reply;
    if ((stream.recv_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1)
      ACE_ERROR_RETURN((LM_ERROR,
                        "%p\n",
                        "recv_n"),
                       0);
  }

  // AFTER PRIMING THE PUMP CREATE THE HISTOGRAM
  ACE_SCTP::HIST aceStream_hist = 0;
  aceStream_hist = createHistogram(msgLen);
  if (0 == aceStream_hist)
    ACE_ERROR_RETURN((LM_ERROR,
                      "%p\n",
                      "histogram create failed"),
                     0);

  iovec iov[2];
  // PERFORMANCE TEST LOOP
  for (cnt = 0; cnt < testIterations; ++cnt){

    // get the start time
    startTime = ACE_OS::gethrtime();
    if (!startTime)
      ACE_ERROR_RETURN((LM_ERROR,
                        "%p\n",
                        "ACE_OS::gethrtime()"),
                       0);


    ACE_CDR::ULong msgLenExpressed = ACE_HTONL(msgLen);
    iov[0].iov_base = reinterpret_cast<char *> (&msgLenExpressed);
    iov[0].iov_len = ACE_CDR::LONG_SIZE;
    iov[1].iov_base = reinterpret_cast<char *> (buf);
    iov[1].iov_len = msgLen;

    if (-1 == stream.sendv_n (iov, 2))
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "send_n"),
                        0);

    // block for a Short reply
    ACE_CDR::Short reply;
    if ((stream.recv_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1)
      ACE_ERROR_RETURN((LM_ERROR,
                        "%p\n",
                        "recv_n"),
                       0);

    // get the end time
    endTime = ACE_OS::gethrtime();
    if (!endTime)
      ACE_ERROR_RETURN((LM_ERROR,
                        "%p\n",
                        "ACE_OS::gethrtime()"),
                       0);

    // compute the message latency in micro-seconds
    messageLatency_usec =

      (static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER(endTime)) -
       static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER(startTime)))

      / microsec_clock_scale_factor;

    // record the message latency in the histogram
    ACE_SCTP::record(messageLatency_usec, aceStream_hist);
  }

  // THE HEADER MESSAGE SENT TO THE SERVER CONTAINED THE NUMBER OF
  // PRIMER AND TEST MESSAGES TO BE SENT AFTER WHICH THE SERVER WILL
  // CLOSE THE STREAM SO ONCE WE REACH THIS POINT THE STREAM IS NO
  // LONGER VALID AND WE CLOSE IT.
  stream.close();

  // allocated by runTest
  delete[] buf;
  return aceStream_hist;
}
Ejemplo n.º 8
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int result = parse_args (argc, argv);

  if (result != 0)
    {
      return result;
    }

  Synchronisers synch_forms;

  ACE_High_Res_Timer::calibrate ();

  // Leader Followers.
  Leader_Follower_Task **leader_followers = 0;
  ACE_NEW_RETURN (leader_followers,
                  Leader_Follower_Task *[number_of_threads],
                  -1);

  int priority =
    ACE_Sched_Params::priority_max (ACE_SCHED_FIFO);

  long flags = THR_SCOPE_PROCESS;

  // Number of messages left = Number_Of_messages
  number_of_messages_left = number_of_messages;

  size_t i = 0;
  // Create and activate them.
  for (i = 0; i < number_of_threads; ++i)
    {
      ACE_NEW_RETURN (leader_followers[i],
                      Leader_Follower_Task (synch_forms),
                      -1);

      // Activate the leader_followers.
      result = leader_followers[i]->activate (flags,
                                              1,
                                              1,
                                              priority);
      if (result != 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "(%P|%t) - Activate failed  for RT class "
                      " - Using default priority for thread [%d]\n",
                      i));

          flags = THR_BOUND;
          priority = ACE_Sched_Params::priority_min (ACE_SCHED_OTHER,
                                                     ACE_SCOPE_THREAD);

          // Activate the leader_followers.
          result = leader_followers[i]->activate (flags,
                                                  1,
                                                  1,
                                                  priority);

          if (result != 0)
            {
              ACE_DEBUG ((LM_DEBUG,
                          "(%P|%t) - Failed again no hope\n"));

              return 0;
            }

        }
    }

  // Wait for all threads to terminate.
  result = ACE_Thread_Manager::instance ()->wait ();

  ACE_hrtime_t elapsed_time = 0;

  test_timer.elapsed_time (elapsed_time);

  double elapsed_time_per_invocation =
    static_cast<double> (
        ACE_UINT64_DBLCAST_ADAPTER (elapsed_time / number_of_messages)
      );

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Throughput is [%f]\n",
              1000000000/ elapsed_time_per_invocation));


  for (i = 0; i < number_of_threads; ++i)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Message consumed in thread [%d] is [%d]\n",
                  i, leader_followers[i]->processed ()));
      delete leader_followers[i];
    }

  delete[] leader_followers;

  return result;
}