10#include "llvm/ADT/SmallString.h"
11#include "llvm/Support/FileSystem.h"
12#include "llvm/Support/Path.h"
13#include "llvm/Support/raw_ostream.h"
15#include <system_error>
18#define DEBUG_TYPE "clang-tidy-profiling"
23 llvm::StringRef SourceFile)
24 : Timestamp(std::chrono::system_clock::now()), SourceFilename(SourceFile) {
25 llvm::SmallString<32> TimestampStr;
26 llvm::raw_svector_ostream
OS(TimestampStr);
30 llvm::SmallString<256> FinalPrefix(ProfilePrefix);
31 llvm::sys::path::append(FinalPrefix, TimestampStr);
35 llvm::sys::path::filename(SourceFile) +
".json")
39void ClangTidyProfiling::printUserFriendlyTable(llvm::raw_ostream &
OS) {
44void ClangTidyProfiling::printAsJSON(llvm::raw_ostream &
OS) {
46 OS << R
"("file": ")" << Storage->SourceFilename << "\",\n";
47 OS << R
"("timestamp": ")" << Storage->Timestamp << "\",\n";
48 OS <<
"\"profile\": {\n";
49 TG->printJSONValues(
OS,
"");
55void ClangTidyProfiling::storeProfileData() {
56 assert(Storage &&
"We should have a filename.");
58 llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
59 llvm::sys::path::remove_filename(OutputDirectory);
60 if (std::error_code EC = llvm::sys::fs::create_directories(OutputDirectory)) {
61 llvm::errs() <<
"Unable to create output directory '" << OutputDirectory
62 <<
"': " << EC.message() <<
"\n";
67 llvm::raw_fd_ostream
OS(Storage->StoreFilename, EC, llvm::sys::fs::OF_None);
69 llvm::errs() <<
"Error opening output file '" << Storage->StoreFilename
70 <<
"': " << EC.message() <<
"\n";
78 : Storage(std::move(Storage)) {}
81 TG.emplace(
"clang-tidy",
"clang-tidy checks profiling",
Records);
84 printUserFriendlyTable(llvm::errs());
llvm::raw_string_ostream OS
llvm::StringMap< llvm::TimeRecord > Records
ClangTidyProfiling()=default
std::string StoreFilename
llvm::sys::TimePoint Timestamp