Add name attribute for the WorkQueue class

fixes #10816
This commit is contained in:
Gunnar Beutner 2016-06-14 08:19:13 +02:00
parent a8209c1a1a
commit ff57b0ccd6
11 changed files with 51 additions and 4 deletions

View 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;

View 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)

View 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;

View 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))

View 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();

View 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;

View 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)
{

View 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;

View 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)
{

View 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);
}

View 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)