]> granicus.if.org Git - icinga2/commitdiff
Add name attribute for the WorkQueue class
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 14 Jun 2016 06:19:13 +0000 (08:19 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 14 Jun 2016 07:08:04 +0000 (09:08 +0200)
fixes #10816

lib/base/configobject.cpp
lib/base/workqueue.cpp
lib/base/workqueue.hpp
lib/config/configitem.cpp
lib/db_ido_mysql/idomysqlconnection.cpp
lib/db_ido_mysql/idomysqlconnection.hpp
lib/db_ido_pgsql/idopgsqlconnection.cpp
lib/db_ido_pgsql/idopgsqlconnection.hpp
lib/remote/apilistener.cpp
lib/remote/httpserverconnection.cpp
lib/remote/jsonrpcconnection.cpp

index 560e8a58a0715b8755c1ff6a22ed5f5174c9b895..84071acd58dc52180d42b9406c66697ef98dc481 100644 (file)
@@ -574,6 +574,7 @@ void ConfigObject::RestoreObjects(const String& filename, int attributeTypes)
        unsigned long restored = 0;
 
        WorkQueue upq(25000, Application::GetConcurrency());
+       upq.SetName("ConfigObject::RestoreObjects");
 
        String message;
        StreamReadContext src;
index 730c76bd0f631d03a31236f71be5dd7584db3baf..9a74557c1df3b26975b38b5ac8df2df49b66268a 100644 (file)
@@ -49,6 +49,16 @@ WorkQueue::~WorkQueue(void)
        Join(true);
 }
 
+void WorkQueue::SetName(const String& name)
+{
+       m_Name = name;
+}
+
+String WorkQueue::GetName(void) const
+{
+       return m_Name;
+}
+
 /**
  * Enqueues a task. Tasks are guaranteed to be executed in the order
  * they were enqueued in except if there is more than one worker thread or when
@@ -177,8 +187,14 @@ void WorkQueue::StatusTimerHandler(void)
 {
        boost::mutex::scoped_lock lock(m_Mutex);
 
-       Log(LogNotice, "WorkQueue")
-           << "#" << m_ID << " tasks: " << m_Tasks.size();
+       Log log(LogNotice, "WorkQueue");
+
+       log << "#" << m_ID;
+
+       if (!m_Name.IsEmpty())
+               log << " (" << m_Name << ")";
+
+       log << " tasks: " << m_Tasks.size();
 }
 
 void WorkQueue::WorkerThreadProc(void)
index 320dfdc7bad64b2ec6d858e15e3d2cb78ef95296..8b466cc70f4daa10c2512bd792ef4125dae1de98 100644 (file)
@@ -83,6 +83,9 @@ public:
        WorkQueue(size_t maxItems = 0, int threadCount = 1);
        ~WorkQueue(void);
 
+       void SetName(const String& name);
+       String GetName(void) const;
+
        void Enqueue(const boost::function<void (void)>& function, WorkQueuePriority priority = PriorityNormal,
            bool allowInterleaved = false);
        void Join(bool stop = false);
@@ -99,6 +102,7 @@ public:
 
 private:
        int m_ID;
+       String m_Name;
        static int m_NextID;
        int m_ThreadCount;
        bool m_Spawned;
index d34e9ddc80492c4f889ab43323ef619535be19c8..711585d34fa04af602e1f995928678a3ecfc14b5 100644 (file)
@@ -625,6 +625,8 @@ bool ConfigItem::RunWithActivationContext(const Function::Ptr& function)
        }
 
        WorkQueue upq(25000, Application::GetConcurrency());
+       upq.SetName("ConfigItem::RunWithActivationContext");
+
        std::vector<ConfigItem::Ptr> newItems;
 
        if (!CommitItems(scope.GetContext(), upq, newItems))
index 78f259a15ce5fca57f2dacfafe1fed7ff48a56f2..a1b3550dad73d8ff7e27d0f8fdf02804a046ee34 100644 (file)
@@ -42,6 +42,11 @@ IdoMysqlConnection::IdoMysqlConnection(void)
        : m_QueryQueue(1000000)
 { }
 
+void IdoMysqlConnection::OnConfigLoaded(void)
+{
+       m_QueryQueue.SetName("IdoMysqlConnection, " + GetName());
+}
+
 void IdoMysqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
        Dictionary::Ptr nodes = new Dictionary();
index 5823e33e3b956d0311156155a6cdbdaff2a3c6c9..fdc54c6609731a4417cdc9c403584c12ccd7f5dc 100644 (file)
@@ -57,6 +57,7 @@ public:
        virtual int GetPendingQueryCount(void) const override;
 
 protected:
+       virtual void OnConfigLoaded(void) override;
        virtual void Resume(void) override;
        virtual void Pause(void) override;
 
index 6bd6f0332d3025c31e956bb8dff3a3ba966ae36c..f5f22d7e067d438f9813c75bd5bbd62e60219a72 100644 (file)
@@ -42,7 +42,14 @@ REGISTER_STATSFUNCTION(IdoPgsqlConnection, &IdoPgsqlConnection::StatsFunc);
 
 IdoPgsqlConnection::IdoPgsqlConnection(void)
        : m_QueryQueue(1000000)
-{ }
+{
+       m_QueryQueue.SetName("IdoPgsqlConnection, " + GetName());
+}
+
+void IdoPgsqlConnection::OnConfigLoaded(void)
+{
+       m_QueryQueue.SetName("IdoPgsqlConnection, " + GetName());
+}
 
 void IdoPgsqlConnection::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
 {
index cdf789ff75365b4fe6fba511dbdcfd79612d281e..180d16f301b4ee42b68d6961d167182c4439840c 100644 (file)
@@ -49,6 +49,7 @@ public:
        virtual int GetPendingQueryCount(void) const override;
 
 protected:
+       virtual void OnConfigLoaded(void) override;
        virtual void Resume(void) override;
        virtual void Pause(void) override;
 
index 14d0cdbc6b7f906e40504608d3272830344da6fc..b099ef21bdc12416a9f80ebd1493ef5c4202e672 100644 (file)
@@ -49,7 +49,10 @@ REGISTER_APIFUNCTION(Hello, icinga, &ApiListener::HelloAPIHandler);
 
 ApiListener::ApiListener(void)
        : m_SyncQueue(0, 4), m_LogMessageCount(0)
-{ }
+{
+       m_RelayQueue.SetName("ApiListener, RelayQueue");
+       m_SyncQueue.SetName("ApiListener, SyncQueue");
+}
 
 void ApiListener::OnConfigLoaded(void)
 {
index f4aa24f421197935cb1e004246513569b7f49206..be3dec15aafdd5cbc2f0cdc425a6e2654cc8b1e0 100644 (file)
@@ -41,6 +41,8 @@ HttpServerConnection::HttpServerConnection(const String& identity, bool authenti
 {
        boost::call_once(l_HttpServerConnectionOnceFlag, &HttpServerConnection::StaticInitialize);
 
+       m_RequestQueue.SetName("HttpServerConnection");
+
        if (authenticated)
                m_ApiUser = ApiUser::GetByClientCN(identity);
 }
index 81911c30064efc46b640dd6405e900415828e560..651ff0e009d3549524d628310b332ec9ff6527a6 100644 (file)
@@ -26,6 +26,7 @@
 #include "base/utility.hpp"
 #include "base/logger.hpp"
 #include "base/exception.hpp"
+#include "base/convert.hpp"
 #include <boost/thread/once.hpp>
 
 using namespace icinga;
@@ -62,6 +63,10 @@ void JsonRpcConnection::StaticInitialize(void)
 
        l_JsonRpcConnectionWorkQueueCount = Application::GetConcurrency();
        l_JsonRpcConnectionWorkQueues = new WorkQueue[l_JsonRpcConnectionWorkQueueCount];
+
+       for (int i = 0; i < l_JsonRpcConnectionWorkQueueCount; i++) {
+               l_JsonRpcConnectionWorkQueues[i].SetName("JsonRpcConnection, #" + Convert::ToString(i));
+       }
 }
 
 void JsonRpcConnection::Start(void)