[Mlir-commits] [mlir] b82f374 - Revert "Minor fixes on the MLIR ActionProfiler (NFC)"
Mehdi Amini
llvmlistbot at llvm.org
Tue Oct 3 12:15:58 PDT 2023
Author: Mehdi Amini
Date: 2023-10-03T12:15:35-07:00
New Revision: b82f3747dac0ea3508656f9cd08ad0dbc03ca16d
URL: https://github.com/llvm/llvm-project/commit/b82f3747dac0ea3508656f9cd08ad0dbc03ca16d
DIFF: https://github.com/llvm/llvm-project/commit/b82f3747dac0ea3508656f9cd08ad0dbc03ca16d.diff
LOG: Revert "Minor fixes on the MLIR ActionProfiler (NFC)"
This reverts commit 0502d83470202de6412d4b310692c7b06f1791cb.
This introduces a race condition on the printComma variable.
Added:
Modified:
mlir/include/mlir/Debug/Observers/ActionProfiler.h
mlir/lib/Debug/Observers/ActionProfiler.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Debug/Observers/ActionProfiler.h b/mlir/include/mlir/Debug/Observers/ActionProfiler.h
index 8b324ea46eaba09..50ee4f0baf2b096 100644
--- a/mlir/include/mlir/Debug/Observers/ActionProfiler.h
+++ b/mlir/include/mlir/Debug/Observers/ActionProfiler.h
@@ -41,7 +41,7 @@ struct ActionProfiler : public ExecutionContext::Observer {
std::chrono::time_point<std::chrono::steady_clock> startTime;
bool printComma = false;
- /// A mutex used to guard printing from multiple threads.
+ /// A mutex used to guard profiling.
std::mutex mutex;
};
diff --git a/mlir/lib/Debug/Observers/ActionProfiler.cpp b/mlir/lib/Debug/Observers/ActionProfiler.cpp
index b08d5a24526b6a9..07bf9fd0ccc7db8 100644
--- a/mlir/lib/Debug/Observers/ActionProfiler.cpp
+++ b/mlir/lib/Debug/Observers/ActionProfiler.cpp
@@ -36,8 +36,6 @@ void ActionProfiler::print(const ActionActiveStack *action,
// Create the event.
std::string str;
llvm::raw_string_ostream event(str);
- if (printComma)
- event << ",\n";
event << "{";
event << R"("name": ")" << action->getAction().getTag() << "\", ";
event << R"("cat": "PERF", )";
@@ -54,11 +52,12 @@ void ActionProfiler::print(const ActionActiveStack *action,
event << "\"}";
}
event << "}";
- event.flush();
- // Print the event, guard with a mutex to ensure the stream is correctly
- // formed.
+ // Print the event.
std::lock_guard<std::mutex> guard(mutex);
+ if (printComma)
+ os << ",\n";
printComma = true;
os << event.str();
+ os.flush();
}
More information about the Mlir-commits
mailing list