Commit 15c9b35a authored by Pavlo Kushnir's avatar Pavlo Kushnir Committed by Facebook Github Bot 1

Cheaper bumpHandlingTime

Summary: no need in virtual call from EventHandler.

Reviewed By: yfeldblum

Differential Revision: D3226960

fb-gh-sync-id: eb9c191630e1a1ac022666201100e3778eb7b611
fbshipit-source-id: eb9c191630e1a1ac022666201100e3778eb7b611
parent 4aa901d0
...@@ -150,7 +150,7 @@ void AsyncTimeout::libeventCallback(int fd, short events, void* arg) { ...@@ -150,7 +150,7 @@ void AsyncTimeout::libeventCallback(int fd, short events, void* arg) {
assert((event_ref_flags(&timeout->event_) & ~EVLIST_INTERNAL) == EVLIST_INIT); assert((event_ref_flags(&timeout->event_) & ~EVLIST_INTERNAL) == EVLIST_INIT);
// this can't possibly fire if timeout->eventBase_ is nullptr // this can't possibly fire if timeout->eventBase_ is nullptr
(void) timeout->timeoutManager_->bumpHandlingTime(); timeout->timeoutManager_->bumpHandlingTime();
auto old_ctx = auto old_ctx =
RequestContext::setContext(timeout->context_); RequestContext::setContext(timeout->context_);
......
...@@ -380,9 +380,7 @@ bool EventBase::loopBody(int flags) { ...@@ -380,9 +380,7 @@ bool EventBase::loopBody(int flags) {
idleStart = std::chrono::duration_cast<std::chrono::microseconds>( idleStart = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count(); std::chrono::steady_clock::now().time_since_epoch()).count();
} else { } else {
VLOG(11) << "EventBase " << this << " did not timeout " VLOG(11) << "EventBase " << this << " did not timeout";
" time measurement is disabled "
" nothingHandledYet(): "<< nothingHandledYet();
} }
// If the event loop indicate that there were no more events, and // If the event loop indicate that there were no more events, and
...@@ -445,22 +443,23 @@ void EventBase::loopForever() { ...@@ -445,22 +443,23 @@ void EventBase::loopForever() {
} }
} }
bool EventBase::bumpHandlingTime() { void EventBase::bumpHandlingTime() {
if (!enableTimeMeasurement_) {
return;
}
VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ << VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ <<
" (loop) latest " << latestLoopCnt_ << " next " << nextLoopCnt_; " (loop) latest " << latestLoopCnt_ << " next " << nextLoopCnt_;
if(nothingHandledYet()) { if (nothingHandledYet()) {
latestLoopCnt_ = nextLoopCnt_; latestLoopCnt_ = nextLoopCnt_;
if (enableTimeMeasurement_) { // set the time
// set the time startWork_ = std::chrono::duration_cast<std::chrono::microseconds>(
startWork_ = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now().time_since_epoch())
std::chrono::steady_clock::now().time_since_epoch()).count(); .count();
VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ << VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__
" (loop) startWork_ " << startWork_; << " (loop) startWork_ " << startWork_;
}
return true;
} }
return false;
} }
void EventBase::terminateLoopSoon() { void EventBase::terminateLoopSoon() {
...@@ -706,7 +705,7 @@ void EventBase::SmoothLoopTime::addSample(int64_t idle, int64_t busy) { ...@@ -706,7 +705,7 @@ void EventBase::SmoothLoopTime::addSample(int64_t idle, int64_t busy) {
value_ += (1.0 - coeff) * busy; value_ += (1.0 - coeff) * busy;
} }
bool EventBase::nothingHandledYet() { bool EventBase::nothingHandledYet() const noexcept {
VLOG(11) << "latest " << latestLoopCnt_ << " next " << nextLoopCnt_; VLOG(11) << "latest " << latestLoopCnt_ << " next " << nextLoopCnt_;
return (nextLoopCnt_ != latestLoopCnt_); return (nextLoopCnt_ != latestLoopCnt_);
} }
......
...@@ -508,7 +508,7 @@ class EventBase : private boost::noncopyable, ...@@ -508,7 +508,7 @@ class EventBase : private boost::noncopyable,
* first handler fired within that cycle. * first handler fired within that cycle.
* *
*/ */
bool bumpHandlingTime() override; void bumpHandlingTime() override final;
class SmoothLoopTime { class SmoothLoopTime {
public: public:
...@@ -598,7 +598,7 @@ class EventBase : private boost::noncopyable, ...@@ -598,7 +598,7 @@ class EventBase : private boost::noncopyable,
void cancelTimeout(AsyncTimeout* obj) override; void cancelTimeout(AsyncTimeout* obj) override;
bool isInTimeoutManagerThread() override { bool isInTimeoutManagerThread() override final {
return isInEventBaseThread(); return isInEventBaseThread();
} }
...@@ -606,7 +606,7 @@ class EventBase : private boost::noncopyable, ...@@ -606,7 +606,7 @@ class EventBase : private boost::noncopyable,
* Helper function that tells us whether we have already handled * Helper function that tells us whether we have already handled
* some event/timeout/callback in this loop iteration. * some event/timeout/callback in this loop iteration.
*/ */
bool nothingHandledYet(); bool nothingHandledYet() const noexcept;
// small object used as a callback arg with enough info to execute the // small object used as a callback arg with enough info to execute the
// appropriate client-provided Cob // appropriate client-provided Cob
......
...@@ -155,7 +155,7 @@ void EventHandler::libeventCallback(int fd, short events, void* arg) { ...@@ -155,7 +155,7 @@ void EventHandler::libeventCallback(int fd, short events, void* arg) {
} }
// this can't possibly fire if handler->eventBase_ is nullptr // this can't possibly fire if handler->eventBase_ is nullptr
(void) handler->eventBase_->bumpHandlingTime(); handler->eventBase_->bumpHandlingTime();
handler->handlerReady(events); handler->handlerReady(events);
......
...@@ -65,7 +65,7 @@ class TimeoutManager { ...@@ -65,7 +65,7 @@ class TimeoutManager {
* This is used to mark the beginning of a new loop cycle by the * This is used to mark the beginning of a new loop cycle by the
* first handler fired within that cycle. * first handler fired within that cycle.
*/ */
virtual bool bumpHandlingTime() = 0; virtual void bumpHandlingTime() = 0;
/** /**
* Helper method to know whether we are running in the timeout manager * Helper method to know whether we are running in the timeout manager
......
...@@ -37,7 +37,7 @@ class MockTimeoutManager : public folly::TimeoutManager { ...@@ -37,7 +37,7 @@ class MockTimeoutManager : public folly::TimeoutManager {
MOCK_METHOD1(cancelTimeout, void(folly::AsyncTimeout*)); MOCK_METHOD1(cancelTimeout, void(folly::AsyncTimeout*));
MOCK_METHOD0(bumpHandlingTime, bool()); MOCK_METHOD0(bumpHandlingTime, void());
MOCK_METHOD0(isInTimeoutManagerThread, bool()); MOCK_METHOD0(isInTimeoutManagerThread, bool());
}; };
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment