X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FStatistic.cpp;h=1141086c3f3c34f2b49998f0446ffe7222db0967;hb=a3c58f1c060bb97371ad06bf10c4836845e0f5a3;hp=6345fbfcfcf83a57aeb7964af1280689376b06c2;hpb=9550dc2df2aad33e92febc0e3a15aca372639a10;p=oota-llvm.git diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp index 6345fbfcfcf..1141086c3f3 100644 --- a/lib/Support/Statistic.cpp +++ b/lib/Support/Statistic.cpp @@ -20,6 +20,9 @@ #include #include +// GetLibSupportInfoOutputFile - Return a file stream to print our output on... +std::ostream *GetLibSupportInfoOutputFile(); + bool DebugFlag; // DebugFlag - Exported boolean set by the -debug option unsigned StatisticBase::NumStats = 0; @@ -30,10 +33,13 @@ unsigned StatisticBase::NumStats = 0; 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; @@ -46,11 +52,12 @@ struct StatRecord { 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"; + void print(unsigned ValFieldSize, unsigned NameFieldSize, + std::ostream &OS) { + OS << std::string(ValFieldSize-Value.length(), ' ') + << Value << " " << Name + << std::string(NameFieldSize-std::strlen(Name), ' ') + << " - " << Desc << "\n"; } }; @@ -68,6 +75,8 @@ void StatisticBase::destroy() const { } if (--NumStats == 0 && AccumStats) { + std::ostream *OutStream = GetLibSupportInfoOutputFile(); + // 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) { @@ -81,18 +90,20 @@ void StatisticBase::destroy() const { 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"; + *OutStream << "===" << 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); + (*AccumStats)[i].print(MaxValLen, MaxNameLen, *OutStream); - std::cerr << std::endl; // Flush the output stream... + *OutStream << std::endl; // Flush the output stream... // Free all accumulated statistics... delete AccumStats; AccumStats = 0; + if (OutStream != &std::cerr && OutStream != &std::cout) + delete OutStream; // Close the file... } }