Skip to content

Commit b82f374

Browse files
committed
Revert "Minor fixes on the MLIR ActionProfiler (NFC)"
This reverts commit 0502d83. This introduces a race condition on the printComma variable.
1 parent af16a4e commit b82f374

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

mlir/include/mlir/Debug/Observers/ActionProfiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ActionProfiler : public ExecutionContext::Observer {
4141
std::chrono::time_point<std::chrono::steady_clock> startTime;
4242
bool printComma = false;
4343

44-
/// A mutex used to guard printing from multiple threads.
44+
/// A mutex used to guard profiling.
4545
std::mutex mutex;
4646
};
4747

mlir/lib/Debug/Observers/ActionProfiler.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ void ActionProfiler::print(const ActionActiveStack *action,
3636
// Create the event.
3737
std::string str;
3838
llvm::raw_string_ostream event(str);
39-
if (printComma)
40-
event << ",\n";
4139
event << "{";
4240
event << R"("name": ")" << action->getAction().getTag() << "\", ";
4341
event << R"("cat": "PERF", )";
@@ -54,11 +52,12 @@ void ActionProfiler::print(const ActionActiveStack *action,
5452
event << "\"}";
5553
}
5654
event << "}";
57-
event.flush();
5855

59-
// Print the event, guard with a mutex to ensure the stream is correctly
60-
// formed.
56+
// Print the event.
6157
std::lock_guard<std::mutex> guard(mutex);
58+
if (printComma)
59+
os << ",\n";
6260
printComma = true;
6361
os << event.str();
62+
os.flush();
6463
}

0 commit comments

Comments
 (0)