From 20471de7188918e65f22ec0724d29346edd718c3 Mon Sep 17 00:00:00 2001 From: liutiexing <74819124+liutiexing@users.noreply.github.com> Date: Wed, 8 Dec 2021 18:58:01 +0800 Subject: [PATCH] Fix host event recorder (#37944) * add align for WorkQueue * add spinlock * merge develop * merge * Add EventsWaiter * Revert "Add EventsWaiter" This reverts commit e206173aa9be7401b83a53581627bfaf557c8fb2. * Fix RecordEvent Co-authored-by: liutiexing --- paddle/fluid/platform/profiler.cc | 23 ++++++++++++++--------- paddle/fluid/platform/profiler.h | 7 +++++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index f6d9c8f64f..476a192910 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -353,7 +353,7 @@ RecordEvent::RecordEvent(const char *name, const EventRole role) { #endif #endif if (UNLIKELY(g_enable_host_event_recorder_hook == false)) { - RecordEvent(name, role, "none"); + OriginalConstruct(name, role, "none"); return; } shallow_copy_name_ = name; @@ -371,7 +371,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) { #endif #endif if (UNLIKELY(g_enable_host_event_recorder_hook == false)) { - RecordEvent(name, role, "none"); + OriginalConstruct(name, role, "none"); return; } name_ = new std::string(name); @@ -389,13 +389,18 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role, } #endif #endif - if (g_enable_host_event_recorder_hook) { - name_ = new std::string(name); - start_ns_ = PosixInNsec(); - attr_ = new std::string(attr); + if (UNLIKELY(g_enable_host_event_recorder_hook == false)) { + OriginalConstruct(name, role, attr); return; } + name_ = new std::string(name); + start_ns_ = PosixInNsec(); + attr_ = new std::string(attr); +} +void RecordEvent::OriginalConstruct(const std::string &name, + const EventRole role, + const std::string &attr) { if (g_state == ProfilerState::kDisabled || name.empty()) return; // do some initialization @@ -408,7 +413,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role, // Maybe need the same push/pop behavior. Event *e = PushEvent(name, role, attr); SetCurAnnotation(e); - // name_ = e->name(); + *name_ = e->name(); } RecordEvent::~RecordEvent() { @@ -431,10 +436,10 @@ RecordEvent::~RecordEvent() { } else { HostEventRecorder::GetInstance().RecordEvent(*name_, start_ns_, end_ns, role_, *attr_); + delete attr_; } + delete name_; } - delete name_; - delete attr_; return; } diff --git a/paddle/fluid/platform/profiler.h b/paddle/fluid/platform/profiler.h index 317991160b..9d0bdf2358 100644 --- a/paddle/fluid/platform/profiler.h +++ b/paddle/fluid/platform/profiler.h @@ -139,17 +139,20 @@ struct RecordEvent { ~RecordEvent(); + void OriginalConstruct(const std::string& name, const EventRole role, + const std::string& attr); + bool is_enabled_{false}; bool is_pushed_{false}; // Event name - const std::string* name_{nullptr}; + std::string* name_{nullptr}; const char* shallow_copy_name_{nullptr}; uint64_t start_ns_; // Need to distinguish name by op type, block_id, program_id and perhaps // different kernel invocations within an op. // std::string full_name_; EventRole role_{EventRole::kOrdinary}; - const std::string* attr_{nullptr}; + std::string* attr_{nullptr}; }; /*class RecordRPCEvent { -- GitLab