From 6ba7c3ac92094c1bf5f7dddd1396d2776e538889 Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Fri, 24 Apr 2020 17:01:08 +0800 Subject: [PATCH] Reduce the construction time of fuction about profiler (#24117) --- paddle/fluid/platform/profiler.cc | 13 +++++++++---- paddle/fluid/platform/profiler.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 394fdf13fa8..a36d8456eea 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 9eddee2ab67..dcc9f1eee10 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_; -- GitLab