mirror of https://github.com/Icinga/icinga2.git
Implement OS-specific support for thread names.
This commit is contained in:
parent
f3638877eb
commit
7f52e04a01
|
@ -66,6 +66,8 @@ void CheckerComponent::Stop(void)
|
||||||
|
|
||||||
void CheckerComponent::CheckThreadProc(void)
|
void CheckerComponent::CheckThreadProc(void)
|
||||||
{
|
{
|
||||||
|
Utility::SetThreadName("Check Scheduler");
|
||||||
|
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -157,6 +157,8 @@ void ClusterComponent::AddListener(const String& service)
|
||||||
|
|
||||||
void ClusterComponent::ListenerThreadProc(const Socket::Ptr& server)
|
void ClusterComponent::ListenerThreadProc(const Socket::Ptr& server)
|
||||||
{
|
{
|
||||||
|
Utility::SetThreadName("Cluster Listener");
|
||||||
|
|
||||||
server->Listen();
|
server->Listen();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -113,6 +113,8 @@ String CompatComponent::GetCommandPath(void) const
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
void CompatComponent::CommandPipeThread(const String& commandPath)
|
void CompatComponent::CommandPipeThread(const String& commandPath)
|
||||||
{
|
{
|
||||||
|
Utility::SetThreadName("Command Pipe");
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
bool fifo_ok = false;
|
bool fifo_ok = false;
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,8 @@ void Application::RunEventLoop(void) const
|
||||||
*/
|
*/
|
||||||
void Application::TimeWatchThreadProc(void)
|
void Application::TimeWatchThreadProc(void)
|
||||||
{
|
{
|
||||||
|
Utility::SetThreadName("Time Watch");
|
||||||
|
|
||||||
double lastLoop = Utility::GetTime();
|
double lastLoop = Utility::GetTime();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -30,8 +30,10 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
int ThreadPool::m_NextID = 1;
|
||||||
|
|
||||||
ThreadPool::ThreadPool(void)
|
ThreadPool::ThreadPool(void)
|
||||||
: m_WaitTime(0), m_ServiceTime(0),
|
: m_ID(m_NextID++), m_WaitTime(0), m_ServiceTime(0),
|
||||||
m_TaskCount(0), m_Stopped(false)
|
m_TaskCount(0), m_Stopped(false)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
|
@ -96,7 +98,7 @@ void ThreadPool::Join(void)
|
||||||
void ThreadPool::QueueThreadProc(int tid)
|
void ThreadPool::QueueThreadProc(int tid)
|
||||||
{
|
{
|
||||||
std::ostringstream idbuf;
|
std::ostringstream idbuf;
|
||||||
idbuf << "TP " << this << " Worker #" << tid;
|
idbuf << "TP #" << m_ID << " Worker #" << tid;
|
||||||
Utility::SetThreadName(idbuf.str());
|
Utility::SetThreadName(idbuf.str());
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -219,7 +221,7 @@ bool ThreadPool::Post(const ThreadPool::WorkFunction& callback)
|
||||||
void ThreadPool::ManagerThreadProc(void)
|
void ThreadPool::ManagerThreadProc(void)
|
||||||
{
|
{
|
||||||
std::ostringstream idbuf;
|
std::ostringstream idbuf;
|
||||||
idbuf << "TP " << this << " Manager";
|
idbuf << "TP #" << m_ID << " Manager";
|
||||||
Utility::SetThreadName(idbuf.str());
|
Utility::SetThreadName(idbuf.str());
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -336,7 +338,7 @@ void ThreadPool::KillWorker(void)
|
||||||
void ThreadPool::StatsThreadProc(void)
|
void ThreadPool::StatsThreadProc(void)
|
||||||
{
|
{
|
||||||
std::ostringstream idbuf;
|
std::ostringstream idbuf;
|
||||||
idbuf << "TP " << this << " Stats";
|
idbuf << "TP #" << m_ID << " Stats";
|
||||||
Utility::SetThreadName(idbuf.str());
|
Utility::SetThreadName(idbuf.str());
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -69,6 +69,9 @@ private:
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int m_ID;
|
||||||
|
static int m_NextID;
|
||||||
|
|
||||||
ThreadStats m_ThreadStats[512];
|
ThreadStats m_ThreadStats[512];
|
||||||
|
|
||||||
boost::thread m_ManagerThread;
|
boost::thread m_ManagerThread;
|
||||||
|
|
|
@ -261,6 +261,8 @@ void Timer::AdjustTimers(double adjustment)
|
||||||
*/
|
*/
|
||||||
void Timer::TimerThreadProc(void)
|
void Timer::TimerThreadProc(void)
|
||||||
{
|
{
|
||||||
|
Utility::SetThreadName("Timer Thread");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
boost::mutex::scoped_lock lock(l_Mutex);
|
boost::mutex::scoped_lock lock(l_Mutex);
|
||||||
|
|
||||||
|
|
|
@ -500,6 +500,29 @@ String Utility::EscapeShellCmd(const String& s)
|
||||||
void Utility::SetThreadName(const String& name)
|
void Utility::SetThreadName(const String& name)
|
||||||
{
|
{
|
||||||
m_ThreadName.reset(new String(name));
|
m_ThreadName.reset(new String(name));
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
THREADNAME_INFO info;
|
||||||
|
info.dwType = 0x1000;
|
||||||
|
info.szName = name.CStr();
|
||||||
|
info.dwThreadID = -1;
|
||||||
|
info.dwFlags = 0;
|
||||||
|
|
||||||
|
__try {
|
||||||
|
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
|
||||||
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
||||||
|
/* Nothing to do here. */
|
||||||
|
}
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
pthread_setname_np(name.CStr());
|
||||||
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
String tname = name.SubStr(0, 15);
|
||||||
|
pthread_setname_np(pthread_self(), tname.CStr());
|
||||||
|
#endif /* __linux__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
String Utility::GetThreadName(void)
|
String Utility::GetThreadName(void)
|
||||||
|
|
|
@ -29,6 +29,20 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define MS_VC_EXCEPTION 0x406D1388
|
||||||
|
|
||||||
|
# pragma pack(push, 8)
|
||||||
|
struct THREADNAME_INFO
|
||||||
|
{
|
||||||
|
DWORD dwType;
|
||||||
|
LPCSTR szName;
|
||||||
|
DWORD dwThreadID;
|
||||||
|
DWORD dwFlags;
|
||||||
|
};
|
||||||
|
# pragma pack(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper functions.
|
* Helper functions.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue