未验证 提交 6ba7c3ac 编写于 作者: W wangchaochaohu 提交者: GitHub

Reduce the construction time of fuction about profiler (#24117)

上级 2ca0e118
......@@ -63,11 +63,14 @@ double Event::CudaElapsedMs(const Event &e) const {
#endif
}
RecordEvent::RecordEvent(const std::string &name, const EventRole role)
: is_enabled_(false), start_ns_(PosixInNsec()), role_(role) {
RecordEvent::RecordEvent(const std::string &name, const EventRole role) {
if (g_state == ProfilerState::kDisabled || name.empty()) return;
// lock is not needed, the code below is thread-safe
// do some initialization
start_ns_ = PosixInNsec();
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.
SetCurAnnotation(e);
......@@ -256,6 +259,7 @@ void DisableProfiler(EventSortingKey sorted_key,
ResetProfiler();
g_state = ProfilerState::kDisabled;
g_tracer_option = TracerOption::kDefault;
should_send_profile_state = true;
}
......@@ -275,7 +279,8 @@ bool ShouldSendProfileState() { return should_send_profile_state; }
std::string OpName(const framework::VariableNameMap &name_map,
const std::string &type_name) {
if (platform::GetTracerOption() != platform::TracerOption::kAllOpDetail)
if (platform::GetTracerOption() != platform::TracerOption::kAllOpDetail ||
!IsProfileEnabled())
return "";
std::string ret = type_name + "%";
......
......@@ -127,7 +127,7 @@ struct RecordEvent {
~RecordEvent();
bool is_enabled_;
bool is_enabled_{false};
uint64_t start_ns_;
// Event name
std::string name_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册