Skip to content

Commit

Permalink
Fixes for profiler (apache#9932)
Browse files Browse the repository at this point in the history
* hash tid

* remove first flag conditions to fix missing commas

* hash tid

* remove first flag conditions to fix missing commas

* update comment

* CI restart

* address review comments
  • Loading branch information
rahul003 authored and cjolivier01 committed Mar 11, 2018
1 parent 34d5e50 commit faf23f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 2 additions & 14 deletions src/profiler/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,14 @@ void Profiler::DumpProfile(bool peform_cleanup) {
// If aggregate stats aren't enabled, this won't cause a locked instruction
std::shared_ptr<AggregateStats> 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;
while (d.opr_exec_stats_->try_dequeue(_opr_stat)) {
CHECK_NOTNULL(_opr_stat);
std::unique_ptr<ProfileStat> 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) {
Expand All @@ -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<ProfileStat> 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
Expand Down
8 changes: 5 additions & 3 deletions src/profiler/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<std::thread::id>{}(thread_id_) << "\n"
<< " }\n";
}
}
Expand Down Expand Up @@ -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<std::thread::id>{}(thread_id_) << ",\n";
}
};

Expand Down

0 comments on commit faf23f9

Please sign in to comment.