From: Pavlo Kushnir Date: Wed, 27 Apr 2016 07:20:04 +0000 (-0700) Subject: Cheaper bumpHandlingTime X-Git-Tag: 2016.07.26~318 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=15c9b35a511157666c3be6a003f2ecaa22b131db;p=folly.git 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 --- diff --git a/folly/io/async/AsyncTimeout.cpp b/folly/io/async/AsyncTimeout.cpp index 50399767..6758aec7 100644 --- a/folly/io/async/AsyncTimeout.cpp +++ b/folly/io/async/AsyncTimeout.cpp @@ -150,7 +150,7 @@ void AsyncTimeout::libeventCallback(int fd, short events, void* arg) { assert((event_ref_flags(&timeout->event_) & ~EVLIST_INTERNAL) == EVLIST_INIT); // this can't possibly fire if timeout->eventBase_ is nullptr - (void) timeout->timeoutManager_->bumpHandlingTime(); + timeout->timeoutManager_->bumpHandlingTime(); auto old_ctx = RequestContext::setContext(timeout->context_); diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 7f2d9239..6f7e9a27 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -380,9 +380,7 @@ bool EventBase::loopBody(int flags) { idleStart = std::chrono::duration_cast( std::chrono::steady_clock::now().time_since_epoch()).count(); } else { - VLOG(11) << "EventBase " << this << " did not timeout " - " time measurement is disabled " - " nothingHandledYet(): "<< nothingHandledYet(); + VLOG(11) << "EventBase " << this << " did not timeout"; } // If the event loop indicate that there were no more events, and @@ -445,22 +443,23 @@ void EventBase::loopForever() { } } -bool EventBase::bumpHandlingTime() { +void EventBase::bumpHandlingTime() { + if (!enableTimeMeasurement_) { + return; + } + VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ << " (loop) latest " << latestLoopCnt_ << " next " << nextLoopCnt_; - if(nothingHandledYet()) { + if (nothingHandledYet()) { latestLoopCnt_ = nextLoopCnt_; - if (enableTimeMeasurement_) { - // set the time - startWork_ = std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()).count(); + // set the time + startWork_ = std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()) + .count(); - VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ << - " (loop) startWork_ " << startWork_; - } - return true; + VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ + << " (loop) startWork_ " << startWork_; } - return false; } void EventBase::terminateLoopSoon() { @@ -706,7 +705,7 @@ void EventBase::SmoothLoopTime::addSample(int64_t idle, int64_t busy) { value_ += (1.0 - coeff) * busy; } -bool EventBase::nothingHandledYet() { +bool EventBase::nothingHandledYet() const noexcept { VLOG(11) << "latest " << latestLoopCnt_ << " next " << nextLoopCnt_; return (nextLoopCnt_ != latestLoopCnt_); } diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index a7958d22..e678781e 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -508,7 +508,7 @@ class EventBase : private boost::noncopyable, * first handler fired within that cycle. * */ - bool bumpHandlingTime() override; + void bumpHandlingTime() override final; class SmoothLoopTime { public: @@ -598,7 +598,7 @@ class EventBase : private boost::noncopyable, void cancelTimeout(AsyncTimeout* obj) override; - bool isInTimeoutManagerThread() override { + bool isInTimeoutManagerThread() override final { return isInEventBaseThread(); } @@ -606,7 +606,7 @@ class EventBase : private boost::noncopyable, * Helper function that tells us whether we have already handled * 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 // appropriate client-provided Cob diff --git a/folly/io/async/EventHandler.cpp b/folly/io/async/EventHandler.cpp index 67d15889..a0ac4a8f 100644 --- a/folly/io/async/EventHandler.cpp +++ b/folly/io/async/EventHandler.cpp @@ -155,7 +155,7 @@ void EventHandler::libeventCallback(int fd, short events, void* arg) { } // this can't possibly fire if handler->eventBase_ is nullptr - (void) handler->eventBase_->bumpHandlingTime(); + handler->eventBase_->bumpHandlingTime(); handler->handlerReady(events); diff --git a/folly/io/async/TimeoutManager.h b/folly/io/async/TimeoutManager.h index e544674d..e7df72e9 100644 --- a/folly/io/async/TimeoutManager.h +++ b/folly/io/async/TimeoutManager.h @@ -65,7 +65,7 @@ class TimeoutManager { * This is used to mark the beginning of a new loop cycle by the * 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 diff --git a/folly/io/async/test/MockTimeoutManager.h b/folly/io/async/test/MockTimeoutManager.h index fe2e8e60..686aa3f7 100644 --- a/folly/io/async/test/MockTimeoutManager.h +++ b/folly/io/async/test/MockTimeoutManager.h @@ -37,7 +37,7 @@ class MockTimeoutManager : public folly::TimeoutManager { MOCK_METHOD1(cancelTimeout, void(folly::AsyncTimeout*)); - MOCK_METHOD0(bumpHandlingTime, bool()); + MOCK_METHOD0(bumpHandlingTime, void()); MOCK_METHOD0(isInTimeoutManagerThread, bool()); }; }