Commit 82dd413a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Back out "EventBase::getRecentSteadyTime"

Summary:
Original commit changeset: 8eb472ce50bf

This breaks time measurement to include measuring the wait preceding handler/callback invocation.

Reviewed By: w-o-o

Differential Revision: D21986042

fbshipit-source-id: 42701b929878c3f56d736de5ca0417814c64fce1
parent aa825c5c
...@@ -215,8 +215,6 @@ EventBase::~EventBase() { ...@@ -215,8 +215,6 @@ EventBase::~EventBase() {
virtualEventBaseDestroyFuture.get(); virtualEventBaseDestroyFuture.get();
} }
bumpHandlingTime();
// Call all destruction callbacks, before we start cleaning up our state. // Call all destruction callbacks, before we start cleaning up our state.
while (!onDestructionCallbacks_.rlock()->empty()) { while (!onDestructionCallbacks_.rlock()->empty()) {
OnDestructionCallback::List callbacks; OnDestructionCallback::List callbacks;
...@@ -383,8 +381,6 @@ bool EventBase::loopBody(int flags, bool ignoreKeepAlive) { ...@@ -383,8 +381,6 @@ bool EventBase::loopBody(int flags, bool ignoreKeepAlive) {
} }
++nextLoopCnt_; ++nextLoopCnt_;
bumpHandlingTime();
// Run the before loop callbacks // Run the before loop callbacks
LoopCallbackList callbacks; LoopCallbackList callbacks;
callbacks.swap(runBeforeLoopCallbacks_); callbacks.swap(runBeforeLoopCallbacks_);
...@@ -406,12 +402,11 @@ bool EventBase::loopBody(int flags, bool ignoreKeepAlive) { ...@@ -406,12 +402,11 @@ bool EventBase::loopBody(int flags, bool ignoreKeepAlive) {
ranLoopCallbacks = runLoopCallbacks(); ranLoopCallbacks = runLoopCallbacks();
if (enableTimeMeasurement_) { if (enableTimeMeasurement_) {
assert(startWork_);
auto now = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now();
busy = std::chrono::duration_cast<std::chrono::microseconds>( busy = std::chrono::duration_cast<std::chrono::microseconds>(
now - *startWork_); now - startWork_);
idle = std::chrono::duration_cast<std::chrono::microseconds>( idle = std::chrono::duration_cast<std::chrono::microseconds>(
*startWork_ - idleStart); startWork_ - idleStart);
auto loop_time = busy + idle; auto loop_time = busy + idle;
avgLoopTime_.addSample(loop_time, busy); avgLoopTime_.addSample(loop_time, busy);
...@@ -561,7 +556,7 @@ void EventBase::bumpHandlingTime() { ...@@ -561,7 +556,7 @@ void EventBase::bumpHandlingTime() {
startWork_ = std::chrono::steady_clock::now(); startWork_ = std::chrono::steady_clock::now();
VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__
<< " (loop) startWork_ " << startWork_->time_since_epoch().count(); << " (loop) startWork_ " << startWork_.time_since_epoch().count();
} }
} }
...@@ -687,6 +682,7 @@ void EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) noexcept { ...@@ -687,6 +682,7 @@ void EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) noexcept {
} }
bool EventBase::runLoopCallbacks() { bool EventBase::runLoopCallbacks() {
bumpHandlingTime();
if (!loopCallbacks_.empty()) { if (!loopCallbacks_.empty()) {
// Swap the loopCallbacks_ list with a temporary list on our stack. // Swap the loopCallbacks_ list with a temporary list on our stack.
// This way we will only run callbacks scheduled at the time // This way we will only run callbacks scheduled at the time
......
...@@ -781,12 +781,6 @@ class EventBase : public TimeoutManager, ...@@ -781,12 +781,6 @@ class EventBase : public TimeoutManager,
loopOnce(); loopOnce();
} }
Optional<std::chrono::steady_clock::time_point> getRecentSteadyTime() const
noexcept {
dcheckIsInEventBaseThread();
return startWork_;
}
// Implements the ScheduledExecutor interface // Implements the ScheduledExecutor interface
void scheduleAt(Func&& fn, TimePoint const& timeout) override; void scheduleAt(Func&& fn, TimePoint const& timeout) override;
...@@ -914,7 +908,7 @@ class EventBase : public TimeoutManager, ...@@ -914,7 +908,7 @@ class EventBase : public TimeoutManager,
// Wrap-around loop counter to detect beginning of each loop // Wrap-around loop counter to detect beginning of each loop
std::size_t nextLoopCnt_; std::size_t nextLoopCnt_;
std::size_t latestLoopCnt_; std::size_t latestLoopCnt_;
Optional<std::chrono::steady_clock::time_point> startWork_; std::chrono::steady_clock::time_point startWork_;
// Prevent undefined behavior from invoking event_base_loop() reentrantly. // Prevent undefined behavior from invoking event_base_loop() reentrantly.
// This is needed since many projects use libevent-1.4, which lacks commit // This is needed since many projects use libevent-1.4, which lacks commit
// b557b175c00dc462c1fce25f6e7dd67121d2c001 from // b557b175c00dc462c1fce25f6e7dd67121d2c001 from
......
...@@ -2286,27 +2286,6 @@ TYPED_TEST_P(EventBaseTest1, RunOnDestructionAddCallbackWithinCallback) { ...@@ -2286,27 +2286,6 @@ TYPED_TEST_P(EventBaseTest1, RunOnDestructionAddCallbackWithinCallback) {
EXPECT_EQ(2, callbacksCalled); EXPECT_EQ(2, callbacksCalled);
} }
TYPED_TEST_P(EventBaseTest1, RecentSteadyTime) {
using namespace std::literals::chrono_literals;
using tp = std::chrono::steady_clock::time_point;
FOLLY_SKIP_IF_NULLPTR_BACKEND(evb);
tp a;
tp b;
tp c;
evb.runInEventBaseThread([&] {
a = evb.getRecentSteadyTime().value();
/* sleep override */ std::this_thread::sleep_for(10ms);
b = evb.getRecentSteadyTime().value();
});
evb.loop();
evb.runInEventBaseThread([&] { //
c = evb.getRecentSteadyTime().value();
});
evb.loop();
EXPECT_EQ(a, b);
EXPECT_LT(a, c);
}
REGISTER_TYPED_TEST_CASE_P( REGISTER_TYPED_TEST_CASE_P(
EventBaseTest, EventBaseTest,
ReadEvent, ReadEvent,
...@@ -2371,7 +2350,6 @@ REGISTER_TYPED_TEST_CASE_P( ...@@ -2371,7 +2350,6 @@ REGISTER_TYPED_TEST_CASE_P(
RunOnDestructionCancelled, RunOnDestructionCancelled,
RunOnDestructionAfterHandleDestroyed, RunOnDestructionAfterHandleDestroyed,
RunOnDestructionAddCallbackWithinCallback, RunOnDestructionAddCallbackWithinCallback,
InternalExternalCallbackOrderTest, InternalExternalCallbackOrderTest);
RecentSteadyTime);
} // namespace test } // namespace test
} // namespace folly } // namespace folly
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