Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
9 changes: 3 additions & 6 deletions clang-tools-extra/clang-tidy/ClangTidyProfiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ class ClangTidyProfiling {
};

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;
Expand Down
Loading