summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
diff options
context:
space:
mode:
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