summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-05-08 13:14:21 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-05-08 13:14:21 +0000
commit12152511518ef370a24923539a3ac792e387789f (patch)
tree7d173ae59d5167e8b88151fb975625ceeccd7b9d /clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
parent8f266dbbdcddb0fb9df96cb02b40550cdfdd5dd6 (diff)
downloadbcm5719-llvm-12152511518ef370a24923539a3ac792e387789f.tar.gz
bcm5719-llvm-12152511518ef370a24923539a3ac792e387789f.zip
[clang-tidy] Profile is a per-AST (per-TU) data.
Summary: As discussed in D45931, currently, profiling output of clang-tidy is somewhat not great. It outputs one profile at the end of the execution, and that profile contains the data from the last TU that was processed. So if the tool run on multiple TU's, the data is not accumulated, it is simply discarded. It would be nice to improve this. This differential is the first step - make this profiling info per-TU, and output it after the tool has finished processing each TU. In particular, when `ClangTidyASTConsumer` destructor runs. Next step will be to add a CSV (JSON?) printer to store said profiles under user-specified directory prefix. Reviewers: alexfh, sbenza Reviewed By: alexfh Subscribers: Eugene.Zelenko, mgorny, xazax.hun, mgrang, klimek, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D46504 llvm-svn: 331763
Diffstat (limited to 'clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
new file mode 100644
index 00000000000..d332942fa24
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
@@ -0,0 +1,65 @@
+//===--- ClangTidyProfiling.cpp - clang-tidy --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ClangTidyProfiling.h"
+#include "llvm/ADT/STLExtras.h"
+
+#define DEBUG_TYPE "clang-tidy-profiling"
+
+namespace clang {
+namespace tidy {
+
+void ClangTidyProfiling::preprocess() {
+ // Convert from a insertion-friendly map to sort-friendly vector.
+ Timers.clear();
+ Timers.reserve(Records.size());
+ for (const auto &P : Records) {
+ Timers.emplace_back(P.getValue(), P.getKey());
+ Total += P.getValue();
+ }
+ assert(Timers.size() == Records.size() && "Size mismatch after processing");
+
+ // We want the measurements to be sorted by decreasing time spent.
+ llvm::sort(Timers.begin(), Timers.end());
+}
+
+void ClangTidyProfiling::printProfileData(llvm::raw_ostream &OS) const {
+ 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();
+}
+
+ClangTidyProfiling::~ClangTidyProfiling() {
+ preprocess();
+ printProfileData(llvm::errs());
+}
+
+} // namespace tidy
+} // namespace clang
OpenPOWER on IntegriCloud