2002-10-01 19:36:54 +00:00
|
|
|
//===-- Timer.cpp - Interval Timing Support -------------------------------===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-01 19:36:54 +00:00
|
|
|
//
|
|
|
|
// Interval Timing implementation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/Timer.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2010-03-29 21:28:41 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2006-10-04 21:52:35 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-08-23 08:43:55 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Mutex.h"
|
|
|
|
#include "llvm/Support/Process.h"
|
2010-03-30 05:20:02 +00:00
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2010-03-30 04:03:22 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2003-12-14 21:27:33 +00:00
|
|
|
using namespace llvm;
|
2003-05-09 20:05:44 +00:00
|
|
|
|
2010-03-30 05:01:08 +00:00
|
|
|
// CreateInfoOutputFile - Return a file stream to print our output on.
|
|
|
|
namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2003-07-31 19:38:34 +00:00
|
|
|
// getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
|
|
|
|
// of constructor/destructor ordering being unspecified by C++. Basically the
|
2006-12-06 17:46:33 +00:00
|
|
|
// problem is that a Statistic object gets destroyed, which ends up calling
|
2003-07-31 19:38:34 +00:00
|
|
|
// 'GetLibSupportInfoOutputFile()' (below), which calls this function.
|
|
|
|
// LibSupportInfoOutputFilename used to be a global variable, but sometimes it
|
2004-12-14 03:55:21 +00: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 21:52:35 +00:00
|
|
|
static ManagedStatic<std::string> LibSupportInfoOutputFilename;
|
2003-07-31 19:38:34 +00:00
|
|
|
static std::string &getLibSupportInfoOutputFilename() {
|
2004-12-14 03:55:21 +00:00
|
|
|
return *LibSupportInfoOutputFilename;
|
2003-07-31 19:38:34 +00:00
|
|
|
}
|
2002-10-01 19:36:54 +00:00
|
|
|
|
2009-06-23 20:52:29 +00:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > TimerLock;
|
|
|
|
|
2003-01-30 23:08:50 +00:00
|
|
|
namespace {
|
2008-04-23 23:15:23 +00:00
|
|
|
static cl::opt<bool>
|
2003-01-30 23:08:50 +00:00
|
|
|
TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
|
|
|
|
"tracking (this may be slow)"),
|
|
|
|
cl::Hidden);
|
2003-05-09 20:05:44 +00:00
|
|
|
|
2008-04-23 23:15:23 +00:00
|
|
|
static cl::opt<std::string, true>
|
2003-08-01 22:15:15 +00:00
|
|
|
InfoOutputFilename("info-output-file", cl::value_desc("filename"),
|
2003-05-09 20:05:44 +00:00
|
|
|
cl::desc("File to append -stats and -timer output to"),
|
2003-07-31 19:38:34 +00:00
|
|
|
cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
|
2003-01-30 23:08:50 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 05:01:08 +00:00
|
|
|
// CreateInfoOutputFile - Return a file stream to print our output on.
|
|
|
|
raw_ostream *llvm::CreateInfoOutputFile() {
|
2010-03-30 05:34:02 +00:00
|
|
|
const std::string &OutputFilename = getLibSupportInfoOutputFilename();
|
|
|
|
if (OutputFilename.empty())
|
2010-03-30 05:01:08 +00:00
|
|
|
return new raw_fd_ostream(2, false); // stderr.
|
2010-03-30 05:34:02 +00:00
|
|
|
if (OutputFilename == "-")
|
2010-03-30 05:01:08 +00:00
|
|
|
return new raw_fd_ostream(1, false); // stdout.
|
2010-03-29 21:34:06 +00:00
|
|
|
|
2010-05-19 01:21:34 +00:00
|
|
|
// Append mode is used because the info output file is opened and closed
|
|
|
|
// each time -stats or -time-passes wants to print output to it. To
|
|
|
|
// compensate for this, the test-suite Makefiles have code to delete the
|
|
|
|
// info output file before running commands which write to it.
|
2010-03-29 21:34:06 +00:00
|
|
|
std::string Error;
|
2010-03-30 05:34:02 +00:00
|
|
|
raw_ostream *Result = new raw_fd_ostream(OutputFilename.c_str(),
|
2010-03-29 21:34:06 +00:00
|
|
|
Error, raw_fd_ostream::F_Append);
|
|
|
|
if (Error.empty())
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
errs() << "Error opening info-output-file '"
|
2010-03-30 05:34:02 +00:00
|
|
|
<< OutputFilename << " for appending!\n";
|
2010-03-29 21:34:06 +00:00
|
|
|
delete Result;
|
2010-03-30 05:01:08 +00:00
|
|
|
return new raw_fd_ostream(2, false); // stderr.
|
2010-03-29 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-23 16:36:10 +00:00
|
|
|
static TimerGroup *DefaultTimerGroup = 0;
|
2002-10-01 19:36:54 +00:00
|
|
|
static TimerGroup *getDefaultTimerGroup() {
|
2010-03-29 20:35:01 +00:00
|
|
|
TimerGroup *tmp = DefaultTimerGroup;
|
2009-06-23 17:33:37 +00:00
|
|
|
sys::MemoryFence();
|
2010-03-29 20:35:01 +00:00
|
|
|
if (tmp) return tmp;
|
|
|
|
|
|
|
|
llvm_acquire_global_lock();
|
|
|
|
tmp = DefaultTimerGroup;
|
2009-06-23 17:33:37 +00:00
|
|
|
if (!tmp) {
|
2010-03-29 20:35:01 +00:00
|
|
|
tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
|
|
|
|
sys::MemoryFence();
|
|
|
|
DefaultTimerGroup = tmp;
|
2009-06-23 17:33:37 +00:00
|
|
|
}
|
2010-03-29 20:35:01 +00:00
|
|
|
llvm_release_global_lock();
|
2009-11-07 06:33:12 +00:00
|
|
|
|
2009-06-23 17:33:37 +00:00
|
|
|
return tmp;
|
2002-10-01 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 20:35:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Timer Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-03-30 05:34:02 +00:00
|
|
|
void Timer::init(StringRef N) {
|
2010-03-30 04:03:22 +00:00
|
|
|
assert(TG == 0 && "Timer already initialized");
|
2010-03-30 05:34:02 +00:00
|
|
|
Name.assign(N.begin(), N.end());
|
2010-03-30 04:03:22 +00:00
|
|
|
Started = false;
|
|
|
|
TG = getDefaultTimerGroup();
|
2010-03-30 04:40:01 +00:00
|
|
|
TG->addTimer(*this);
|
2002-10-01 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 05:34:02 +00:00
|
|
|
void Timer::init(StringRef N, TimerGroup &tg) {
|
2010-03-30 04:03:22 +00:00
|
|
|
assert(TG == 0 && "Timer already initialized");
|
2010-03-30 05:34:02 +00:00
|
|
|
Name.assign(N.begin(), N.end());
|
2010-03-30 04:03:22 +00:00
|
|
|
Started = false;
|
|
|
|
TG = &tg;
|
2010-03-30 04:40:01 +00:00
|
|
|
TG->addTimer(*this);
|
2002-10-01 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Timer::~Timer() {
|
2010-03-30 05:20:02 +00:00
|
|
|
if (!TG) return; // Never initialized, or already cleared.
|
2010-03-30 04:40:01 +00:00
|
|
|
TG->removeTimer(*this);
|
2002-10-01 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2005-01-08 20:15:57 +00:00
|
|
|
static inline size_t getMemUsage() {
|
2010-03-30 05:20:02 +00:00
|
|
|
if (!TrackSpace) return 0;
|
|
|
|
return sys::Process::GetMallocUsage();
|
2004-12-27 08:03:04 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRecord TimeRecord::getCurrentTime(bool Start) {
|
2004-12-20 00:59:04 +00:00
|
|
|
TimeRecord Result;
|
2010-03-30 05:20:02 +00:00
|
|
|
sys::TimeValue now(0,0), user(0,0), sys(0,0);
|
|
|
|
|
2004-12-20 21:44:27 +00:00
|
|
|
if (Start) {
|
2010-03-30 05:20:02 +00:00
|
|
|
Result.MemUsed = getMemUsage();
|
2010-03-29 20:35:01 +00:00
|
|
|
sys::Process::GetTimeUsage(now, user, sys);
|
2004-12-20 21:44:27 +00:00
|
|
|
} else {
|
2010-03-29 20:35:01 +00:00
|
|
|
sys::Process::GetTimeUsage(now, user, sys);
|
2010-03-30 05:20:02 +00:00
|
|
|
Result.MemUsed = getMemUsage();
|
2004-12-20 21:44:27 +00:00
|
|
|
}
|
2002-11-18 21:47:09 +00:00
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
Result.WallTime = now.seconds() + now.microseconds() / 1000000.0;
|
2010-03-29 20:35:01 +00:00
|
|
|
Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
|
2010-03-30 04:03:22 +00:00
|
|
|
Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0;
|
2002-10-01 19:36:54 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2006-10-04 21:52:35 +00:00
|
|
|
static ManagedStatic<std::vector<Timer*> > ActiveTimers;
|
2002-11-18 21:47:09 +00:00
|
|
|
|
2002-10-01 19:36:54 +00:00
|
|
|
void Timer::startTimer() {
|
|
|
|
Started = true;
|
2008-06-24 22:07:07 +00:00
|
|
|
ActiveTimers->push_back(this);
|
2010-03-30 04:03:22 +00:00
|
|
|
Time -= TimeRecord::getCurrentTime(true);
|
2002-10-01 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::stopTimer() {
|
2010-03-30 04:03:22 +00:00
|
|
|
Time += TimeRecord::getCurrentTime(false);
|
2002-11-18 21:47:09 +00:00
|
|
|
|
2006-10-04 21:52:35 +00:00
|
|
|
if (ActiveTimers->back() == this) {
|
|
|
|
ActiveTimers->pop_back();
|
2002-11-18 21:47:09 +00:00
|
|
|
} else {
|
|
|
|
std::vector<Timer*>::iterator I =
|
2006-10-04 21:52:35 +00:00
|
|
|
std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
|
|
|
|
assert(I != ActiveTimers->end() && "stop but no startTimer?");
|
|
|
|
ActiveTimers->erase(I);
|
2002-11-18 21:47:09 +00:00
|
|
|
}
|
2002-10-01 19:36:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 20:35:01 +00:00
|
|
|
static void printVal(double Val, double Total, raw_ostream &OS) {
|
2010-03-29 20:40:19 +00:00
|
|
|
if (Total < 1e-7) // Avoid dividing by zero.
|
2010-03-29 20:35:01 +00:00
|
|
|
OS << " ----- ";
|
2011-10-16 16:30:34 +00:00
|
|
|
else
|
|
|
|
OS << format(" %7.4f (%5.1f%%)", Val, Val*100/Total);
|
2010-03-29 20:35:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
void TimeRecord::print(const TimeRecord &Total, raw_ostream &OS) const {
|
|
|
|
if (Total.getUserTime())
|
|
|
|
printVal(getUserTime(), Total.getUserTime(), OS);
|
|
|
|
if (Total.getSystemTime())
|
|
|
|
printVal(getSystemTime(), Total.getSystemTime(), OS);
|
2010-03-29 20:35:01 +00:00
|
|
|
if (Total.getProcessTime())
|
|
|
|
printVal(getProcessTime(), Total.getProcessTime(), OS);
|
2010-03-30 04:03:22 +00:00
|
|
|
printVal(getWallTime(), Total.getWallTime(), OS);
|
2010-03-29 20:35:01 +00:00
|
|
|
|
|
|
|
OS << " ";
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
if (Total.getMemUsed())
|
2011-10-16 16:30:34 +00:00
|
|
|
OS << format("%9lld ", (long long)getMemUsed());
|
2010-03-29 20:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-06 15:02:31 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NamedRegionTimer Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-04-15 17:08:50 +00:00
|
|
|
namespace {
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
typedef StringMap<Timer> Name2TimerMap;
|
2010-03-30 05:20:02 +00:00
|
|
|
|
|
|
|
class Name2PairMap {
|
|
|
|
StringMap<std::pair<TimerGroup*, Name2TimerMap> > Map;
|
|
|
|
public:
|
|
|
|
~Name2PairMap() {
|
|
|
|
for (StringMap<std::pair<TimerGroup*, Name2TimerMap> >::iterator
|
|
|
|
I = Map.begin(), E = Map.end(); I != E; ++I)
|
|
|
|
delete I->second.first;
|
|
|
|
}
|
|
|
|
|
2010-03-30 05:34:02 +00:00
|
|
|
Timer &get(StringRef Name, StringRef GroupName) {
|
2010-03-30 05:20:02 +00:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
|
|
|
|
std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
|
|
|
|
|
|
|
|
if (!GroupEntry.first)
|
|
|
|
GroupEntry.first = new TimerGroup(GroupName);
|
|
|
|
|
|
|
|
Timer &T = GroupEntry.second[Name];
|
|
|
|
if (!T.isInitialized())
|
|
|
|
T.init(Name, *GroupEntry.first);
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
};
|
2008-07-14 18:19:29 +00:00
|
|
|
|
2010-04-15 17:08:50 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
static ManagedStatic<Name2TimerMap> NamedTimers;
|
|
|
|
static ManagedStatic<Name2PairMap> NamedGroupedTimers;
|
2003-10-06 15:02:31 +00:00
|
|
|
|
2010-03-30 05:34:02 +00:00
|
|
|
static Timer &getNamedRegionTimer(StringRef Name) {
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2010-03-30 04:03:22 +00:00
|
|
|
|
|
|
|
Timer &T = (*NamedTimers)[Name];
|
|
|
|
if (!T.isInitialized())
|
|
|
|
T.init(Name);
|
|
|
|
return T;
|
2003-10-06 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-18 15:56:31 +00:00
|
|
|
NamedRegionTimer::NamedRegionTimer(StringRef Name,
|
|
|
|
bool Enabled)
|
|
|
|
: TimeRegion(!Enabled ? 0 : &getNamedRegionTimer(Name)) {}
|
2003-10-06 15:02:31 +00:00
|
|
|
|
2010-06-18 15:56:31 +00:00
|
|
|
NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef GroupName,
|
|
|
|
bool Enabled)
|
|
|
|
: TimeRegion(!Enabled ? 0 : &NamedGroupedTimers->get(Name, GroupName)) {}
|
2002-11-18 21:47:09 +00:00
|
|
|
|
2002-10-01 19:36:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TimerGroup Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-03-30 05:27:58 +00:00
|
|
|
/// TimerGroupList - This is the global list of TimerGroups, maintained by the
|
|
|
|
/// TimerGroup ctor/dtor and is protected by the TimerLock lock.
|
|
|
|
static TimerGroup *TimerGroupList = 0;
|
|
|
|
|
2010-03-30 05:34:02 +00:00
|
|
|
TimerGroup::TimerGroup(StringRef name)
|
|
|
|
: Name(name.begin(), name.end()), FirstTimer(0) {
|
2010-03-30 05:27:58 +00:00
|
|
|
|
|
|
|
// Add the group to TimerGroupList.
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
if (TimerGroupList)
|
|
|
|
TimerGroupList->Prev = &Next;
|
|
|
|
Next = TimerGroupList;
|
|
|
|
Prev = &TimerGroupList;
|
|
|
|
TimerGroupList = this;
|
|
|
|
}
|
|
|
|
|
2010-03-30 04:58:26 +00:00
|
|
|
TimerGroup::~TimerGroup() {
|
|
|
|
// If the timer group is destroyed before the timers it owns, accumulate and
|
|
|
|
// print the timing data.
|
|
|
|
while (FirstTimer != 0)
|
|
|
|
removeTimer(*FirstTimer);
|
2010-03-30 05:27:58 +00:00
|
|
|
|
|
|
|
// Remove the group from the TimerGroupList.
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
*Prev = Next;
|
|
|
|
if (Next)
|
|
|
|
Next->Prev = Prev;
|
2010-03-30 04:58:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 04:40:01 +00:00
|
|
|
void TimerGroup::removeTimer(Timer &T) {
|
2009-07-07 18:33:04 +00:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2010-03-29 20:35:01 +00:00
|
|
|
|
2010-03-30 04:40:01 +00:00
|
|
|
// If the timer was started, move its data to TimersToPrint.
|
2010-03-30 04:58:26 +00:00
|
|
|
if (T.Started)
|
2010-03-30 04:40:01 +00:00
|
|
|
TimersToPrint.push_back(std::make_pair(T.Time, T.Name));
|
2010-03-30 04:58:26 +00:00
|
|
|
|
|
|
|
T.TG = 0;
|
2010-03-30 04:40:01 +00:00
|
|
|
|
|
|
|
// Unlink the timer from our list.
|
|
|
|
*T.Prev = T.Next;
|
|
|
|
if (T.Next)
|
|
|
|
T.Next->Prev = T.Prev;
|
|
|
|
|
|
|
|
// Print the report when all timers in this group are destroyed if some of
|
|
|
|
// them were started.
|
|
|
|
if (FirstTimer != 0 || TimersToPrint.empty())
|
|
|
|
return;
|
|
|
|
|
2010-03-30 05:01:08 +00:00
|
|
|
raw_ostream *OutStream = CreateInfoOutputFile();
|
2010-03-30 04:40:01 +00:00
|
|
|
PrintQueuedTimers(*OutStream);
|
2010-03-30 05:01:08 +00:00
|
|
|
delete OutStream; // Close the file.
|
2010-03-30 04:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimerGroup::addTimer(Timer &T) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
|
|
|
|
// Add the timer to our list.
|
|
|
|
if (FirstTimer)
|
|
|
|
FirstTimer->Prev = &T.Next;
|
|
|
|
T.Next = FirstTimer;
|
|
|
|
T.Prev = &FirstTimer;
|
|
|
|
FirstTimer = &T;
|
|
|
|
}
|
2010-03-29 20:35:01 +00:00
|
|
|
|
2010-03-30 04:40:01 +00:00
|
|
|
void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
|
|
|
|
// Sort the timers in descending order by amount of time taken.
|
2010-08-07 13:27:41 +00:00
|
|
|
std::sort(TimersToPrint.begin(), TimersToPrint.end());
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
TimeRecord Total;
|
|
|
|
for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
|
|
|
|
Total += TimersToPrint[i].first;
|
2010-03-30 04:40:01 +00:00
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
// Print out timing header.
|
2010-03-30 04:40:01 +00:00
|
|
|
OS << "===" << std::string(73, '-') << "===\n";
|
|
|
|
// 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
|
|
|
|
OS.indent(Padding) << Name << '\n';
|
|
|
|
OS << "===" << std::string(73, '-') << "===\n";
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
// 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.
|
2011-10-16 16:30:34 +00:00
|
|
|
if (this != DefaultTimerGroup)
|
|
|
|
OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
|
|
|
|
Total.getProcessTime(), Total.getWallTime());
|
2010-03-30 04:40:01 +00:00
|
|
|
OS << '\n';
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
if (Total.getUserTime())
|
2010-03-30 04:40:01 +00:00
|
|
|
OS << " ---User Time---";
|
2010-03-30 04:03:22 +00:00
|
|
|
if (Total.getSystemTime())
|
2010-03-30 04:40:01 +00:00
|
|
|
OS << " --System Time--";
|
2010-03-30 04:03:22 +00:00
|
|
|
if (Total.getProcessTime())
|
2010-03-30 04:40:01 +00:00
|
|
|
OS << " --User+System--";
|
|
|
|
OS << " ---Wall Time---";
|
2010-03-30 04:03:22 +00:00
|
|
|
if (Total.getMemUsed())
|
2010-03-30 04:40:01 +00:00
|
|
|
OS << " ---Mem---";
|
|
|
|
OS << " --- Name ---\n";
|
|
|
|
|
2010-03-30 04:03:22 +00:00
|
|
|
// Loop through all of the timing data, printing it out.
|
|
|
|
for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i) {
|
|
|
|
const std::pair<TimeRecord, std::string> &Entry = TimersToPrint[e-i-1];
|
2010-03-30 04:40:01 +00:00
|
|
|
Entry.first.print(Total, OS);
|
|
|
|
OS << Entry.second << '\n';
|
2010-03-30 04:03:22 +00:00
|
|
|
}
|
2010-03-30 04:40:01 +00:00
|
|
|
|
|
|
|
Total.print(Total, OS);
|
|
|
|
OS << "Total\n\n";
|
|
|
|
OS.flush();
|
|
|
|
|
2010-03-29 20:35:01 +00:00
|
|
|
TimersToPrint.clear();
|
2009-06-23 20:52:29 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 05:20:02 +00:00
|
|
|
/// print - Print any started timers in this group and zero them.
|
|
|
|
void TimerGroup::print(raw_ostream &OS) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
|
|
|
|
// See if any of our timers were started, if so add them to TimersToPrint and
|
|
|
|
// reset them.
|
|
|
|
for (Timer *T = FirstTimer; T; T = T->Next) {
|
|
|
|
if (!T->Started) continue;
|
|
|
|
TimersToPrint.push_back(std::make_pair(T->Time, T->Name));
|
|
|
|
|
|
|
|
// Clear out the time.
|
|
|
|
T->Started = 0;
|
|
|
|
T->Time = TimeRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If any timers were started, print the group.
|
|
|
|
if (!TimersToPrint.empty())
|
|
|
|
PrintQueuedTimers(OS);
|
|
|
|
}
|
2010-03-30 05:27:58 +00:00
|
|
|
|
|
|
|
/// printAll - This static method prints all timers and clears them all out.
|
|
|
|
void TimerGroup::printAll(raw_ostream &OS) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
|
|
|
|
for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
|
|
|
|
TG->print(OS);
|
|
|
|
}
|