diff --git a/paddle/fluid/platform/device_tracer.cc b/paddle/fluid/platform/device_tracer.cc index f2266bd78ce678333f1e20f3522ac8d9b444184e..d362b841065c41a0b26cedb566fa6d66572dbbbc 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 22e00b89239fcb556efe56d50c3ed209664ee7e3..fc1d9a8799962be4110037125e755b18ee0b93ee 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(); }