未验证 提交 b8a16911 编写于 作者: L liutiexing 提交者: GitHub

Workqueue threadnames (#40035)

* add align for WorkQueue

* add spinlock

* merge develop

* merge

* Add EventsWaiter

* Revert "Add EventsWaiter"

This reverts commit e206173aa9be7401b83a53581627bfaf557c8fb2.

* Set thread name for WorkQueue

* Add thread names

* fix ut
Co-authored-by: Nliutiexing <liutiexing@google.com>
上级 3779e807
...@@ -409,7 +409,7 @@ class ThreadPoolTempl { ...@@ -409,7 +409,7 @@ class ThreadPoolTempl {
return false; return false;
} }
platform::RecordEvent("SleepWaitForWork", platform::RecordEvent("SleepWaitForWork",
platform::TracerEventType::UserDefined, 2); platform::TracerEventType::UserDefined, 10);
ec_.CommitWait(waiter); ec_.CommitWait(waiter);
blocked_--; blocked_--;
return true; return true;
......
...@@ -28,6 +28,7 @@ limitations under the License. */ ...@@ -28,6 +28,7 @@ limitations under the License. */
#include "paddle/fluid/platform/device/device_wrapper.h" #include "paddle/fluid/platform/device/device_wrapper.h"
#include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/init.h" #include "paddle/fluid/platform/init.h"
#include "paddle/fluid/platform/os_info.h"
#include "paddle/fluid/platform/place.h" #include "paddle/fluid/platform/place.h"
#ifdef PADDLE_WITH_XPU #ifdef PADDLE_WITH_XPU
...@@ -161,6 +162,8 @@ void LoadCustomDevice(const std::string &library_dir) { ...@@ -161,6 +162,8 @@ void LoadCustomDevice(const std::string &library_dir) {
#endif #endif
void InitDevices() { void InitDevices() {
// set name at the entry point of Paddle
platform::SetCurrentThreadName("MainThread");
// CUPTI attribute should be set before any CUDA context is created (see CUPTI // CUPTI attribute should be set before any CUDA context is created (see CUPTI
// documentation about CUpti_ActivityAttribute). // documentation about CUpti_ActivityAttribute).
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
......
...@@ -30,8 +30,7 @@ TEST(ThreadInfo, TestThreadNameUtils) { ...@@ -30,8 +30,7 @@ TEST(ThreadInfo, TestThreadNameUtils) {
using paddle::platform::GetCurrentThreadName; using paddle::platform::GetCurrentThreadName;
using paddle::platform::SetCurrentThreadName; using paddle::platform::SetCurrentThreadName;
using paddle::platform::GetAllThreadNames; using paddle::platform::GetAllThreadNames;
EXPECT_EQ("unset", GetCurrentThreadName()); SetCurrentThreadName("MainThread");
EXPECT_TRUE(SetCurrentThreadName("MainThread"));
EXPECT_FALSE(SetCurrentThreadName("MainThread")); EXPECT_FALSE(SetCurrentThreadName("MainThread"));
auto names = GetAllThreadNames(); auto names = GetAllThreadNames();
EXPECT_TRUE(names.find(GetCurrentThreadStdId()) != names.end()); EXPECT_TRUE(names.find(GetCurrentThreadStdId()) != names.end());
......
...@@ -189,7 +189,10 @@ struct ThreadEventSection { ...@@ -189,7 +189,10 @@ struct ThreadEventSection {
class ThreadEventRecorder { class ThreadEventRecorder {
public: public:
ThreadEventRecorder() { thread_id_ = GetCurrentThreadSysId(); } ThreadEventRecorder() {
thread_id_ = GetCurrentThreadSysId();
thread_name_ = GetCurrentThreadName();
}
DISABLE_COPY_AND_ASSIGN(ThreadEventRecorder); DISABLE_COPY_AND_ASSIGN(ThreadEventRecorder);
...@@ -202,7 +205,7 @@ class ThreadEventRecorder { ...@@ -202,7 +205,7 @@ class ThreadEventRecorder {
ThreadEventSection GatherEvents() { ThreadEventSection GatherEvents() {
ThreadEventSection thr_sec; ThreadEventSection thr_sec;
thr_sec.thread_name = GetCurrentThreadName(); thr_sec.thread_name = thread_name_;
thr_sec.thread_id = thread_id_; thr_sec.thread_id = thread_id_;
thr_sec.events = std::move(base_evt_cntr_.Reduce()); thr_sec.events = std::move(base_evt_cntr_.Reduce());
return thr_sec; return thr_sec;
...@@ -210,6 +213,7 @@ class ThreadEventRecorder { ...@@ -210,6 +213,7 @@ class ThreadEventRecorder {
private: private:
uint64_t thread_id_; uint64_t thread_id_;
std::string thread_name_;
EventContainer<CommonEvent> base_evt_cntr_; EventContainer<CommonEvent> base_evt_cntr_;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册