X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FTimer.cpp;h=5d493b8a15e2e329b073362fea01235e384468b3;hb=311ca2e51f1c9be1b81a73e7acef4e3564b71ad9;hp=98001287d9a03a0cf1a5eeedf32182197900a6de;hpb=96a54db5e763c19f556a1b54ad2956cc91b81cb8;p=oota-llvm.git diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index 98001287d9a..5d493b8a15e 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -1,4 +1,11 @@ //===-- Timer.cpp - Interval Timing Support -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// // // Interval Timing implementation. // @@ -6,16 +13,19 @@ #include "Support/Timer.h" #include "Support/CommandLine.h" - #include "Config/sys/resource.h" #include "Config/sys/time.h" #include "Config/unistd.h" #include "Config/malloc.h" -#include "Config/stdio.h" #include #include #include #include +#include +using namespace llvm; + +// GetLibSupportInfoOutputFile - Return a file stream to print our output on... +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 @@ -114,9 +124,9 @@ static TimeRecord getTimeRecord(bool Start) { gettimeofday(&T, 0); if (!Start) { - MemUsed = getMemUsage(); if (getrusage(RUSAGE_SELF, &RU)) perror("getrusage call failed: -time-passes info incorrect!"); + MemUsed = getMemUsage(); } TimeRecord Result; @@ -178,6 +188,23 @@ void Timer::addPeakMemoryMeasurement() { (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase); } +//===----------------------------------------------------------------------===// +// NamedRegionTimer Implementation +//===----------------------------------------------------------------------===// + +static Timer &getNamedRegionTimer(const std::string &Name) { + static std::map NamedTimers; + + 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; +} + +NamedRegionTimer::NamedRegionTimer(const std::string &Name) + : TimeRegion(getNamedRegionTimer(Name)) {} + //===----------------------------------------------------------------------===// // TimerGroup Implementation @@ -242,7 +269,8 @@ void Timer::print(const Timer &Total, std::ostream &OS) { } // GetLibSupportInfoOutputFile - Return a file stream to print our output on... -std::ostream *GetLibSupportInfoOutputFile() { +std::ostream * +llvm::GetLibSupportInfoOutputFile() { std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename(); if (LibSupportInfoOutputFilename.empty()) return &std::cerr; @@ -326,3 +354,4 @@ void TimerGroup::removeTimer() { DefaultTimerGroup = 0; } } +