11 #include "llvm/ADT/STLExtras.h" 12 #include "llvm/ADT/SmallString.h" 13 #include "llvm/Support/FileSystem.h" 14 #include "llvm/Support/Path.h" 15 #include "llvm/Support/YAMLTraits.h" 16 #include "llvm/Support/raw_ostream.h" 17 #include <system_error> 20 #define DEBUG_TYPE "clang-tidy-profiling" 26 llvm::StringRef SourceFile)
27 : Timestamp(std::chrono::system_clock::now()), SourceFilename(SourceFile) {
28 llvm::SmallString<32> TimestampStr;
29 llvm::raw_svector_ostream OS(TimestampStr);
30 llvm::format_provider<decltype(Timestamp)>::format(
Timestamp, OS,
33 llvm::SmallString<256> FinalPrefix(ProfilePrefix);
34 llvm::sys::path::append(FinalPrefix, TimestampStr);
38 llvm::sys::path::filename(SourceFile) +
".json")
42 void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &OS) {
47 void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &OS) {
49 OS <<
"\"file\": \"" << Storage->SourceFilename <<
"\",\n";
50 OS <<
"\"timestamp\": \"" << Storage->Timestamp <<
"\",\n";
51 OS <<
"\"profile\": {\n";
52 TG->printJSONValues(OS,
"");
58 void ClangTidyProfiling::storeProfileData() {
59 assert(Storage.hasValue() &&
"We should have a filename.");
61 llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
62 llvm::sys::path::remove_filename(OutputDirectory);
63 if (std::error_code EC = llvm::sys::fs::create_directories(OutputDirectory)) {
64 llvm::errs() <<
"Unable to create output directory '" << OutputDirectory
65 <<
"': " << EC.message() <<
"\n";
70 llvm::raw_fd_ostream OS(Storage->StoreFilename, EC, llvm::sys::fs::F_None);
72 llvm::errs() <<
"Error opening output file '" << Storage->StoreFilename
73 <<
"': " << EC.message() <<
"\n";
81 : Storage(std::move(Storage)) {}
84 TG.emplace(
"clang-tidy",
"clang-tidy checks profiling",
Records);
86 if (!Storage.hasValue())
87 printUserFriendlyTable(llvm::errs());
std::string StoreFilename
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::sys::TimePoint Timestamp
llvm::StringMap< llvm::TimeRecord > Records
ClangTidyProfiling()=default