Commit b817015d authored by Amlan Nayak's avatar Amlan Nayak Committed by Facebook GitHub Bot

Add WorkersProvider interface to QueueObserver

Summary:
In order to colect backtraces from all threads consuming from a
task queue, we need the ability to expose their correpsonding thread IDs.
Here we introduce a new interface `WorkerProvider` which can be used to
collect the thread IDs. The implementations of this interface will come
later in the stack.

Reviewed By: mshneer

Differential Revision: D30101184

fbshipit-source-id: 24aaaeeba1983e3917c0224e94fc741b66a4f6a4
parent 3eb9e985
......@@ -17,17 +17,23 @@
#include <folly/executors/QueueObserver.h>
namespace {
std::unique_ptr<folly::QueueObserverFactory>
make_queue_observer_factory_fallback(const std::string&, size_t) noexcept {
make_queue_observer_factory_fallback(
const std::string&, size_t, folly::WorkerProvider*) noexcept {
return std::unique_ptr<folly::QueueObserverFactory>();
}
} // namespace
namespace folly {
/* static */ std::unique_ptr<QueueObserverFactory> QueueObserverFactory::make(
const std::string& context, size_t numPriorities) {
const std::string& context,
size_t numPriorities,
WorkerProvider* workerProvider) {
auto f = make_queue_observer_factory ? make_queue_observer_factory
: make_queue_observer_factory_fallback;
return f(context, numPriorities);
return f(context, numPriorities, workerProvider);
}
} // namespace folly
......@@ -19,6 +19,7 @@
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include <folly/Portability.h>
......@@ -26,6 +27,39 @@ namespace folly {
class RequestContext;
/**
* WorkerProvider is a simple interface that can be used
* to collect information about worker threads that are pulling work
* from a given queue.
*/
class WorkerProvider {
public:
virtual ~WorkerProvider() {}
/**
* Abstract type returned by the collectThreadIds() method.
* Implementations of the WorkerProvider interface need to define this class.
* The intent is to return a guard along with a list of worker IDs which can
* be removed on destruction of this object.
*/
class KeepAlive {
public:
virtual ~KeepAlive() = 0;
};
// collectThreadIds() will return this aggregate type which includes an
// instance of the WorkersGuard.
struct IdsWithKeepAlive {
std::unique_ptr<KeepAlive> guard;
std::vector<pid_t> threadIds;
};
// Capture the Thread IDs of all threads consuming from a given queue.
// The provided vector should be populated with the OS Thread IDs and the
// method should return a SharedMutex which the caller can lock.
virtual IdsWithKeepAlive collectThreadIds() = 0;
};
class QueueObserver {
public:
virtual ~QueueObserver() {}
......@@ -40,11 +74,13 @@ class QueueObserverFactory {
virtual std::unique_ptr<QueueObserver> create(int8_t pri) = 0;
static std::unique_ptr<QueueObserverFactory> make(
const std::string& context, size_t numPriorities);
const std::string& context,
size_t numPriorities,
WorkerProvider* workerProvider = nullptr);
};
using MakeQueueObserverFactory =
std::unique_ptr<QueueObserverFactory>(const std::string&, size_t);
using MakeQueueObserverFactory = std::unique_ptr<QueueObserverFactory>(
const std::string&, size_t, WorkerProvider*);
#if FOLLY_HAVE_WEAK_SYMBOLS
FOLLY_ATTR_WEAK MakeQueueObserverFactory make_queue_observer_factory;
#else
......
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