diff options
| author | 2019-06-23 21:36:31 +0000 | |
|---|---|---|
| committer | 2019-06-23 21:36:31 +0000 | |
| commit | 23f101f37937a1bd4a29726cab2f76e0fb038b35 (patch) | |
| tree | f7da7d6b32c2e07114da399150bfa88d72187012 /gnu/llvm/lib/Support/DebugCounter.cpp | |
| parent | sort previous; ok deraadt (diff) | |
| download | wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.tar.xz wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.zip | |
Import LLVM 8.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/lib/Support/DebugCounter.cpp')
| -rw-r--r-- | gnu/llvm/lib/Support/DebugCounter.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/gnu/llvm/lib/Support/DebugCounter.cpp b/gnu/llvm/lib/Support/DebugCounter.cpp index 9c12de0776a..6598103658d 100644 --- a/gnu/llvm/lib/Support/DebugCounter.cpp +++ b/gnu/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 @@ -83,8 +93,10 @@ void DebugCounter::push_back(const std::string &Val) { return; } enableAllCounters(); - Counters[CounterID].Skip = CounterVal; - Counters[CounterID].IsSet = true; + + CounterInfo &Counter = Counters[CounterID]; + Counter.Skip = CounterVal; + Counter.IsSet = true; } else if (CounterPair.first.endswith("-count")) { auto CounterName = CounterPair.first.drop_back(6); unsigned CounterID = getCounterId(CounterName); @@ -94,8 +106,10 @@ void DebugCounter::push_back(const std::string &Val) { return; } enableAllCounters(); - Counters[CounterID].StopAfter = CounterVal; - Counters[CounterID].IsSet = true; + + CounterInfo &Counter = Counters[CounterID]; + Counter.StopAfter = CounterVal; + Counter.IsSet = true; } else { errs() << "DebugCounter Error: " << CounterPair.first << " does not end with -skip or -count\n"; @@ -103,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 { |
