From feba131893120705f77c56e488a54fb14b603cd4 Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Tue, 9 Jun 2020 12:04:26 +0800 Subject: [PATCH] fix the sgement fault error of profiler in seqseq model test=develop (#24952) --- paddle/fluid/platform/device_tracer.cc | 10 ++++------ paddle/fluid/platform/profiler.cc | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/platform/device_tracer.cc b/paddle/fluid/platform/device_tracer.cc index f2266bd78ce..d362b841065 100644 --- a/paddle/fluid/platform/device_tracer.cc +++ b/paddle/fluid/platform/device_tracer.cc @@ -646,7 +646,6 @@ DeviceTracer *GetDeviceTracer() { // so when event is not in same thread of PE event, we need add // father event(PE::run event) for this event void SetCurAnnotation(Event *event) { - std::string ret; if (!annotation_stack.empty()) { event->set_parent(annotation_stack.back()); event->set_name(annotation_stack.back()->name() + "/" + event->name()); @@ -670,17 +669,16 @@ void SetCurAnnotation(Event *event) { } void ClearCurAnnotation() { - if (!main_thread_annotation_stack.empty() && - main_thread_annotation_stack.back()->name() == - annotation_stack.back()->name()) { + if (!main_thread_annotation_stack.empty()) { std::string name = annotation_stack.back()->name(); std::string main_name = main_thread_annotation_stack.back()->name(); int main_name_len = main_name.length(); int name_len = name.length(); int prefix_len = main_name_len - name_len; - if (prefix_len >= 0 && main_name.at(prefix_len) == '/' && - name == main_name.substr(prefix_len, name_len)) { + if ((prefix_len > 0 && main_name.at(prefix_len - 1) == '/' && + name == main_name.substr(prefix_len, name_len)) || + (name == main_name)) { main_thread_annotation_stack_name.pop_back(); main_thread_annotation_stack.pop_back(); } diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 22e00b89239..fc1d9a87999 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -71,8 +71,8 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) { role_ = role; is_enabled_ = true; // lock is not needed, the code below is thread-safe - Event *e = PushEvent(name, role); // Maybe need the same push/pop behavior. + Event *e = PushEvent(name, role); SetCurAnnotation(e); name_ = e->name(); } -- GitLab