Implement workqueue statistics.

Refs #5235
This commit is contained in:
Gunnar Beutner 2013-11-28 12:12:24 +01:00
parent 85fec966b8
commit f9c53ad295
2 changed files with 11 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#include "base/utility.h" #include "base/utility.h"
#include "base/debug.h" #include "base/debug.h"
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include "base/convert.h"
#include <boost/bind.hpp> #include <boost/bind.hpp>
using namespace icinga; using namespace icinga;
@ -29,7 +30,8 @@ int WorkQueue::m_NextID = 1;
WorkQueue::WorkQueue(size_t maxItems) WorkQueue::WorkQueue(size_t maxItems)
: m_ID(m_NextID++), m_MaxItems(maxItems), m_Joined(false), : m_ID(m_NextID++), m_MaxItems(maxItems), m_Joined(false),
m_Stopped(false), m_ExceptionCallback(WorkQueue::DefaultExceptionCallback) m_Stopped(false), m_ExceptionCallback(WorkQueue::DefaultExceptionCallback),
m_LastStatus(0)
{ {
m_Thread = boost::thread(boost::bind(&WorkQueue::WorkerThreadProc, this)); m_Thread = boost::thread(boost::bind(&WorkQueue::WorkerThreadProc, this));
} }
@ -109,6 +111,13 @@ void WorkQueue::ProcessItems(boost::mutex::scoped_lock& lock, bool interleaved)
m_Items.pop_front(); m_Items.pop_front();
m_CV.notify_all(); m_CV.notify_all();
double now = Utility::GetTime();
if (m_LastStatus + 10 < now) {
Log(LogInformation, "base", "WQ items: " + Convert::ToString(m_Items.size()));
m_LastStatus = now;
}
lock.unlock(); lock.unlock();
wi.Callback(); wi.Callback();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {

View File

@ -72,6 +72,7 @@ private:
bool m_Stopped; bool m_Stopped;
std::deque<WorkItem> m_Items; std::deque<WorkItem> m_Items;
ExceptionCallback m_ExceptionCallback; ExceptionCallback m_ExceptionCallback;
double m_LastStatus;
void ProcessItems(boost::mutex::scoped_lock& lock, bool interleaved); void ProcessItems(boost::mutex::scoped_lock& lock, bool interleaved);
void WorkerThreadProc(void); void WorkerThreadProc(void);