Skip to content

Commit 46a08ce

Browse files
authored
[clang-tidy][NFC] simplify TimerGroup in ClangTidyProfiling (llvm#123958)
`TimerGroup` don't need to use as field of `ClangTidyProfiling`. We can construct it local during destructing.
1 parent 88136f9 commit 46a08ce

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,25 @@ ClangTidyProfiling::StorageParams::StorageParams(llvm::StringRef ProfilePrefix,
3636
.str();
3737
}
3838

39-
void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS) {
40-
TG->print(OS);
39+
void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS,
40+
llvm::TimerGroup &TG) {
41+
TG.print(OS);
4142
OS.flush();
4243
}
4344

44-
void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS) {
45+
void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS,
46+
llvm::TimerGroup &TG) {
4547
OS << "{\n";
4648
OS << R"("file": ")" << Storage->SourceFilename << "\",\n";
4749
OS << R"("timestamp": ")" << Storage->Timestamp << "\",\n";
4850
OS << "\"profile\": {\n";
49-
TG->printJSONValues(OS, "");
51+
TG.printJSONValues(OS, "");
5052
OS << "\n}\n";
5153
OS << "}\n";
5254
OS.flush();
5355
}
5456

55-
void ClangTidyProfiling::storeProfileData() {
57+
void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) {
5658
assert(Storage && "We should have a filename.");
5759

5860
llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
@@ -71,19 +73,18 @@ void ClangTidyProfiling::storeProfileData() {
7173
return;
7274
}
7375

74-
printAsJSON(OS);
76+
printAsJSON(OS, TG);
7577
}
7678

7779
ClangTidyProfiling::ClangTidyProfiling(std::optional<StorageParams> Storage)
7880
: Storage(std::move(Storage)) {}
7981

8082
ClangTidyProfiling::~ClangTidyProfiling() {
81-
TG.emplace("clang-tidy", "clang-tidy checks profiling", Records);
82-
83+
llvm::TimerGroup TG{"clang-tidy", "clang-tidy checks profiling", Records};
8384
if (!Storage)
84-
printUserFriendlyTable(llvm::errs());
85+
printUserFriendlyTable(llvm::errs(), TG);
8586
else
86-
storeProfileData();
87+
storeProfileData(TG);
8788
}
8889

8990
} // namespace clang::tidy

clang-tools-extra/clang-tidy/ClangTidyProfiling.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ class ClangTidyProfiling {
3434
};
3535

3636
private:
37-
std::optional<llvm::TimerGroup> TG;
38-
3937
std::optional<StorageParams> Storage;
4038

41-
void printUserFriendlyTable(llvm::raw_ostream &OS);
42-
void printAsJSON(llvm::raw_ostream &OS);
43-
44-
void storeProfileData();
39+
void printUserFriendlyTable(llvm::raw_ostream &OS, llvm::TimerGroup &TG);
40+
void printAsJSON(llvm::raw_ostream &OS, llvm::TimerGroup &TG);
41+
void storeProfileData(llvm::TimerGroup &TG);
4542

4643
public:
4744
llvm::StringMap<llvm::TimeRecord> Records;

0 commit comments

Comments
 (0)