2002-10-01 21:36:54 +02:00
|
|
|
//===-- Timer.cpp - Interval Timing Support -------------------------------===//
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:55:34 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-01 21:36:54 +02:00
|
|
|
//
|
|
|
|
// Interval Timing implementation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-05 02:28:58 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-10-04 23:52:35 +02:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-08-23 10:43:55 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2004-12-20 01:59:04 +01:00
|
|
|
#include "llvm/System/Process.h"
|
2004-12-20 04:59:23 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2003-10-06 17:02:31 +02:00
|
|
|
#include <map>
|
2003-12-14 22:27:33 +01:00
|
|
|
using namespace llvm;
|
2003-05-09 22:05:44 +02:00
|
|
|
|
2004-06-07 21:34:51 +02:00
|
|
|
// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
|
2009-08-23 10:43:55 +02:00
|
|
|
namespace llvm { extern raw_ostream *GetLibSupportInfoOutputFile(); }
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2003-07-31 21:38:34 +02:00
|
|
|
// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
|
|
|
|
// of constructor/destructor ordering being unspecified by C++. Basically the
|
2006-12-06 18:46:33 +01:00
|
|
|
// problem is that a Statistic object gets destroyed, which ends up calling
|
2003-07-31 21:38:34 +02:00
|
|
|
// 'GetLibSupportInfoOutputFile()' (below), which calls this function.
|
|
|
|
// LibSupportInfoOutputFilename used to be a global variable, but sometimes it
|
2004-12-14 04:55:21 +01:00
|
|
|
// 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.
|
2006-10-04 23:52:35 +02:00
|
|
|
static ManagedStatic<std::string> LibSupportInfoOutputFilename;
|
2003-07-31 21:38:34 +02:00
|
|
|
static std::string &getLibSupportInfoOutputFilename() {
|
2004-12-14 04:55:21 +01:00
|
|
|
return *LibSupportInfoOutputFilename;
|
2003-07-31 21:38:34 +02:00
|
|
|
}
|
2002-10-01 21:36:54 +02:00
|
|
|
|
2009-06-23 22:52:29 +02:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > TimerLock;
|
|
|
|
|
2003-01-31 00:08:50 +01:00
|
|
|
namespace {
|
2008-04-24 01:15:23 +02:00
|
|
|
static cl::opt<bool>
|
2003-01-31 00:08:50 +01:00
|
|
|
TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
|
|
|
|
"tracking (this may be slow)"),
|
|
|
|
cl::Hidden);
|
2003-05-09 22:05:44 +02:00
|
|
|
|
2008-04-24 01:15:23 +02:00
|
|
|
static cl::opt<std::string, true>
|
2003-08-02 00:15:15 +02:00
|
|
|
InfoOutputFilename("info-output-file", cl::value_desc("filename"),
|
2003-05-09 22:05:44 +02:00
|
|
|
cl::desc("File to append -stats and -timer output to"),
|
2003-07-31 21:38:34 +02:00
|
|
|
cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
|
2003-01-31 00:08:50 +01:00
|
|
|
}
|
|
|
|
|
2009-06-23 18:36:10 +02:00
|
|
|
static TimerGroup *DefaultTimerGroup = 0;
|
2002-10-01 21:36:54 +02:00
|
|
|
static TimerGroup *getDefaultTimerGroup() {
|
2009-06-23 19:33:37 +02:00
|
|
|
TimerGroup* tmp = DefaultTimerGroup;
|
|
|
|
sys::MemoryFence();
|
|
|
|
if (!tmp) {
|
|
|
|
llvm_acquire_global_lock();
|
|
|
|
tmp = DefaultTimerGroup;
|
|
|
|
if (!tmp) {
|
|
|
|
tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
|
|
|
|
sys::MemoryFence();
|
|
|
|
DefaultTimerGroup = tmp;
|
|
|
|
}
|
|
|
|
llvm_release_global_lock();
|
|
|
|
}
|
2009-11-07 07:33:12 +01:00
|
|
|
|
2009-06-23 19:33:37 +02:00
|
|
|
return tmp;
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Timer::Timer(const std::string &N)
|
2002-11-18 22:47:09 +01:00
|
|
|
: Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
|
2002-10-01 21:36:54 +02:00
|
|
|
Started(false), TG(getDefaultTimerGroup()) {
|
|
|
|
TG->addTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer::Timer(const std::string &N, TimerGroup &tg)
|
2002-11-18 22:47:09 +01:00
|
|
|
: Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
|
2002-10-01 21:36:54 +02:00
|
|
|
Started(false), TG(&tg) {
|
|
|
|
TG->addTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer::Timer(const Timer &T) {
|
|
|
|
TG = T.TG;
|
|
|
|
if (TG) TG->addTimer();
|
|
|
|
operator=(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Copy ctor, initialize with no TG member.
|
|
|
|
Timer::Timer(bool, const Timer &T) {
|
|
|
|
TG = T.TG; // Avoid assertion in operator=
|
|
|
|
operator=(T); // Copy contents
|
|
|
|
TG = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Timer::~Timer() {
|
|
|
|
if (TG) {
|
|
|
|
if (Started) {
|
|
|
|
Started = false;
|
|
|
|
TG->addTimerToPrint(*this);
|
|
|
|
}
|
|
|
|
TG->removeTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-08 21:15:57 +01:00
|
|
|
static inline size_t getMemUsage() {
|
2004-12-27 09:03:04 +01:00
|
|
|
if (TrackSpace)
|
2005-01-08 21:15:57 +01:00
|
|
|
return sys::Process::GetMallocUsage();
|
2004-12-27 09:03:04 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
struct TimeRecord {
|
2009-06-23 22:17:22 +02:00
|
|
|
double Elapsed, UserTime, SystemTime;
|
|
|
|
ssize_t MemUsed;
|
2002-10-01 21:36:54 +02:00
|
|
|
};
|
|
|
|
|
2002-11-18 22:47:09 +01:00
|
|
|
static TimeRecord getTimeRecord(bool Start) {
|
2004-12-20 01:59:04 +01:00
|
|
|
TimeRecord Result;
|
2004-06-07 21:34:51 +02:00
|
|
|
|
2004-12-20 01:59:04 +01:00
|
|
|
sys::TimeValue now(0,0);
|
|
|
|
sys::TimeValue user(0,0);
|
|
|
|
sys::TimeValue sys(0,0);
|
2004-06-07 21:34:51 +02:00
|
|
|
|
2009-06-23 22:17:22 +02:00
|
|
|
ssize_t MemUsed = 0;
|
2004-12-20 22:44:27 +01:00
|
|
|
if (Start) {
|
2004-12-27 09:03:04 +01:00
|
|
|
MemUsed = getMemUsage();
|
2005-03-22 04:20:38 +01:00
|
|
|
sys::Process::GetTimeUsage(now,user,sys);
|
2004-12-20 22:44:27 +01:00
|
|
|
} else {
|
|
|
|
sys::Process::GetTimeUsage(now,user,sys);
|
2005-03-22 04:20:38 +01:00
|
|
|
MemUsed = getMemUsage();
|
2004-12-20 22:44:27 +01:00
|
|
|
}
|
2002-11-18 22:47:09 +01:00
|
|
|
|
2009-06-23 22:17:22 +02:00
|
|
|
Result.Elapsed = now.seconds() + now.microseconds() / 1000000.0;
|
|
|
|
Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
|
|
|
|
Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
|
2004-12-20 22:44:27 +01:00
|
|
|
Result.MemUsed = MemUsed;
|
2002-10-01 21:36:54 +02:00
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2006-10-04 23:52:35 +02:00
|
|
|
static ManagedStatic<std::vector<Timer*> > ActiveTimers;
|
2002-11-18 22:47:09 +01:00
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
void Timer::startTimer() {
|
2009-11-17 08:06:10 +01:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2002-10-01 21:36:54 +02:00
|
|
|
Started = true;
|
2008-06-25 00:07:07 +02:00
|
|
|
ActiveTimers->push_back(this);
|
2002-11-18 22:47:09 +01:00
|
|
|
TimeRecord TR = getTimeRecord(true);
|
2002-10-01 21:36:54 +02:00
|
|
|
Elapsed -= TR.Elapsed;
|
|
|
|
UserTime -= TR.UserTime;
|
|
|
|
SystemTime -= TR.SystemTime;
|
2002-11-04 20:19:36 +01:00
|
|
|
MemUsed -= TR.MemUsed;
|
2002-11-18 22:47:09 +01:00
|
|
|
PeakMemBase = TR.MemUsed;
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::stopTimer() {
|
2009-11-17 08:06:10 +01:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2002-11-18 22:47:09 +01:00
|
|
|
TimeRecord TR = getTimeRecord(false);
|
2002-10-01 21:36:54 +02:00
|
|
|
Elapsed += TR.Elapsed;
|
|
|
|
UserTime += TR.UserTime;
|
|
|
|
SystemTime += TR.SystemTime;
|
2002-11-04 20:19:36 +01:00
|
|
|
MemUsed += TR.MemUsed;
|
2002-11-18 22:47:09 +01:00
|
|
|
|
2006-10-04 23:52:35 +02:00
|
|
|
if (ActiveTimers->back() == this) {
|
|
|
|
ActiveTimers->pop_back();
|
2002-11-18 22:47:09 +01:00
|
|
|
} else {
|
|
|
|
std::vector<Timer*>::iterator I =
|
2006-10-04 23:52:35 +02:00
|
|
|
std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
|
|
|
|
assert(I != ActiveTimers->end() && "stop but no startTimer?");
|
|
|
|
ActiveTimers->erase(I);
|
2002-11-18 22:47:09 +01:00
|
|
|
}
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::sum(const Timer &T) {
|
|
|
|
Elapsed += T.Elapsed;
|
|
|
|
UserTime += T.UserTime;
|
|
|
|
SystemTime += T.SystemTime;
|
2002-11-04 20:19:36 +01:00
|
|
|
MemUsed += T.MemUsed;
|
2002-11-18 22:47:09 +01:00
|
|
|
PeakMem += T.PeakMem;
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
|
2002-11-18 22:47:09 +01:00
|
|
|
/// addPeakMemoryMeasurement - This method should be called whenever memory
|
|
|
|
/// usage needs to be checked. It adds a peak memory measurement to the
|
|
|
|
/// currently active timers, which will be printed when the timer group prints
|
|
|
|
///
|
|
|
|
void Timer::addPeakMemoryMeasurement() {
|
2009-11-17 08:06:10 +01:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2009-06-23 22:17:22 +02:00
|
|
|
size_t MemUsed = getMemUsage();
|
2002-11-18 22:47:09 +01:00
|
|
|
|
2006-10-04 23:52:35 +02:00
|
|
|
for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
|
2009-11-17 08:06:10 +01:00
|
|
|
E = ActiveTimers->end(); I != E; ++I)
|
2009-06-23 22:17:22 +02:00
|
|
|
(*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
|
2002-11-18 22:47:09 +01:00
|
|
|
}
|
|
|
|
|
2003-10-06 17:02:31 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NamedRegionTimer Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-07-14 20:19:29 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef std::map<std::string, Timer> Name2Timer;
|
|
|
|
typedef std::map<std::string, std::pair<TimerGroup, Name2Timer> > Name2Pair;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static ManagedStatic<Name2Timer> NamedTimers;
|
|
|
|
|
|
|
|
static ManagedStatic<Name2Pair> NamedGroupedTimers;
|
2003-10-06 17:02:31 +02:00
|
|
|
|
2006-10-04 23:52:35 +02:00
|
|
|
static Timer &getNamedRegionTimer(const std::string &Name) {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2008-07-14 20:19:29 +02:00
|
|
|
Name2Timer::iterator I = NamedTimers->find(Name);
|
2008-07-11 22:58:19 +02:00
|
|
|
if (I != NamedTimers->end())
|
2003-10-06 17:02:31 +02:00
|
|
|
return I->second;
|
|
|
|
|
2006-10-04 23:52:35 +02:00
|
|
|
return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
|
2003-10-06 17:02:31 +02:00
|
|
|
}
|
|
|
|
|
2008-07-14 20:19:29 +02:00
|
|
|
static Timer &getNamedRegionTimer(const std::string &Name,
|
|
|
|
const std::string &GroupName) {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2008-07-14 20:19:29 +02:00
|
|
|
|
|
|
|
Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
|
|
|
|
if (I == NamedGroupedTimers->end()) {
|
|
|
|
TimerGroup TG(GroupName);
|
|
|
|
std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
|
|
|
|
I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
|
|
|
|
}
|
|
|
|
|
|
|
|
Name2Timer::iterator J = I->second.second.find(Name);
|
|
|
|
if (J == I->second.second.end())
|
|
|
|
J = I->second.second.insert(J,
|
|
|
|
std::make_pair(Name,
|
|
|
|
Timer(Name,
|
|
|
|
I->second.first)));
|
|
|
|
|
|
|
|
return J->second;
|
|
|
|
}
|
|
|
|
|
2003-10-06 17:02:31 +02:00
|
|
|
NamedRegionTimer::NamedRegionTimer(const std::string &Name)
|
|
|
|
: TimeRegion(getNamedRegionTimer(Name)) {}
|
|
|
|
|
2008-07-14 20:19:29 +02:00
|
|
|
NamedRegionTimer::NamedRegionTimer(const std::string &Name,
|
|
|
|
const std::string &GroupName)
|
|
|
|
: TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
|
2002-11-18 22:47:09 +01:00
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TimerGroup Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-05-09 22:05:44 +02:00
|
|
|
|
2009-08-23 10:43:55 +02:00
|
|
|
static void printVal(double Val, double Total, raw_ostream &OS) {
|
2002-10-01 21:36:54 +02:00
|
|
|
if (Total < 1e-7) // Avoid dividing by zero...
|
2003-05-09 22:05:44 +02:00
|
|
|
OS << " ----- ";
|
|
|
|
else {
|
2009-08-23 10:43:55 +02:00
|
|
|
OS << " " << format("%7.4f", Val) << " (";
|
|
|
|
OS << format("%5.1f", Val*100/Total) << "%)";
|
2003-05-09 22:05:44 +02:00
|
|
|
}
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
|
2009-08-23 10:43:55 +02:00
|
|
|
void Timer::print(const Timer &Total, raw_ostream &OS) {
|
2009-11-17 08:06:10 +01:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2002-10-01 21:36:54 +02:00
|
|
|
if (Total.UserTime)
|
2009-06-23 22:17:22 +02:00
|
|
|
printVal(UserTime, Total.UserTime, OS);
|
2002-10-01 21:36:54 +02:00
|
|
|
if (Total.SystemTime)
|
2009-06-23 22:17:22 +02:00
|
|
|
printVal(SystemTime, Total.SystemTime, OS);
|
2002-10-01 21:36:54 +02:00
|
|
|
if (Total.getProcessTime())
|
2009-06-23 22:17:22 +02:00
|
|
|
printVal(getProcessTime(), Total.getProcessTime(), OS);
|
|
|
|
printVal(Elapsed, Total.Elapsed, OS);
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2003-05-09 22:05:44 +02:00
|
|
|
OS << " ";
|
2002-10-01 21:36:54 +02:00
|
|
|
|
2003-05-09 22:05:44 +02:00
|
|
|
if (Total.MemUsed) {
|
2009-08-23 10:43:55 +02:00
|
|
|
OS << format("%9lld", (long long)MemUsed) << " ";
|
2003-05-09 22:05:44 +02:00
|
|
|
}
|
2002-11-18 22:47:09 +01:00
|
|
|
if (Total.PeakMem) {
|
2003-05-09 22:05:44 +02:00
|
|
|
if (PeakMem) {
|
2009-08-23 10:43:55 +02:00
|
|
|
OS << format("%9lld", (long long)PeakMem) << " ";
|
2003-05-09 22:05:44 +02:00
|
|
|
} else
|
|
|
|
OS << " ";
|
2002-11-18 22:47:09 +01:00
|
|
|
}
|
2003-05-09 22:05:44 +02:00
|
|
|
OS << Name << "\n";
|
2002-10-01 21:36:54 +02:00
|
|
|
|
|
|
|
Started = false; // Once printed, don't print again
|
|
|
|
}
|
|
|
|
|
2003-05-09 22:05:44 +02:00
|
|
|
// GetLibSupportInfoOutputFile - Return a file stream to print our output on...
|
2009-08-23 10:43:55 +02:00
|
|
|
raw_ostream *
|
2003-12-14 22:27:33 +01:00
|
|
|
llvm::GetLibSupportInfoOutputFile() {
|
2003-07-31 21:38:34 +02:00
|
|
|
std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
|
2003-05-09 22:05:44 +02:00
|
|
|
if (LibSupportInfoOutputFilename.empty())
|
2009-08-23 10:43:55 +02:00
|
|
|
return &errs();
|
2003-05-09 22:05:44 +02:00
|
|
|
if (LibSupportInfoOutputFilename == "-")
|
2009-08-23 10:43:55 +02:00
|
|
|
return &outs();
|
2003-05-09 22:05:44 +02:00
|
|
|
|
2009-11-07 07:33:12 +01:00
|
|
|
|
2009-08-23 10:43:55 +02:00
|
|
|
std::string Error;
|
|
|
|
raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
|
|
|
|
Error, raw_fd_ostream::F_Append);
|
|
|
|
if (Error.empty())
|
|
|
|
return Result;
|
2009-11-07 07:33:12 +01:00
|
|
|
|
2009-08-23 10:43:55 +02:00
|
|
|
errs() << "Error opening info-output-file '"
|
2006-12-07 21:28:15 +01:00
|
|
|
<< LibSupportInfoOutputFilename << " for appending!\n";
|
2009-08-23 10:43:55 +02:00
|
|
|
delete Result;
|
|
|
|
return &errs();
|
2003-05-09 22:05:44 +02:00
|
|
|
}
|
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
|
|
|
|
void TimerGroup::removeTimer() {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2002-10-01 21:36:54 +02:00
|
|
|
if (--NumTimers == 0 && !TimersToPrint.empty()) { // Print timing report...
|
|
|
|
// Sort the timers in descending order by amount of time taken...
|
|
|
|
std::sort(TimersToPrint.begin(), TimersToPrint.end(),
|
|
|
|
std::greater<Timer>());
|
|
|
|
|
|
|
|
// Figure out how many spaces to indent TimerGroup name...
|
|
|
|
unsigned Padding = (80-Name.length())/2;
|
|
|
|
if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
|
|
|
|
|
2009-08-23 10:43:55 +02:00
|
|
|
raw_ostream *OutStream = GetLibSupportInfoOutputFile();
|
2003-05-09 22:05:44 +02:00
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
++NumTimers;
|
|
|
|
{ // Scope to contain Total timer... don't allow total timer to drop us to
|
|
|
|
// zero timers...
|
|
|
|
Timer Total("TOTAL");
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
|
|
|
|
Total.sum(TimersToPrint[i]);
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
// Print out timing header...
|
2003-05-09 22:05:44 +02:00
|
|
|
*OutStream << "===" << std::string(73, '-') << "===\n"
|
|
|
|
<< std::string(Padding, ' ') << Name << "\n"
|
|
|
|
<< "===" << std::string(73, '-')
|
2005-02-09 19:41:32 +01:00
|
|
|
<< "===\n";
|
|
|
|
|
|
|
|
// If this is not an collection of ungrouped times, print the total time.
|
|
|
|
// Ungrouped timers don't really make sense to add up. We still print the
|
|
|
|
// TOTAL line to make the percentages make sense.
|
2009-06-23 18:36:10 +02:00
|
|
|
if (this != DefaultTimerGroup) {
|
2005-02-09 19:41:32 +01:00
|
|
|
*OutStream << " Total Execution Time: ";
|
|
|
|
|
2009-08-23 10:43:55 +02:00
|
|
|
*OutStream << format("%5.4f", Total.getProcessTime()) << " seconds (";
|
|
|
|
*OutStream << format("%5.4f", Total.getWallTime()) << " wall clock)\n";
|
2005-02-09 19:41:32 +01:00
|
|
|
}
|
|
|
|
*OutStream << "\n";
|
2002-10-01 21:36:54 +02:00
|
|
|
|
2009-06-23 22:17:22 +02:00
|
|
|
if (Total.UserTime)
|
2003-05-09 22:05:44 +02:00
|
|
|
*OutStream << " ---User Time---";
|
2009-06-23 22:17:22 +02:00
|
|
|
if (Total.SystemTime)
|
2003-05-09 22:05:44 +02:00
|
|
|
*OutStream << " --System Time--";
|
2009-06-23 22:17:22 +02:00
|
|
|
if (Total.getProcessTime())
|
2003-05-09 22:05:44 +02:00
|
|
|
*OutStream << " --User+System--";
|
|
|
|
*OutStream << " ---Wall Time---";
|
2009-06-23 22:17:22 +02:00
|
|
|
if (Total.getMemUsed())
|
2003-05-09 22:05:44 +02:00
|
|
|
*OutStream << " ---Mem---";
|
2009-06-23 22:17:22 +02:00
|
|
|
if (Total.getPeakMem())
|
2003-05-09 22:05:44 +02:00
|
|
|
*OutStream << " -PeakMem-";
|
|
|
|
*OutStream << " --- Name ---\n";
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2002-10-01 21:36:54 +02:00
|
|
|
// Loop through all of the timing data, printing it out...
|
|
|
|
for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
|
2003-05-09 22:05:44 +02:00
|
|
|
TimersToPrint[i].print(Total, *OutStream);
|
2005-04-22 00:55:34 +02:00
|
|
|
|
2003-05-09 22:05:44 +02:00
|
|
|
Total.print(Total, *OutStream);
|
2009-08-23 10:43:55 +02:00
|
|
|
*OutStream << '\n';
|
|
|
|
OutStream->flush();
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
--NumTimers;
|
|
|
|
|
|
|
|
TimersToPrint.clear();
|
2003-05-09 22:05:44 +02:00
|
|
|
|
2010-01-05 02:28:58 +01:00
|
|
|
if (OutStream != &errs() && OutStream != &outs() && OutStream != &dbgs())
|
2003-05-09 22:05:44 +02:00
|
|
|
delete OutStream; // Close the file...
|
2002-10-01 21:36:54 +02:00
|
|
|
}
|
|
|
|
}
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2009-06-23 22:52:29 +02:00
|
|
|
void TimerGroup::addTimer() {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2009-06-23 22:52:29 +02:00
|
|
|
++NumTimers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerGroup::addTimerToPrint(const Timer &T) {
|
2009-07-07 20:33:04 +02:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2009-06-23 22:52:29 +02:00
|
|
|
TimersToPrint.push_back(Timer(true, T));
|
|
|
|
}
|
|
|
|
|