X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FStatistic.cpp;h=56c3b0f5659fa716e7c43cc567b9ac4d5f4bdc7d;hb=9988c292f1b6b38ecf7957ab3d6cd00b0b18c7dd;hp=3e2a183fe1904337a4dd0ba150bd615651252f2b;hpb=7e2c793a2b5c746344652b6579e958ee42fafdcc;p=oota-llvm.git diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp index 3e2a183fe19..56c3b0f5659 100644 --- a/lib/Support/Statistic.cpp +++ b/lib/Support/Statistic.cpp @@ -22,13 +22,13 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/Mutex.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/Support/raw_ostream.h" #include #include using namespace llvm; @@ -40,7 +40,9 @@ namespace llvm { extern raw_ostream *CreateInfoOutputFile(); } /// what they did. /// static cl::opt -Enabled("stats", cl::desc("Enable statistics output from program")); +Enabled( + "stats", + cl::desc("Enable statistics output from program (available with Asserts)")); namespace { @@ -82,21 +84,7 @@ void Statistic::RegisterStatistic() { } } -namespace { - -struct NameCompare { - bool operator()(const Statistic *LHS, const Statistic *RHS) const { - int Cmp = std::strcmp(LHS->getName(), RHS->getName()); - if (Cmp != 0) return Cmp < 0; - - // Secondary key is the description. - return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0; - } -}; - -} - -// Print information when destroyed, if command line option is specified. +// Print information when destroyed, iff command line option is specified. StatisticInfo::~StatisticInfo() { llvm::PrintStatistics(); } @@ -122,7 +110,14 @@ void llvm::PrintStatistics(raw_ostream &OS) { } // Sort the fields by name. - std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(), NameCompare()); + std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(), + [](const Statistic *LHS, const Statistic *RHS) { + if (int Cmp = std::strcmp(LHS->getName(), RHS->getName())) + return Cmp < 0; + + // Secondary key is the description. + return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0; + }); // Print out the statistics header... OS << "===" << std::string(73, '-') << "===\n" @@ -142,6 +137,7 @@ void llvm::PrintStatistics(raw_ostream &OS) { } void llvm::PrintStatistics() { +#if !defined(NDEBUG) || defined(LLVM_ENABLE_STATS) StatisticInfo &Stats = *StatInfo; // Statistics not enabled? @@ -151,4 +147,17 @@ void llvm::PrintStatistics() { raw_ostream &OutStream = *CreateInfoOutputFile(); PrintStatistics(OutStream); delete &OutStream; // Close the file. +#else + // Check if the -stats option is set instead of checking + // !Stats.Stats.empty(). In release builds, Statistics operators + // do nothing, so stats are never Registered. + if (Enabled) { + // Get the stream to write to. + raw_ostream &OutStream = *CreateInfoOutputFile(); + OutStream << "Statistics are disabled. " + << "Build with asserts or with -DLLVM_ENABLE_STATS\n"; + OutStream.flush(); + delete &OutStream; // Close the file. + } +#endif }