proxygen
folly::EventBase::SmoothLoopTime Class Reference

#include <EventBase.h>

Public Member Functions

 SmoothLoopTime (std::chrono::microseconds timeInterval)
 
void setTimeInterval (std::chrono::microseconds timeInterval)
 
void reset (double value=0.0)
 
void addSample (std::chrono::microseconds total, std::chrono::microseconds busy)
 
double get () const
 
void dampen (double factor)
 

Private Attributes

double expCoeff_
 
double value_
 
std::chrono::microseconds buffer_time_ {0}
 
std::chrono::microseconds busy_buffer_ {0}
 
std::size_t buffer_cnt_ {0}
 

Static Private Attributes

static constexpr std::chrono::milliseconds buffer_interval_ {10}
 

Detailed Description

Definition at line 553 of file EventBase.h.

Constructor & Destructor Documentation

folly::EventBase::SmoothLoopTime::SmoothLoopTime ( std::chrono::microseconds  timeInterval)
inlineexplicit

Definition at line 555 of file EventBase.h.

References folly::value().

556  : expCoeff_(-1.0 / timeInterval.count()), value_(0.0) {
557  VLOG(11) << "expCoeff_ " << expCoeff_ << " " << __PRETTY_FUNCTION__;
558  }

Member Function Documentation

void folly::EventBase::SmoothLoopTime::addSample ( std::chrono::microseconds  total,
std::chrono::microseconds  busy 
)

Definition at line 671 of file EventBase.cpp.

Referenced by folly::EventBase::loopBody().

673  {
674  if ((buffer_time_ + total) > buffer_interval_ && buffer_cnt_ > 0) {
675  // See https://en.wikipedia.org/wiki/Exponential_smoothing for
676  // more info on this calculation.
677  double coeff = exp(buffer_time_.count() * expCoeff_);
678  value_ =
679  value_ * coeff + (1.0 - coeff) * (busy_buffer_.count() / buffer_cnt_);
680  buffer_time_ = std::chrono::microseconds{0};
681  busy_buffer_ = std::chrono::microseconds{0};
682  buffer_cnt_ = 0;
683  }
684  buffer_time_ += total;
685  busy_buffer_ += busy;
686  buffer_cnt_++;
687 }
static constexpr std::chrono::milliseconds buffer_interval_
Definition: EventBase.h:584
std::chrono::microseconds buffer_time_
Definition: EventBase.h:581
std::chrono::microseconds busy_buffer_
Definition: EventBase.h:582
void folly::EventBase::SmoothLoopTime::dampen ( double  factor)
inline

Definition at line 574 of file EventBase.h.

Referenced by folly::EventBase::loopBody().

574  {
575  value_ *= factor;
576  }
double folly::EventBase::SmoothLoopTime::get ( ) const
inline

Definition at line 567 of file EventBase.h.

Referenced by folly::EventBase::loopBody().

567  {
568  // Add the outstanding buffered times linearly, to avoid
569  // expensive exponentiation
570  auto lcoeff = buffer_time_.count() * -expCoeff_;
571  return value_ * (1.0 - lcoeff) + lcoeff * busy_buffer_.count();
572  }
std::chrono::microseconds buffer_time_
Definition: EventBase.h:581
std::chrono::microseconds busy_buffer_
Definition: EventBase.h:582
void folly::EventBase::SmoothLoopTime::reset ( double  value = 0.0)

Definition at line 667 of file EventBase.cpp.

References folly::value().

Referenced by folly::EventBase::resetLoadAvg().

667  {
668  value_ = value;
669 }
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
void folly::EventBase::SmoothLoopTime::setTimeInterval ( std::chrono::microseconds  timeInterval)

Definition at line 661 of file EventBase.cpp.

Referenced by folly::EventBase::setLoadAvgMsec().

662  {
663  expCoeff_ = -1.0 / timeInterval.count();
664  VLOG(11) << "expCoeff_ " << expCoeff_ << " " << __PRETTY_FUNCTION__;
665 }

Member Data Documentation

std::size_t folly::EventBase::SmoothLoopTime::buffer_cnt_ {0}
private

Definition at line 583 of file EventBase.h.

constexpr std::chrono::milliseconds folly::EventBase::SmoothLoopTime::buffer_interval_ {10}
staticprivate

Definition at line 584 of file EventBase.h.

Referenced by folly::EventBase::getEventBase().

std::chrono::microseconds folly::EventBase::SmoothLoopTime::buffer_time_ {0}
private

Definition at line 581 of file EventBase.h.

std::chrono::microseconds folly::EventBase::SmoothLoopTime::busy_buffer_ {0}
private

Definition at line 582 of file EventBase.h.

double folly::EventBase::SmoothLoopTime::expCoeff_
private

Definition at line 579 of file EventBase.h.

double folly::EventBase::SmoothLoopTime::value_
private

Definition at line 580 of file EventBase.h.


The documentation for this class was generated from the following files: