diff --git a/src/libslic3r/Thread.cpp b/src/libslic3r/Thread.cpp index 878130df5..58684a4dd 100644 --- a/src/libslic3r/Thread.cpp +++ b/src/libslic3r/Thread.cpp @@ -84,6 +84,13 @@ void set_current_thread_name(const char *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 // posix @@ -102,6 +109,12 @@ void set_current_thread_name(const char *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 // 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 { assert(range.begin() > 0); std::ostringstream name; - name << "slic3r_tbbpool_" << range.begin() << "_" << thread_id; + name << "slic3r_tbb_" << range.begin(); set_current_thread_name(name.str()); } }); diff --git a/src/libslic3r/Thread.hpp b/src/libslic3r/Thread.hpp index f2cb5b1f0..8950cd3d3 100644 --- a/src/libslic3r/Thread.hpp +++ b/src/libslic3r/Thread.hpp @@ -7,6 +7,8 @@ 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); 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); @@ -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); 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 // give them names recognizible in the debugger. void name_tbb_thread_pool_threads(); diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index d868362f3..53d8eb701 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -224,7 +224,7 @@ void BackgroundSlicingProcess::process_sla() void BackgroundSlicingProcess::thread_proc() { - set_current_thread_name("slic3r_BackgroundSlicingProcess"); + set_current_thread_name("slic3r_BgSlcPcs"); name_tbb_thread_pool_threads(); assert(m_print != nullptr);