未验证 提交 79caed66 编写于 作者: W wangchaochaohu 提交者: GitHub

fix the print error of PE record_event and framework overhead in profiler test=develop (#24744)

上级 56a714a1
......@@ -641,22 +641,24 @@ DeviceTracer *GetDeviceTracer() {
return tracer;
}
std::string SetCurAnnotation(Event *event) {
// In order to record PE time, we add main_thread_annotation_stack
// for all event between PE run, we treat it as PE's child Event,
// 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->role() != EventRole::kSpecial) {
if (!annotation_stack.empty()) {
event->set_parent(annotation_stack.back());
event->set_name(annotation_stack.back()->name() + "/" + event->name());
}
if (annotation_stack.empty() && !main_thread_annotation_stack.empty() &&
main_thread_annotation_stack.back()->thread_id() != event->thread_id()) {
event->set_parent(main_thread_annotation_stack.back());
event->set_name(main_thread_annotation_stack.back()->name() + "/" +
event->name());
}
annotation_stack.push_back(event);
if (!main_thread_annotation_stack_name.empty() && !annotation_stack.empty() &&
main_thread_annotation_stack.back()->thread_id() !=
annotation_stack.back()->thread_id()) {
ret = main_thread_annotation_stack_name.back() + "/" + event->name();
} else {
ret = event->name();
}
if (event->role() == EventRole::kSpecial) {
std::string name = event->name();
if (!main_thread_annotation_stack_name.empty()) {
......@@ -665,23 +667,24 @@ std::string SetCurAnnotation(Event *event) {
main_thread_annotation_stack_name.push_back(name);
main_thread_annotation_stack.push_back(event);
}
return ret;
}
void ClearCurAnnotation() {
if (!main_thread_annotation_stack_name.empty() && !annotation_stack.empty() &&
main_thread_annotation_stack.back()->thread_id() !=
annotation_stack.back()->thread_id()) {
annotation_stack.back()->set_name(main_thread_annotation_stack_name.back() +
"/" + annotation_stack.back()->name());
}
if (!main_thread_annotation_stack.empty() &&
main_thread_annotation_stack.back()->name() ==
annotation_stack.back()->name()) {
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)) {
main_thread_annotation_stack_name.pop_back();
main_thread_annotation_stack.pop_back();
}
}
annotation_stack.pop_back();
}
......
......@@ -137,7 +137,7 @@ class DeviceTracer {
DeviceTracer* GetDeviceTracer();
// Set a name for the cuda kernel operation being launched by the thread.
std::string SetCurAnnotation(Event* event);
void SetCurAnnotation(Event* event);
// Clear the name after the operation is done.
void ClearCurAnnotation();
// Current name of the operation being run in the thread.
......
......@@ -73,7 +73,8 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) {
// lock is not needed, the code below is thread-safe
Event *e = PushEvent(name, role);
// Maybe need the same push/pop behavior.
name_ = SetCurAnnotation(e);
SetCurAnnotation(e);
name_ = e->name();
}
RecordEvent::~RecordEvent() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册