diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 394fdf13fa818b03c270f83d93c868e36c82b0ad..a36d8456eeaa5316f56e7fac649442c48355f9c1 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -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 + "%"; diff --git a/paddle/fluid/platform/profiler.h b/paddle/fluid/platform/profiler.h index 9eddee2ab676be03da50d90866b564791c3df8a4..dcc9f1eee104deb55e96619fade908f4d6532913 100644 --- a/paddle/fluid/platform/profiler.h +++ b/paddle/fluid/platform/profiler.h @@ -127,7 +127,7 @@ struct RecordEvent { ~RecordEvent(); - bool is_enabled_; + bool is_enabled_{false}; uint64_t start_ns_; // Event name std::string name_;