[clang] [analyzer] Only create checker time trace scopes when tracing (PR #245070)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 05:46:34 PST 2026
================
@@ -134,11 +134,27 @@ static void expandGraphWithCheckers(CHECK_CTX checkCtx, ExplodedNodeSet &Dst,
namespace {
-std::string checkerScopeName(StringRef Name, const CheckerBackend *Checker) {
- if (!llvm::timeTraceProfilerEnabled())
- return "";
+/// A time trace scope that only exists when -ftime-trace is enabled.
+using CheckerTimeTraceScope = std::optional<llvm::TimeTraceScope>;
+
+template <typename... ArgTys>
+CheckerTimeTraceScope timeTraceScope(const CheckerManager &Mgr,
+ ArgTys &&...Args) {
+ if (!Mgr.isTimeTraceEnabled())
+ return std::nullopt;
+ return CheckerTimeTraceScope(std::in_place, std::forward<ArgTys>(Args)...);
+}
+
+/// Like timeTraceScope, but names the scope after the checker, and only
+/// builds the name when -ftime-trace is enabled.
+CheckerTimeTraceScope checkerTimeTraceScope(const ExprEngine &Eng,
+ StringRef Name,
+ const CheckerBackend *Checker) {
+ const CheckerManager &Mgr = Eng.getCheckerManager();
+ if (!Mgr.isTimeTraceEnabled())
+ return std::nullopt;
StringRef CheckerTag = Checker ? Checker->getDebugTag() : "<unknown>";
- return (Name + ":" + CheckerTag).str();
+ return timeTraceScope(Mgr, (Name + ":" + CheckerTag).str());
----------------
Xazax-hun wrote:
The call is indeed redundant, will update. I'd keep the current approach rather than going to `Twine`, because constructing the `Twine` involved a virtual call (`getDebugTag`). While a single virtual call is not that big of a cost, I think changing to another approach that is also a bit worse off performance wise might not carry its weight given that this PR is already relatively small.
https://github.com/llvm/llvm-project/pull/245070
More information about the cfe-commits
mailing list