mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 11:06:33 +00:00
[clang-tidy][NFC] simplify TimerGroup
in ClangTidyProfiling
(#123958)
`TimerGroup` don't need to use as field of `ClangTidyProfiling`. We can construct it local during destructing.
This commit is contained in:
parent
88136f9645
commit
46a08ce832
@ -36,23 +36,25 @@ ClangTidyProfiling::StorageParams::StorageParams(llvm::StringRef ProfilePrefix,
|
||||
.str();
|
||||
}
|
||||
|
||||
void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS) {
|
||||
TG->print(OS);
|
||||
void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS,
|
||||
llvm::TimerGroup &TG) {
|
||||
TG.print(OS);
|
||||
OS.flush();
|
||||
}
|
||||
|
||||
void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS) {
|
||||
void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS,
|
||||
llvm::TimerGroup &TG) {
|
||||
OS << "{\n";
|
||||
OS << R"("file": ")" << Storage->SourceFilename << "\",\n";
|
||||
OS << R"("timestamp": ")" << Storage->Timestamp << "\",\n";
|
||||
OS << "\"profile\": {\n";
|
||||
TG->printJSONValues(OS, "");
|
||||
TG.printJSONValues(OS, "");
|
||||
OS << "\n}\n";
|
||||
OS << "}\n";
|
||||
OS.flush();
|
||||
}
|
||||
|
||||
void ClangTidyProfiling::storeProfileData() {
|
||||
void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) {
|
||||
assert(Storage && "We should have a filename.");
|
||||
|
||||
llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
|
||||
@ -71,19 +73,18 @@ void ClangTidyProfiling::storeProfileData() {
|
||||
return;
|
||||
}
|
||||
|
||||
printAsJSON(OS);
|
||||
printAsJSON(OS, TG);
|
||||
}
|
||||
|
||||
ClangTidyProfiling::ClangTidyProfiling(std::optional<StorageParams> Storage)
|
||||
: Storage(std::move(Storage)) {}
|
||||
|
||||
ClangTidyProfiling::~ClangTidyProfiling() {
|
||||
TG.emplace("clang-tidy", "clang-tidy checks profiling", Records);
|
||||
|
||||
llvm::TimerGroup TG{"clang-tidy", "clang-tidy checks profiling", Records};
|
||||
if (!Storage)
|
||||
printUserFriendlyTable(llvm::errs());
|
||||
printUserFriendlyTable(llvm::errs(), TG);
|
||||
else
|
||||
storeProfileData();
|
||||
storeProfileData(TG);
|
||||
}
|
||||
|
||||
} // namespace clang::tidy
|
||||
|
@ -34,14 +34,11 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
std::optional<llvm::TimerGroup> TG;
|
||||
|
||||
std::optional<StorageParams> Storage;
|
||||
|
||||
void printUserFriendlyTable(llvm::raw_ostream &OS);
|
||||
void printAsJSON(llvm::raw_ostream &OS);
|
||||
|
||||
void storeProfileData();
|
||||
void printUserFriendlyTable(llvm::raw_ostream &OS, llvm::TimerGroup &TG);
|
||||
void printAsJSON(llvm::raw_ostream &OS, llvm::TimerGroup &TG);
|
||||
void storeProfileData(llvm::TimerGroup &TG);
|
||||
|
||||
public:
|
||||
llvm::StringMap<llvm::TimeRecord> Records;
|
||||
|
Loading…
x
Reference in New Issue
Block a user