aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/lib/Support/DebugCounter.cpp
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:45:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:01 +0300
commit2d37894b1b037cf24231090eda8589bbb44fb6fc (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/llvm12/lib/Support/DebugCounter.cpp
parent718c552901d703c502ccbefdfc3c9028d608b947 (diff)
downloadydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/Support/DebugCounter.cpp')
-rw-r--r--contrib/libs/llvm12/lib/Support/DebugCounter.cpp268
1 files changed, 134 insertions, 134 deletions
diff --git a/contrib/libs/llvm12/lib/Support/DebugCounter.cpp b/contrib/libs/llvm12/lib/Support/DebugCounter.cpp
index a14fa6098e..7bb231c792 100644
--- a/contrib/libs/llvm12/lib/Support/DebugCounter.cpp
+++ b/contrib/libs/llvm12/lib/Support/DebugCounter.cpp
@@ -1,135 +1,135 @@
-#include "llvm/Support/DebugCounter.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/ManagedStatic.h"
-
-using namespace llvm;
-
-namespace {
-// This class overrides the default list implementation of printing so we
-// can pretty print the list of debug counter options. This type of
-// dynamic option is pretty rare (basically this and pass lists).
-class DebugCounterList : public cl::list<std::string, DebugCounter> {
-private:
- using Base = cl::list<std::string, DebugCounter>;
-
-public:
- template <class... Mods>
- explicit DebugCounterList(Mods &&... Ms) : Base(std::forward<Mods>(Ms)...) {}
-
-private:
- void printOptionInfo(size_t GlobalWidth) const override {
- // This is a variant of from generic_parser_base::printOptionInfo. Sadly,
- // it's not easy to make it more usable. We could get it to print these as
- // options if we were a cl::opt and registered them, but lists don't have
- // options, nor does the parser for std::string. The other mechanisms for
- // options are global and would pollute the global namespace with our
- // counters. Rather than go that route, we have just overridden the
- // printing, which only a few things call anyway.
- outs() << " -" << ArgStr;
- // All of the other options in CommandLine.cpp use ArgStr.size() + 6 for
- // width, so we do the same.
- Option::printHelpStr(HelpStr, GlobalWidth, ArgStr.size() + 6);
- const auto &CounterInstance = DebugCounter::instance();
- for (const auto &Name : CounterInstance) {
- const auto Info =
- CounterInstance.getCounterInfo(CounterInstance.getCounterId(Name));
- size_t NumSpaces = GlobalWidth - Info.first.size() - 8;
- outs() << " =" << Info.first;
- outs().indent(NumSpaces) << " - " << Info.second << '\n';
- }
- }
-};
-} // namespace
-
-// Create our command line option.
-static DebugCounterList DebugCounterOption(
- "debug-counter", cl::Hidden,
- 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
-// debug-counter option defined above.
-void DebugCounter::push_back(const std::string &Val) {
- if (Val.empty())
- return;
- // The strings should come in as counter=value
- auto CounterPair = StringRef(Val).split('=');
- if (CounterPair.second.empty()) {
- errs() << "DebugCounter Error: " << Val << " does not have an = in it\n";
- return;
- }
- // Now we have counter=value.
- // First, process value.
- int64_t CounterVal;
- if (CounterPair.second.getAsInteger(0, CounterVal)) {
- errs() << "DebugCounter Error: " << CounterPair.second
- << " is not a number\n";
- return;
- }
- // Now we need to see if this is the skip or the count, remove the suffix, and
- // add it to the counter values.
- if (CounterPair.first.endswith("-skip")) {
- auto CounterName = CounterPair.first.drop_back(5);
- unsigned CounterID = getCounterId(std::string(CounterName));
- if (!CounterID) {
- errs() << "DebugCounter Error: " << CounterName
- << " is not a registered counter\n";
- return;
- }
- enableAllCounters();
-
- 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(std::string(CounterName));
- if (!CounterID) {
- errs() << "DebugCounter Error: " << CounterName
- << " is not a registered counter\n";
- return;
- }
- enableAllCounters();
-
- CounterInfo &Counter = Counters[CounterID];
- Counter.StopAfter = CounterVal;
- Counter.IsSet = true;
- } else {
- errs() << "DebugCounter Error: " << CounterPair.first
- << " does not end with -skip or -count\n";
- }
-}
-
-void DebugCounter::print(raw_ostream &OS) const {
- SmallVector<StringRef, 16> CounterNames(RegisteredCounters.begin(),
- RegisteredCounters.end());
+#include "llvm/Support/DebugCounter.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/ManagedStatic.h"
+
+using namespace llvm;
+
+namespace {
+// This class overrides the default list implementation of printing so we
+// can pretty print the list of debug counter options. This type of
+// dynamic option is pretty rare (basically this and pass lists).
+class DebugCounterList : public cl::list<std::string, DebugCounter> {
+private:
+ using Base = cl::list<std::string, DebugCounter>;
+
+public:
+ template <class... Mods>
+ explicit DebugCounterList(Mods &&... Ms) : Base(std::forward<Mods>(Ms)...) {}
+
+private:
+ void printOptionInfo(size_t GlobalWidth) const override {
+ // This is a variant of from generic_parser_base::printOptionInfo. Sadly,
+ // it's not easy to make it more usable. We could get it to print these as
+ // options if we were a cl::opt and registered them, but lists don't have
+ // options, nor does the parser for std::string. The other mechanisms for
+ // options are global and would pollute the global namespace with our
+ // counters. Rather than go that route, we have just overridden the
+ // printing, which only a few things call anyway.
+ outs() << " -" << ArgStr;
+ // All of the other options in CommandLine.cpp use ArgStr.size() + 6 for
+ // width, so we do the same.
+ Option::printHelpStr(HelpStr, GlobalWidth, ArgStr.size() + 6);
+ const auto &CounterInstance = DebugCounter::instance();
+ for (const auto &Name : CounterInstance) {
+ const auto Info =
+ CounterInstance.getCounterInfo(CounterInstance.getCounterId(Name));
+ size_t NumSpaces = GlobalWidth - Info.first.size() - 8;
+ outs() << " =" << Info.first;
+ outs().indent(NumSpaces) << " - " << Info.second << '\n';
+ }
+ }
+};
+} // namespace
+
+// Create our command line option.
+static DebugCounterList DebugCounterOption(
+ "debug-counter", cl::Hidden,
+ 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
+// debug-counter option defined above.
+void DebugCounter::push_back(const std::string &Val) {
+ if (Val.empty())
+ return;
+ // The strings should come in as counter=value
+ auto CounterPair = StringRef(Val).split('=');
+ if (CounterPair.second.empty()) {
+ errs() << "DebugCounter Error: " << Val << " does not have an = in it\n";
+ return;
+ }
+ // Now we have counter=value.
+ // First, process value.
+ int64_t CounterVal;
+ if (CounterPair.second.getAsInteger(0, CounterVal)) {
+ errs() << "DebugCounter Error: " << CounterPair.second
+ << " is not a number\n";
+ return;
+ }
+ // Now we need to see if this is the skip or the count, remove the suffix, and
+ // add it to the counter values.
+ if (CounterPair.first.endswith("-skip")) {
+ auto CounterName = CounterPair.first.drop_back(5);
+ unsigned CounterID = getCounterId(std::string(CounterName));
+ if (!CounterID) {
+ errs() << "DebugCounter Error: " << CounterName
+ << " is not a registered counter\n";
+ return;
+ }
+ enableAllCounters();
+
+ 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(std::string(CounterName));
+ if (!CounterID) {
+ errs() << "DebugCounter Error: " << CounterName
+ << " is not a registered counter\n";
+ return;
+ }
+ enableAllCounters();
+
+ CounterInfo &Counter = Counters[CounterID];
+ Counter.StopAfter = CounterVal;
+ Counter.IsSet = true;
+ } else {
+ errs() << "DebugCounter Error: " << CounterPair.first
+ << " does not end with -skip or -count\n";
+ }
+}
+
+void DebugCounter::print(raw_ostream &OS) const {
+ SmallVector<StringRef, 16> CounterNames(RegisteredCounters.begin(),
+ RegisteredCounters.end());
sort(CounterNames);
-
- auto &Us = instance();
- OS << "Counters and values:\n";
- for (auto &CounterName : CounterNames) {
- unsigned CounterID = getCounterId(std::string(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 {
- print(dbgs());
-}
+
+ auto &Us = instance();
+ OS << "Counters and values:\n";
+ for (auto &CounterName : CounterNames) {
+ unsigned CounterID = getCounterId(std::string(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 {
+ print(dbgs());
+}