X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FTimer.cpp;h=077995d9fb8993a21d4a07120d20e1c366b0854a;hb=3daae2701b76293c31c1cbdafc9782352321e1f0;hp=b0012ceb51819a0285aedf02c592864ea729470d;hpb=f976c856fcc5055f3fc7d9f070d72c2d027c1d9d;p=oota-llvm.git diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index b0012ceb518..077995d9fb8 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -13,11 +13,12 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Streams.h" #include "llvm/System/Process.h" #include #include #include -#include #include using namespace llvm; @@ -26,14 +27,14 @@ namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); } // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy // of constructor/destructor ordering being unspecified by C++. Basically the -// problem is that a Statistic<> object gets destroyed, which ends up calling +// problem is that a Statistic object gets destroyed, which ends up calling // 'GetLibSupportInfoOutputFile()' (below), which calls this function. // LibSupportInfoOutputFilename used to be a global variable, but sometimes it // would get destroyed before the Statistic, causing havoc to ensue. We "fix" // this by creating the string the first time it is needed and never destroying // it. +static ManagedStatic LibSupportInfoOutputFilename; static std::string &getLibSupportInfoOutputFilename() { - static std::string *LibSupportInfoOutputFilename = new std::string(); return *LibSupportInfoOutputFilename; } @@ -127,7 +128,7 @@ static TimeRecord getTimeRecord(bool Start) { return Result; } -static std::vector ActiveTimers; +static ManagedStatic > ActiveTimers; void Timer::startTimer() { Started = true; @@ -137,7 +138,7 @@ void Timer::startTimer() { SystemTime -= TR.SystemTime; MemUsed -= TR.MemUsed; PeakMemBase = TR.MemUsed; - ActiveTimers.push_back(this); + ActiveTimers->push_back(this); } void Timer::stopTimer() { @@ -147,13 +148,13 @@ void Timer::stopTimer() { SystemTime += TR.SystemTime; MemUsed += TR.MemUsed; - if (ActiveTimers.back() == this) { - ActiveTimers.pop_back(); + if (ActiveTimers->back() == this) { + ActiveTimers->pop_back(); } else { std::vector::iterator I = - std::find(ActiveTimers.begin(), ActiveTimers.end(), this); - assert(I != ActiveTimers.end() && "stop but no startTimer?"); - ActiveTimers.erase(I); + std::find(ActiveTimers->begin(), ActiveTimers->end(), this); + assert(I != ActiveTimers->end() && "stop but no startTimer?"); + ActiveTimers->erase(I); } } @@ -172,8 +173,8 @@ void Timer::sum(const Timer &T) { void Timer::addPeakMemoryMeasurement() { size_t MemUsed = getMemUsage(); - for (std::vector::iterator I = ActiveTimers.begin(), - E = ActiveTimers.end(); I != E; ++I) + for (std::vector::iterator I = ActiveTimers->begin(), + E = ActiveTimers->end(); I != E; ++I) (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase); } @@ -181,14 +182,14 @@ void Timer::addPeakMemoryMeasurement() { // NamedRegionTimer Implementation //===----------------------------------------------------------------------===// -static Timer &getNamedRegionTimer(const std::string &Name) { - static std::map NamedTimers; +static ManagedStatic > NamedTimers; - std::map::iterator I = NamedTimers.lower_bound(Name); - if (I != NamedTimers.end() && I->first == Name) +static Timer &getNamedRegionTimer(const std::string &Name) { + std::map::iterator I = NamedTimers->lower_bound(Name); + if (I != NamedTimers->end() && I->first == Name) return I->second; - return NamedTimers.insert(I, std::make_pair(Name, Timer(Name)))->second; + return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second; } NamedRegionTimer::NamedRegionTimer(const std::string &Name) @@ -262,17 +263,17 @@ std::ostream * llvm::GetLibSupportInfoOutputFile() { std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename(); if (LibSupportInfoOutputFilename.empty()) - return &std::cerr; + return cerr.stream(); if (LibSupportInfoOutputFilename == "-") - return &std::cout; + return cout.stream(); std::ostream *Result = new std::ofstream(LibSupportInfoOutputFilename.c_str(), std::ios::app); if (!Result->good()) { - std::cerr << "Error opening info-output-file '" - << LibSupportInfoOutputFilename << " for appending!\n"; + cerr << "Error opening info-output-file '" + << LibSupportInfoOutputFilename << " for appending!\n"; delete Result; - return &std::cerr; + return cerr.stream(); } return Result; } @@ -341,7 +342,7 @@ void TimerGroup::removeTimer() { TimersToPrint.clear(); - if (OutStream != &std::cerr && OutStream != &std::cout) + if (OutStream != cerr.stream() && OutStream != cout.stream()) delete OutStream; // Close the file... }