Skip to content

Commit 6b931b8

Browse files
committed
move QueryProfiler into Query.cpp
1. QueryProfiler is very small, no need to expose it; 2. TimerGroup is created when dumping profiling info, no need to be an optional member of QueryProfiler.
1 parent 57151c6 commit 6b931b8

File tree

4 files changed

+24
-64
lines changed

4 files changed

+24
-64
lines changed

clang-tools-extra/clang-query/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(LLVM_LINK_COMPONENTS
77
add_clang_library(clangQuery STATIC
88
Query.cpp
99
QueryParser.cpp
10-
QueryProfile.cpp
1110

1211
DEPENDS
1312
omp_gen

clang-tools-extra/clang-query/Query.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "Query.h"
1010
#include "QueryParser.h"
11-
#include "QueryProfile.h"
1211
#include "QuerySession.h"
1312
#include "clang/AST/ASTDumper.h"
1413
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -94,14 +93,35 @@ struct CollectBoundNodes : MatchFinder::MatchCallback {
9493
StringRef getID() const override { return Unit; }
9594
};
9695

96+
class QueryProfiler {
97+
public:
98+
QueryProfiler() = default;
99+
~QueryProfiler() { printUserFriendlyTable(llvm::errs()); }
100+
101+
void addASTUnitRecord(llvm::StringRef Unit, const llvm::TimeRecord &Record) {
102+
Records[Unit] += Record;
103+
}
104+
105+
private:
106+
void printUserFriendlyTable(llvm::raw_ostream &OS) {
107+
llvm::TimerGroup TG("clang-query", "clang-query matcher profiling",
108+
Records);
109+
TG.print(OS);
110+
OS.flush();
111+
}
112+
113+
private:
114+
llvm::StringMap<llvm::TimeRecord> Records;
115+
};
116+
97117
} // namespace
98118

99119
bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
100120
unsigned MatchCount = 0;
101121

102-
std::optional<QueryProfile> Profiling;
122+
std::optional<QueryProfiler> Profiler;
103123
if (QS.EnableProfile)
104-
Profiling.emplace();
124+
Profiler.emplace();
105125

106126
for (auto &AST : QS.ASTs) {
107127
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
@@ -130,7 +150,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
130150
Ctx.getParentMapContext().setTraversalKind(QS.TK);
131151
Finder.matchAST(Ctx);
132152
if (QS.EnableProfile)
133-
Profiling->Records[OrigSrcName] += (*Records)[OrigSrcName];
153+
Profiler->addASTUnitRecord(OrigSrcName, (*Records)[OrigSrcName]);
134154

135155
if (QS.PrintMatcher) {
136156
SmallVector<StringRef, 4> Lines;

clang-tools-extra/clang-query/QueryProfile.cpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

clang-tools-extra/clang-query/QueryProfile.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)