Give observer manager threads a name
authorChristopher Dykes <cdykes@fb.com>
Mon, 20 Mar 2017 21:51:15 +0000 (14:51 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 20 Mar 2017 21:52:20 +0000 (14:52 -0700)
Summary: Re-landing D4618623 after it had to be reverted due to it's use of `FixedString`, which had broken GCC 4.8. `FixedString` should now be compiling correctly on GCC 4.8 so this should be fine now.

Reviewed By: yfeldblum

Differential Revision: D4727022

fbshipit-source-id: f85c6952fd82e6cd6042f8055ef54d9422f8b0f9

folly/experimental/observer/detail/ObserverManager.cpp

index f14b909..7654dff 100644 (file)
 #include <folly/experimental/observer/detail/ObserverManager.h>
 
 #include <folly/ExceptionString.h>
+#include <folly/Format.h>
 #include <folly/MPMCQueue.h>
+#include <folly/Range.h>
 #include <folly/Singleton.h>
+#include <folly/ThreadName.h>
 #include <folly/portability/GFlags.h>
 
 namespace folly {
@@ -32,6 +35,8 @@ DEFINE_int32(
     4,
     "How many internal threads ObserverManager should use");
 
+static constexpr StringPiece kObserverManagerThreadNamePrefix{"ObserverMngr"};
+
 namespace {
 constexpr size_t kCurrentQueueSize{10 * 1024};
 constexpr size_t kNextQueueSize{10 * 1024};
@@ -45,7 +50,9 @@ class ObserverManager::CurrentQueue {
       FLAGS_observer_manager_pool_size = 1;
     }
     for (int32_t i = 0; i < FLAGS_observer_manager_pool_size; ++i) {
-      threads_.emplace_back([&]() {
+      threads_.emplace_back([this, i]() {
+        folly::setThreadName(
+            folly::sformat("{}{}", kObserverManagerThreadNamePrefix, i));
         ObserverManager::inManagerThread_ = true;
 
         while (true) {