|
8 | 8 |
|
9 | 9 | #include "Query.h" |
10 | 10 | #include "QueryParser.h" |
11 | | -#include "QueryProfile.h" |
12 | 11 | #include "QuerySession.h" |
13 | 12 | #include "clang/AST/ASTDumper.h" |
14 | 13 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
@@ -94,14 +93,35 @@ struct CollectBoundNodes : MatchFinder::MatchCallback { |
94 | 93 | StringRef getID() const override { return Unit; } |
95 | 94 | }; |
96 | 95 |
|
| 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 | + |
97 | 117 | } // namespace |
98 | 118 |
|
99 | 119 | bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { |
100 | 120 | unsigned MatchCount = 0; |
101 | 121 |
|
102 | | - std::optional<QueryProfile> Profiling; |
| 122 | + std::optional<QueryProfiler> Profiler; |
103 | 123 | if (QS.EnableProfile) |
104 | | - Profiling.emplace(); |
| 124 | + Profiler.emplace(); |
105 | 125 |
|
106 | 126 | for (auto &AST : QS.ASTs) { |
107 | 127 | ast_matchers::MatchFinder::MatchFinderOptions FinderOptions; |
@@ -130,7 +150,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const { |
130 | 150 | Ctx.getParentMapContext().setTraversalKind(QS.TK); |
131 | 151 | Finder.matchAST(Ctx); |
132 | 152 | if (QS.EnableProfile) |
133 | | - Profiling->Records[OrigSrcName] += (*Records)[OrigSrcName]; |
| 153 | + Profiler->addASTUnitRecord(OrigSrcName, (*Records)[OrigSrcName]); |
134 | 154 |
|
135 | 155 | if (QS.PrintMatcher) { |
136 | 156 | SmallVector<StringRef, 4> Lines; |
|
0 commit comments