summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/DebugCounter.cpp
diff options
context:
space:
mode:
authorZhizhou Yang <zhizhouyang@gmail.com>2018-10-23 21:51:56 +0000
committerZhizhou Yang <zhizhouyang@gmail.com>2018-10-23 21:51:56 +0000
commit13f76f84bc8f6a0bad31f56639a12f43f938b0b9 (patch)
treed90f240f285ff923829f659ae7c9e89234a7fd71 /llvm/lib/Support/DebugCounter.cpp
parent3ef53e10d3a6bdefdf6e0974775ca0edafc5a91d (diff)
downloadbcm5719-llvm-13f76f84bc8f6a0bad31f56639a12f43f938b0b9.tar.gz
bcm5719-llvm-13f76f84bc8f6a0bad31f56639a12f43f938b0b9.zip
Print out DebugCounter info with -print-debug-counter
Summary: This patch will print out {Counter, Skip, StopAfter} info of all passes which have DebugCounter set at destruction. It can be used to monitor how many times does certain transformation happen in a pass, and also help check if -debug-counter option is set correctly. Please refer to this [[ http://lists.llvm.org/pipermail/llvm-dev/2018-July/124722.html | thread ]] for motivation. Reviewers: george.burgess.iv, davide, greened Reviewed By: greened Subscribers: kristina, llozano, mgorny, llvm-commits, mgrang Differential Revision: https://reviews.llvm.org/D50031 llvm-svn: 345085
Diffstat (limited to 'llvm/lib/Support/DebugCounter.cpp')
-rw-r--r--llvm/lib/Support/DebugCounter.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp
index 9c8260dbe07..6598103658d 100644
--- a/llvm/lib/Support/DebugCounter.cpp
+++ b/llvm/lib/Support/DebugCounter.cpp
@@ -49,8 +49,18 @@ static DebugCounterList DebugCounterOption(
cl::desc("Comma separated list of debug counter skip and count"),
cl::CommaSeparated, cl::ZeroOrMore, cl::location(DebugCounter::instance()));
+static cl::opt<bool> PrintDebugCounter(
+ "print-debug-counter", cl::Hidden, cl::init(false), cl::Optional,
+ cl::desc("Print out debug counter info after all counters accumulated"));
+
static ManagedStatic<DebugCounter> DC;
+// Print information when destroyed, iff command line option is specified.
+DebugCounter::~DebugCounter() {
+ if (isCountingEnabled() && PrintDebugCounter)
+ print(dbgs());
+}
+
DebugCounter &DebugCounter::instance() { return *DC; }
// This is called by the command line parser when it sees a value for the
@@ -107,11 +117,18 @@ void DebugCounter::push_back(const std::string &Val) {
}
void DebugCounter::print(raw_ostream &OS) const {
+ SmallVector<StringRef, 16> CounterNames(RegisteredCounters.begin(),
+ RegisteredCounters.end());
+ sort(CounterNames.begin(), CounterNames.end());
+
+ auto &Us = instance();
OS << "Counters and values:\n";
- for (const auto &KV : Counters)
- OS << left_justify(RegisteredCounters[KV.first], 32) << ": {"
- << KV.second.Count << "," << KV.second.Skip << ","
- << KV.second.StopAfter << "}\n";
+ for (auto &CounterName : CounterNames) {
+ unsigned CounterID = getCounterId(CounterName);
+ OS << left_justify(RegisteredCounters[CounterID], 32) << ": {"
+ << Us.Counters[CounterID].Count << "," << Us.Counters[CounterID].Skip
+ << "," << Us.Counters[CounterID].StopAfter << "}\n";
+ }
}
LLVM_DUMP_METHOD void DebugCounter::dump() const {
OpenPOWER on IntegriCloud