diff --git a/src/profiler/profiler.cc b/src/profiler/profiler.cc index 82d1744d7b47..e6dafb3d0916 100644 --- a/src/profiler/profiler.cc +++ b/src/profiler/profiler.cc @@ -205,7 +205,6 @@ void Profiler::DumpProfile(bool peform_cleanup) { // If aggregate stats aren't enabled, this won't cause a locked instruction std::shared_ptr ptr_aggregate_stats = aggregate_stats_.get() ? aggregate_stats_ : nullptr; - bool first_flag = !first_pass && !num_records_emitted_; for (uint32_t i = 0; i < dev_num; ++i) { DeviceStats &d = profile_stat[i]; ProfileStat *_opr_stat; @@ -213,12 +212,7 @@ void Profiler::DumpProfile(bool peform_cleanup) { CHECK_NOTNULL(_opr_stat); std::unique_ptr opr_stat(_opr_stat); // manage lifecycle opr_stat->process_id_ = i; // lie and set process id to be the device number - if (first_flag) { - first_flag = false; - } else { - file << ",\n"; - } - file << std::endl; + file << ",\n" << std::endl; opr_stat->EmitEvents(&file); ++num_records_emitted_; if (ptr_aggregate_stats) { @@ -231,13 +225,7 @@ void Profiler::DumpProfile(bool peform_cleanup) { ProfileStat *_profile_stat; while (general_stats_.opr_exec_stats_->try_dequeue(_profile_stat)) { CHECK_NOTNULL(_profile_stat); - - if (first_flag) { - first_flag = false; - } else { - file << ","; - } - + file << ","; std::unique_ptr profile_stat(_profile_stat); // manage lifecycle CHECK_NE(profile_stat->categories_.c_str()[0], '\0') << "Category must be set"; // Currently, category_to_pid_ is only accessed here, so it is protected by this->m_ above diff --git a/src/profiler/profiler.h b/src/profiler/profiler.h index 1224231761ba..768a0bc7d711 100644 --- a/src/profiler/profiler.h +++ b/src/profiler/profiler.h @@ -130,7 +130,9 @@ struct ProfileStat { /* !\brief Process id */ size_t process_id_ = current_process_id(); - /*! \brief id of thread which operation run on */ + /*! \brief id of thread which operation run on. + * + * */ std::thread::id thread_id_ = std::this_thread::get_id(); // Not yet seen a // case where this isn't valid @@ -209,7 +211,7 @@ struct ProfileStat { << " \"ts\": " << ev.timestamp_ << ",\n"; EmitExtra(os, idx); *os << " \"pid\": " << process_id_ << ",\n" - << " \"tid\": " << thread_id_ << "\n" + << " \"tid\": " << std::hash{}(thread_id_) << "\n" << " }\n"; } } @@ -794,7 +796,7 @@ struct ProfileTask : public ProfileDuration { } void EmitExtra(std::ostream *os, size_t idx) override { DurationStat::EmitExtra(os, idx); - *os << " \"id\": " << thread_id_ << ",\n"; + *os << " \"id\": " << std::hash{}(thread_id_) << ",\n"; } };