Thread names shortened to 15 characters to fit Posix norm.
Added get_current_thread_name()
This commit is contained in:
parent
be73962699
commit
81b6883710
@ -84,6 +84,13 @@ void set_current_thread_name(const char *thread_name)
|
|||||||
WindowsSetThreadName(::GetCurrentThread(), thread_name);
|
WindowsSetThreadName(::GetCurrentThread(), thread_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void std::string get_current_thread_name() const
|
||||||
|
{
|
||||||
|
wchar_t *ptr = nullptr;
|
||||||
|
::GetThreadDescription(::GetCurrentThread(), &ptr);
|
||||||
|
return std::string((ptr == nullptr) ? "" : ptr);
|
||||||
|
}
|
||||||
|
|
||||||
#else // _WIN32
|
#else // _WIN32
|
||||||
|
|
||||||
// posix
|
// posix
|
||||||
@ -102,6 +109,12 @@ void set_current_thread_name(const char *thread_name)
|
|||||||
set_thread_name(pthread_self(), thread_name);
|
set_thread_name(pthread_self(), thread_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void std::string get_current_thread_name() const
|
||||||
|
{
|
||||||
|
char buf[16];
|
||||||
|
return std::string(pthread_getname_np(pthread_self(), buf, 16) == 0 ? buf : "");
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
// Spawn (n - 1) worker threads on Intel TBB thread pool and name them by an index and a system thread ID.
|
// Spawn (n - 1) worker threads on Intel TBB thread pool and name them by an index and a system thread ID.
|
||||||
@ -149,7 +162,7 @@ void name_tbb_thread_pool_threads()
|
|||||||
} else {
|
} else {
|
||||||
assert(range.begin() > 0);
|
assert(range.begin() > 0);
|
||||||
std::ostringstream name;
|
std::ostringstream name;
|
||||||
name << "slic3r_tbbpool_" << range.begin() << "_" << thread_id;
|
name << "slic3r_tbb_" << range.begin();
|
||||||
set_current_thread_name(name.str());
|
set_current_thread_name(name.str());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
// Set / get thread name.
|
||||||
|
// pthread_setname_np supports maximum 15 character thread names! (16th character is the null terminator)
|
||||||
void set_thread_name(std::thread &thread, const char *thread_name);
|
void set_thread_name(std::thread &thread, const char *thread_name);
|
||||||
inline void set_thread_name(std::thread &thread, const std::string &thread_name) { set_thread_name(thread, thread_name.c_str()); }
|
inline void set_thread_name(std::thread &thread, const std::string &thread_name) { set_thread_name(thread, thread_name.c_str()); }
|
||||||
void set_thread_name(boost::thread &thread, const char *thread_name);
|
void set_thread_name(boost::thread &thread, const char *thread_name);
|
||||||
@ -14,6 +16,8 @@ inline void set_thread_name(boost::thread &thread, const std::string &thread_nam
|
|||||||
void set_current_thread_name(const char *thread_name);
|
void set_current_thread_name(const char *thread_name);
|
||||||
inline void set_current_thread_name(const std::string &thread_name) { set_current_thread_name(thread_name.c_str()); }
|
inline void set_current_thread_name(const std::string &thread_name) { set_current_thread_name(thread_name.c_str()); }
|
||||||
|
|
||||||
|
void std::string get_current_thread_name() const;
|
||||||
|
|
||||||
// To be called somewhere before the TBB threads are spinned for the first time, to
|
// To be called somewhere before the TBB threads are spinned for the first time, to
|
||||||
// give them names recognizible in the debugger.
|
// give them names recognizible in the debugger.
|
||||||
void name_tbb_thread_pool_threads();
|
void name_tbb_thread_pool_threads();
|
||||||
|
@ -224,7 +224,7 @@ void BackgroundSlicingProcess::process_sla()
|
|||||||
|
|
||||||
void BackgroundSlicingProcess::thread_proc()
|
void BackgroundSlicingProcess::thread_proc()
|
||||||
{
|
{
|
||||||
set_current_thread_name("slic3r_BackgroundSlicingProcess");
|
set_current_thread_name("slic3r_BgSlcPcs");
|
||||||
name_tbb_thread_pool_threads();
|
name_tbb_thread_pool_threads();
|
||||||
|
|
||||||
assert(m_print != nullptr);
|
assert(m_print != nullptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user