X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FStatistic.cpp;h=f6645c6ae401132d93e7e12a2b15c7c6fcec1031;hb=8f77daef04355c00b78b645f5aae5694e7a8b631;hp=79b19503b72c5ec65abe3e02e8da3475b0343673;hpb=f3f4fd50f2913faa9a7526b48f1cd5bd14ea5f8e;p=oota-llvm.git diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp index 79b19503b72..f6645c6ae40 100644 --- a/lib/Support/Statistic.cpp +++ b/lib/Support/Statistic.cpp @@ -1,4 +1,4 @@ -//===-- StatisticReporter.cpp - Easy way to expose stats information -------==// +//===-- Statistic.cpp - Easy way to expose stats information --------------===// // // This file implements the 'Statistic' class, which is designed to be an easy // way to expose various success metrics from passes. These statistics are @@ -14,18 +14,88 @@ // //===----------------------------------------------------------------------===// -#include "Support/StatisticReporter.h" +#include "Support/Statistic.h" #include "Support/CommandLine.h" #include +#include +#include -static cl::Flag Enabled("stats", "Enable statistics output from program"); +bool DebugFlag; // DebugFlag - Exported boolean set by the -debug option + +unsigned StatisticBase::NumStats = 0; + +// -stats - Command line option to cause transformations to emit stats about +// what they did. +// +static cl::opt +Enabled("stats", cl::desc("Enable statistics output from program")); + +#ifndef NDEBUG +// -debug - Command line option to enable the DEBUG statements in the passes. +// This flag may only be enabled in debug builds. +static cl::opt +Debug("debug", cl::desc("Enable debug output"), cl::Hidden, + cl::location(DebugFlag)); +#endif + +struct StatRecord { + std::string Value; + const char *Name, *Desc; + + StatRecord(const std::string V, const char *N, const char *D) + : Value(V), Name(N), Desc(D) {} + + bool operator<(const StatRecord &SR) const { + return std::strcmp(Name, SR.Name) < 0; + } + + void print(unsigned ValFieldSize, unsigned NameFieldSize) { + std::cerr << std::string(ValFieldSize-Value.length(), ' ') + << Value << " " << Name + << std::string(NameFieldSize-std::strlen(Name), ' ') + << " - " << Desc << "\n"; + } +}; + +static std::vector *AccumStats = 0; // Print information when destroyed, iff command line option is specified void StatisticBase::destroy() const { if (Enabled && hasSomeData()) { - std::cerr.width(7); - printValue(std::cerr); - std::cerr.width(0); - std::cerr << "\t" << Name << "\n"; + if (AccumStats == 0) + AccumStats = new std::vector(); + + std::ostringstream Out; + printValue(Out); + AccumStats->push_back(StatRecord(Out.str(), Name, Desc)); + } + + if (--NumStats == 0 && AccumStats) { + // Figure out how long the biggest Value and Name fields are... + unsigned MaxNameLen = 0, MaxValLen = 0; + for (unsigned i = 0, e = AccumStats->size(); i != e; ++i) { + MaxValLen = std::max(MaxValLen, + (unsigned)(*AccumStats)[i].Value.length()); + MaxNameLen = std::max(MaxNameLen, + (unsigned)std::strlen((*AccumStats)[i].Name)); + } + + // Sort the fields... + std::stable_sort(AccumStats->begin(), AccumStats->end()); + + // Print out the statistics header... + std::cerr << "===" << std::string(73, '-') << "===\n" + << " ... Statistics Collected ...\n" + << "===" << std::string(73, '-') << "===\n\n"; + + // Print all of the statistics accumulated... + for (unsigned i = 0, e = AccumStats->size(); i != e; ++i) + (*AccumStats)[i].print(MaxValLen, MaxNameLen); + + std::cerr << std::endl; // Flush the output stream... + + // Free all accumulated statistics... + delete AccumStats; + AccumStats = 0; } }