EvictingCacheMap.h \
experimental/AutoTimer.h \
experimental/Bits.h \
+ experimental/ExecutionObserver.h \
experimental/EliasFanoCoding.h \
experimental/EventCount.h \
experimental/fibers/AddTasks.h \
experimental/fibers/BoostContextCompatibility.h \
experimental/fibers/EventBaseLoopController.h \
experimental/fibers/EventBaseLoopController-inl.h \
- experimental/fibers/ExecutionObserver.h \
experimental/fibers/Fiber.h \
experimental/fibers/Fiber-inl.h \
experimental/fibers/FiberManager.h \
--- /dev/null
+/*
+ * Copyright 2015 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <cstdint>
+
+namespace folly {
+
+/**
+ * Observes the execution of a task.
+ */
+class ExecutionObserver {
+ public:
+ virtual ~ExecutionObserver() { }
+
+ /**
+ * Called when a task is about to start executing.
+ *
+ * @param id Unique id for the task which is starting.
+ */
+ virtual void starting(uintptr_t id) noexcept = 0;
+
+ /**
+ * Called when a task is ready to run.
+ *
+ * @param id Unique id for the task which is ready to run.
+ */
+ virtual void runnable(uintptr_t id) noexcept = 0;
+
+ /**
+ * Called just after a task stops executing.
+ *
+ * @param id Unique id for the task which stopped.
+ */
+ virtual void stopped(uintptr_t id) noexcept = 0;
+};
+
+} // namespace folly
+++ /dev/null
-/*
- * Copyright 2015 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <cstdint>
-
-namespace folly { namespace fibers {
-
-/**
- * Observes the execution of a task.
- */
-class ExecutionObserver {
- public:
- virtual ~ExecutionObserver() { }
-
- /**
- * Called when a task is about to start executing.
- *
- * @param id Unique id for the fiber which is starting.
- */
- virtual void starting(uintptr_t id) noexcept = 0;
-
- /**
- * Called when a task is ready to run.
- *
- * @param id Unique id for the fiber which is ready to run.
- */
- virtual void runnable(uintptr_t id) noexcept = 0;
-
- /**
- * Called just after a task stops executing.
- *
- * @param id Unique id for the fiber which is stopping.
- */
- virtual void stopped(uintptr_t id) noexcept = 0;
-};
-
-}} // namespace folly::fibers
#include <folly/IntrusiveList.h>
#include <folly/futures/Try.h>
+#include <folly/experimental/ExecutionObserver.h>
#include <folly/experimental/fibers/BoostContextCompatibility.h>
-#include <folly/experimental/fibers/ExecutionObserver.h>
#include <folly/experimental/fibers/Fiber.h>
#include <folly/experimental/fibers/traits.h>
, latestLoopCnt_(nextLoopCnt_)
, startWork_(0)
, observer_(nullptr)
- , observerSampleCount_(0) {
+ , observerSampleCount_(0)
+ , executionObserver_(nullptr) {
{
std::lock_guard<std::mutex> lock(libevent_mutex_);
, latestLoopCnt_(nextLoopCnt_)
, startWork_(0)
, observer_(nullptr)
- , observerSampleCount_(0) {
+ , observerSampleCount_(0)
+ , executionObserver_(nullptr) {
if (UNLIKELY(evb_ == nullptr)) {
LOG(ERROR) << "EventBase(): Pass nullptr as event base.";
throw std::invalid_argument("EventBase(): event base cannot be nullptr");
#include <folly/io/async/TimeoutManager.h>
#include <folly/io/async/Request.h>
#include <folly/Executor.h>
+#include <folly/experimental/ExecutionObserver.h>
#include <folly/futures/DrivableExecutor.h>
#include <memory>
#include <stack>
return observer_;
}
+ /**
+ * Setup execution observation/instrumentation for every EventHandler
+ * executed in this EventBase.
+ *
+ * @param executionObserver EventHandle's execution observer.
+ */
+ void setExecutionObserver(ExecutionObserver* observer) {
+ executionObserver_ = observer;
+ }
+
+ /**
+ * Gets the execution observer associated with this EventBase.
+ */
+ ExecutionObserver* getExecutionObserver() {
+ return executionObserver_;
+ }
+
/**
* Set the name of the thread that runs this event base.
*/
std::shared_ptr<EventBaseObserver> observer_;
uint32_t observerSampleCount_;
+ // EventHandler's execution observer.
+ ExecutionObserver* executionObserver_;
+
// Name of the thread running this EventBase
std::string name_;
};
EventHandler* handler = reinterpret_cast<EventHandler*>(arg);
assert(fd == handler->event_.ev_fd);
+ auto observer = handler->eventBase_->getExecutionObserver();
+ if (observer) {
+ observer->starting(reinterpret_cast<uintptr_t>(handler));
+ }
+
// this can't possibly fire if handler->eventBase_ is nullptr
(void) handler->eventBase_->bumpHandlingTime();
handler->handlerReady(events);
+
+ if (observer) {
+ observer->stopped(reinterpret_cast<uintptr_t>(handler));
+ }
}
void EventHandler::setEventBase(EventBase* eventBase) {