[icinga-checkins] icinga.org: icinga2/fix/api-sync-repl-11684: Add name attribute for the WorkQueue class

git at icinga.org git at icinga.org
Wed Jun 15 17:50:19 CEST 2016


Module: icinga2
Branch: fix/api-sync-repl-11684
Commit: ff57b0ccd66775a4e2b9f420523a6e6cf532d242
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=ff57b0ccd66775a4e2b9f420523a6e6cf532d242

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Jun 14 08:19:13 2016 +0200

Add name attribute for the WorkQueue class

fixes #10816

---

 lib/base/configobject.cpp               |    1 +
 lib/base/workqueue.cpp                  |   20 ++++++++++++++++++--
 lib/base/workqueue.hpp                  |    4 ++++
 lib/config/configitem.cpp               |    2 ++
 lib/db_ido_mysql/idomysqlconnection.cpp |    5 +++++
 lib/db_ido_mysql/idomysqlconnection.hpp |    1 +
 lib/db_ido_pgsql/idopgsqlconnection.cpp |    9 ++++++++-
 lib/db_ido_pgsql/idopgsqlconnection.hpp |    1 +
 lib/remote/apilistener.cpp              |    5 ++++-
 lib/remote/httpserverconnection.cpp     |    2 ++
 lib/remote/jsonrpcconnection.cpp        |    5 +++++
 11 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp
index 560e8a5..84071ac 100644
--- a/lib/base/configobject.cpp
+++ b/lib/base/configobject.cpp
@@ -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;
diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp
index 730c76b..9a74557 100644
--- a/lib/base/workqueue.cpp
+++ b/lib/base/workqueue.cpp
@@ -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)
diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp
index 320dfdc..8b466cc 100644
--- a/lib/base/workqueue.hpp
+++ b/lib/base/workqueue.hpp
@@ -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;
diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp
index d34e9dd..711585d 100644
--- a/lib/config/configitem.cpp
+++ b/lib/config/configitem.cpp
@@ -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))
diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp
index 78f259a..a1b3550 100644
--- a/lib/db_ido_mysql/idomysqlconnection.cpp
+++ b/lib/db_ido_mysql/idomysqlconnection.cpp
@@ -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();
diff --git a/lib/db_ido_mysql/idomysqlconnection.hpp b/lib/db_ido_mysql/idomysqlconnection.hpp
index 5823e33..fdc54c6 100644
--- a/lib/db_ido_mysql/idomysqlconnection.hpp
+++ b/lib/db_ido_mysql/idomysqlconnection.hpp
@@ -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;
 
diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp
index 6bd6f03..f5f22d7 100644
--- a/lib/db_ido_pgsql/idopgsqlconnection.cpp
+++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp
@@ -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)
 {
diff --git a/lib/db_ido_pgsql/idopgsqlconnection.hpp b/lib/db_ido_pgsql/idopgsqlconnection.hpp
index cdf789f..180d16f 100644
--- a/lib/db_ido_pgsql/idopgsqlconnection.hpp
+++ b/lib/db_ido_pgsql/idopgsqlconnection.hpp
@@ -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;
 
diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp
index 14d0cdb..b099ef2 100644
--- a/lib/remote/apilistener.cpp
+++ b/lib/remote/apilistener.cpp
@@ -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)
 {
diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp
index f4aa24f..be3dec1 100644
--- a/lib/remote/httpserverconnection.cpp
+++ b/lib/remote/httpserverconnection.cpp
@@ -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);
 }
diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp
index 81911c3..651ff0e 100644
--- a/lib/remote/jsonrpcconnection.cpp
+++ b/lib/remote/jsonrpcconnection.cpp
@@ -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)



More information about the icinga-checkins mailing list