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

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: Nliutiexing <liutiexing@google.com>
上级 5cecfd23
...@@ -353,7 +353,7 @@ RecordEvent::RecordEvent(const char *name, const EventRole role) { ...@@ -353,7 +353,7 @@ RecordEvent::RecordEvent(const char *name, const EventRole role) {
#endif #endif
#endif #endif
if (UNLIKELY(g_enable_host_event_recorder_hook == false)) { if (UNLIKELY(g_enable_host_event_recorder_hook == false)) {
RecordEvent(name, role, "none"); OriginalConstruct(name, role, "none");
return; return;
} }
shallow_copy_name_ = name; shallow_copy_name_ = name;
...@@ -371,7 +371,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) { ...@@ -371,7 +371,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) {
#endif #endif
#endif #endif
if (UNLIKELY(g_enable_host_event_recorder_hook == false)) { if (UNLIKELY(g_enable_host_event_recorder_hook == false)) {
RecordEvent(name, role, "none"); OriginalConstruct(name, role, "none");
return; return;
} }
name_ = new std::string(name); name_ = new std::string(name);
...@@ -389,13 +389,18 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role, ...@@ -389,13 +389,18 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role,
} }
#endif #endif
#endif #endif
if (g_enable_host_event_recorder_hook) { if (UNLIKELY(g_enable_host_event_recorder_hook == false)) {
name_ = new std::string(name); OriginalConstruct(name, role, attr);
start_ns_ = PosixInNsec();
attr_ = new std::string(attr);
return; 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; if (g_state == ProfilerState::kDisabled || name.empty()) return;
// do some initialization // do some initialization
...@@ -408,7 +413,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role, ...@@ -408,7 +413,7 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role,
// Maybe need the same push/pop behavior. // Maybe need the same push/pop behavior.
Event *e = PushEvent(name, role, attr); Event *e = PushEvent(name, role, attr);
SetCurAnnotation(e); SetCurAnnotation(e);
// name_ = e->name(); *name_ = e->name();
} }
RecordEvent::~RecordEvent() { RecordEvent::~RecordEvent() {
...@@ -431,10 +436,10 @@ RecordEvent::~RecordEvent() { ...@@ -431,10 +436,10 @@ RecordEvent::~RecordEvent() {
} else { } else {
HostEventRecorder::GetInstance().RecordEvent(*name_, start_ns_, end_ns, HostEventRecorder::GetInstance().RecordEvent(*name_, start_ns_, end_ns,
role_, *attr_); role_, *attr_);
delete attr_;
} }
delete name_;
} }
delete name_;
delete attr_;
return; return;
} }
......
...@@ -139,17 +139,20 @@ struct RecordEvent { ...@@ -139,17 +139,20 @@ struct RecordEvent {
~RecordEvent(); ~RecordEvent();
void OriginalConstruct(const std::string& name, const EventRole role,
const std::string& attr);
bool is_enabled_{false}; bool is_enabled_{false};
bool is_pushed_{false}; bool is_pushed_{false};
// Event name // Event name
const std::string* name_{nullptr}; std::string* name_{nullptr};
const char* shallow_copy_name_{nullptr}; const char* shallow_copy_name_{nullptr};
uint64_t start_ns_; uint64_t start_ns_;
// Need to distinguish name by op type, block_id, program_id and perhaps // Need to distinguish name by op type, block_id, program_id and perhaps
// different kernel invocations within an op. // different kernel invocations within an op.
// std::string full_name_; // std::string full_name_;
EventRole role_{EventRole::kOrdinary}; EventRole role_{EventRole::kOrdinary};
const std::string* attr_{nullptr}; std::string* attr_{nullptr};
}; };
/*class RecordRPCEvent { /*class RecordRPCEvent {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册