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

revert-22778-infer_var_type
wangchaochaohu 5 years ago committed by GitHub
parent 2ca0e11861
commit 6ba7c3ac92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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_;

Loading…
Cancel
Save