diff options
author | Samuel Benzaquen <sbenza@google.com> | 2014-10-23 17:23:20 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2014-10-23 17:23:20 +0000 |
commit | 07babf8b5c80f56ababdb1959cc54e6cc22f903b (patch) | |
tree | c73f80214fbb0966a19fc60a44e585cf2bef168e /clang-tidy/tool/ClangTidyMain.cpp | |
parent | 41094c7cc6512fd687f64312c2d95b6a33fc22fc (diff) |
Add flag --enable-check-profile to clang-tidy.
Summary:
Add flag --enable-check-profile to clang-tidy.
It turns on per-matcher profiles in MatchFinder and prints a report to
stderr at the end.
Reviewers: alexfh
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D5937
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@220491 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/tool/ClangTidyMain.cpp')
-rw-r--r-- | clang-tidy/tool/ClangTidyMain.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/clang-tidy/tool/ClangTidyMain.cpp b/clang-tidy/tool/ClangTidyMain.cpp index 8f45eaab..72d841e3 100644 --- a/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tidy/tool/ClangTidyMain.cpp @@ -98,6 +98,11 @@ DumpConfig("dump-config", cl::desc("Dumps configuration in the YAML format to stdout."), cl::init(false), cl::cat(ClangTidyCategory)); +static cl::opt<bool> EnableCheckProfile( + "enable-check-profile", + cl::desc("Enable per-check timing profiles, and print a report to stderr."), + cl::init(false), cl::cat(ClangTidyCategory)); + static cl::opt<bool> AnalyzeTemporaryDtors( "analyze-temporary-dtors", cl::desc("Enable temporary destructor-aware analysis in\n" @@ -143,6 +148,45 @@ static void printStats(const ClangTidyStats &Stats) { } } +static void printProfileData(const ProfileData &Profile, + llvm::raw_ostream &OS) { + // Time is first to allow for sorting by it. + std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers; + TimeRecord Total; + + for (const auto& P : Profile.Records) { + Timers.emplace_back(P.getValue(), P.getKey()); + Total += P.getValue(); + } + + std::sort(Timers.begin(), Timers.end()); + + std::string Line = "===" + std::string(73, '-') + "===\n"; + OS << Line; + + if (Total.getUserTime()) + OS << " ---User Time---"; + if (Total.getSystemTime()) + OS << " --System Time--"; + if (Total.getProcessTime()) + OS << " --User+System--"; + OS << " ---Wall Time---"; + if (Total.getMemUsed()) + OS << " ---Mem---"; + OS << " --- Name ---\n"; + + // Loop through all of the timing data, printing it out. + for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) { + I->first.print(Total, OS); + OS << I->second << '\n'; + } + + Total.print(Total, OS); + OS << "Total\n"; + OS << Line << "\n"; + OS.flush(); +} + std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() { ClangTidyGlobalOptions GlobalOptions; if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) { @@ -220,10 +264,13 @@ int clangTidyMain(int argc, const char **argv) { return 1; } + ProfileData Profile; + std::vector<ClangTidyError> Errors; ClangTidyStats Stats = runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(), - OptionsParser.getSourcePathList(), &Errors); + OptionsParser.getSourcePathList(), &Errors, + EnableCheckProfile ? &Profile : nullptr); handleErrors(Errors, Fix); if (!ExportFixes.empty() && !Errors.empty()) { @@ -237,6 +284,9 @@ int clangTidyMain(int argc, const char **argv) { } printStats(Stats); + if (EnableCheckProfile) + printProfileData(Profile, llvm::errs()); + return 0; } |