2002-10-02 03:36:54 +08:00
|
|
|
//===-- Timer.cpp - Interval Timing Support -------------------------------===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-02 03:36:54 +08:00
|
|
|
//
|
2016-10-14 08:17:19 +08:00
|
|
|
/// \file Interval Timing implementation.
|
2002-10-02 03:36:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Support/Timer.h"
|
2015-12-17 06:28:34 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-04-30 07:26:49 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2009-08-23 16:43:55 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2014-06-17 06:49:41 +08:00
|
|
|
#include "llvm/Support/Mutex.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Process.h"
|
2016-11-19 03:43:24 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-15 05:27:33 +08:00
|
|
|
using namespace llvm;
|
2003-05-10 04:05:44 +08:00
|
|
|
|
2016-10-14 08:17:19 +08:00
|
|
|
// 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 '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.
|
2006-10-05 05:52:35 +08:00
|
|
|
static ManagedStatic<std::string> LibSupportInfoOutputFilename;
|
2003-08-01 03:38:34 +08:00
|
|
|
static std::string &getLibSupportInfoOutputFilename() {
|
2004-12-14 11:55:21 +08:00
|
|
|
return *LibSupportInfoOutputFilename;
|
2003-08-01 03:38:34 +08:00
|
|
|
}
|
2002-10-02 03:36:54 +08:00
|
|
|
|
2009-06-24 04:52:29 +08:00
|
|
|
static ManagedStatic<sys::SmartMutex<true> > TimerLock;
|
|
|
|
|
2003-01-31 07:08:50 +08:00
|
|
|
namespace {
|
2008-04-24 07:15:23 +08:00
|
|
|
static cl::opt<bool>
|
2003-01-31 07:08:50 +08:00
|
|
|
TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
|
|
|
|
"tracking (this may be slow)"),
|
|
|
|
cl::Hidden);
|
2003-05-10 04:05:44 +08:00
|
|
|
|
2008-04-24 07:15:23 +08:00
|
|
|
static cl::opt<std::string, true>
|
2003-08-02 06:15:15 +08:00
|
|
|
InfoOutputFilename("info-output-file", cl::value_desc("filename"),
|
2003-05-10 04:05:44 +08:00
|
|
|
cl::desc("File to append -stats and -timer output to"),
|
2003-08-01 03:38:34 +08:00
|
|
|
cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2003-01-31 07:08:50 +08:00
|
|
|
|
2015-12-17 06:28:34 +08:00
|
|
|
std::unique_ptr<raw_fd_ostream> llvm::CreateInfoOutputFile() {
|
2010-03-30 13:34:02 +08:00
|
|
|
const std::string &OutputFilename = getLibSupportInfoOutputFilename();
|
|
|
|
if (OutputFilename.empty())
|
2015-12-17 06:28:34 +08:00
|
|
|
return llvm::make_unique<raw_fd_ostream>(2, false); // stderr.
|
2010-03-30 13:34:02 +08:00
|
|
|
if (OutputFilename == "-")
|
2015-12-17 06:28:34 +08:00
|
|
|
return llvm::make_unique<raw_fd_ostream>(1, false); // stdout.
|
|
|
|
|
2010-05-19 09:21:34 +08: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.
|
2014-08-26 02:16:47 +08:00
|
|
|
std::error_code EC;
|
2015-12-17 06:28:34 +08:00
|
|
|
auto Result = llvm::make_unique<raw_fd_ostream>(
|
|
|
|
OutputFilename, EC, sys::fs::F_Append | sys::fs::F_Text);
|
2014-08-26 02:16:47 +08:00
|
|
|
if (!EC)
|
2010-03-30 05:34:06 +08:00
|
|
|
return Result;
|
2015-12-17 06:28:34 +08:00
|
|
|
|
2010-03-30 05:34:06 +08:00
|
|
|
errs() << "Error opening info-output-file '"
|
2010-03-30 13:34:02 +08:00
|
|
|
<< OutputFilename << " for appending!\n";
|
2015-12-17 06:28:34 +08:00
|
|
|
return llvm::make_unique<raw_fd_ostream>(2, false); // stderr.
|
2010-03-30 05:34:06 +08:00
|
|
|
}
|
|
|
|
|
2017-05-29 22:28:04 +08:00
|
|
|
namespace {
|
2017-05-30 04:56:27 +08:00
|
|
|
struct CreateDefaultTimerGroup {
|
|
|
|
static void *call() {
|
|
|
|
return new TimerGroup("misc", "Miscellaneous Ungrouped Timers");
|
|
|
|
}
|
|
|
|
};
|
2017-05-29 22:28:04 +08:00
|
|
|
} // namespace
|
2017-05-29 22:05:29 +08:00
|
|
|
static ManagedStatic<TimerGroup, CreateDefaultTimerGroup> DefaultTimerGroup;
|
|
|
|
static TimerGroup *getDefaultTimerGroup() { return &*DefaultTimerGroup; }
|
2002-10-02 03:36:54 +08:00
|
|
|
|
2010-03-30 04:35:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Timer Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
void Timer::init(StringRef Name, StringRef Description) {
|
|
|
|
init(Name, Description, *getDefaultTimerGroup());
|
2002-10-02 03:36:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
void Timer::init(StringRef Name, StringRef Description, TimerGroup &tg) {
|
2014-04-15 14:32:26 +08:00
|
|
|
assert(!TG && "Timer already initialized");
|
2016-11-19 03:43:18 +08:00
|
|
|
this->Name.assign(Name.begin(), Name.end());
|
|
|
|
this->Description.assign(Description.begin(), Description.end());
|
2015-12-23 01:36:17 +08:00
|
|
|
Running = Triggered = false;
|
2010-03-30 12:03:22 +08:00
|
|
|
TG = &tg;
|
2010-03-30 12:40:01 +08:00
|
|
|
TG->addTimer(*this);
|
2002-10-02 03:36:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Timer::~Timer() {
|
2010-03-30 13:20:02 +08:00
|
|
|
if (!TG) return; // Never initialized, or already cleared.
|
2010-03-30 12:40:01 +08:00
|
|
|
TG->removeTimer(*this);
|
2002-10-02 03:36:54 +08:00
|
|
|
}
|
|
|
|
|
2005-01-09 04:15:57 +08:00
|
|
|
static inline size_t getMemUsage() {
|
2010-03-30 13:20:02 +08:00
|
|
|
if (!TrackSpace) return 0;
|
|
|
|
return sys::Process::GetMallocUsage();
|
2004-12-27 16:03:04 +08:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRecord TimeRecord::getCurrentTime(bool Start) {
|
2016-10-24 18:59:17 +08:00
|
|
|
using Seconds = std::chrono::duration<double, std::ratio<1>>;
|
2004-12-20 08:59:04 +08:00
|
|
|
TimeRecord Result;
|
2016-10-24 18:59:17 +08:00
|
|
|
sys::TimePoint<> now;
|
|
|
|
std::chrono::nanoseconds user, sys;
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2004-12-21 05:44:27 +08:00
|
|
|
if (Start) {
|
2010-03-30 13:20:02 +08:00
|
|
|
Result.MemUsed = getMemUsage();
|
2010-03-30 04:35:01 +08:00
|
|
|
sys::Process::GetTimeUsage(now, user, sys);
|
2004-12-21 05:44:27 +08:00
|
|
|
} else {
|
2010-03-30 04:35:01 +08:00
|
|
|
sys::Process::GetTimeUsage(now, user, sys);
|
2010-03-30 13:20:02 +08:00
|
|
|
Result.MemUsed = getMemUsage();
|
2004-12-21 05:44:27 +08:00
|
|
|
}
|
2002-11-19 05:47:09 +08:00
|
|
|
|
2016-10-24 18:59:17 +08:00
|
|
|
Result.WallTime = Seconds(now.time_since_epoch()).count();
|
|
|
|
Result.UserTime = Seconds(user).count();
|
|
|
|
Result.SystemTime = Seconds(sys).count();
|
2002-10-02 03:36:54 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::startTimer() {
|
2015-12-23 01:36:17 +08:00
|
|
|
assert(!Running && "Cannot start a running timer");
|
|
|
|
Running = Triggered = true;
|
|
|
|
StartTime = TimeRecord::getCurrentTime(true);
|
2002-10-02 03:36:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::stopTimer() {
|
2015-12-23 01:36:17 +08:00
|
|
|
assert(Running && "Cannot stop a paused timer");
|
|
|
|
Running = false;
|
2010-03-30 12:03:22 +08:00
|
|
|
Time += TimeRecord::getCurrentTime(false);
|
2015-12-23 01:36:17 +08:00
|
|
|
Time -= StartTime;
|
|
|
|
}
|
2002-11-19 05:47:09 +08:00
|
|
|
|
2015-12-23 01:36:17 +08:00
|
|
|
void Timer::clear() {
|
|
|
|
Running = Triggered = false;
|
|
|
|
Time = StartTime = TimeRecord();
|
2002-10-02 03:36:54 +08:00
|
|
|
}
|
|
|
|
|
2010-03-30 04:35:01 +08:00
|
|
|
static void printVal(double Val, double Total, raw_ostream &OS) {
|
2010-03-30 04:40:19 +08:00
|
|
|
if (Total < 1e-7) // Avoid dividing by zero.
|
2010-03-30 04:35:01 +08:00
|
|
|
OS << " ----- ";
|
2011-10-17 00:30:34 +08:00
|
|
|
else
|
|
|
|
OS << format(" %7.4f (%5.1f%%)", Val, Val*100/Total);
|
2010-03-30 04:35:01 +08:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:03:22 +08: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-30 04:35:01 +08:00
|
|
|
if (Total.getProcessTime())
|
|
|
|
printVal(getProcessTime(), Total.getProcessTime(), OS);
|
2010-03-30 12:03:22 +08:00
|
|
|
printVal(getWallTime(), Total.getWallTime(), OS);
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 04:35:01 +08:00
|
|
|
OS << " ";
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
if (Total.getMemUsed())
|
2011-11-05 16:57:40 +08:00
|
|
|
OS << format("%9" PRId64 " ", (int64_t)getMemUsed());
|
2010-03-30 04:35:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-06 23:02:31 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NamedRegionTimer Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-04-16 01:08:50 +08:00
|
|
|
namespace {
|
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
typedef StringMap<Timer> Name2TimerMap;
|
2010-03-30 13:20:02 +08: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;
|
|
|
|
}
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
Timer &get(StringRef Name, StringRef Description, StringRef GroupName,
|
|
|
|
StringRef GroupDescription) {
|
2010-03-30 13:20:02 +08:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 13:20:02 +08:00
|
|
|
std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 13:20:02 +08:00
|
|
|
if (!GroupEntry.first)
|
2016-11-19 03:43:18 +08:00
|
|
|
GroupEntry.first = new TimerGroup(GroupName, GroupDescription);
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 13:20:02 +08:00
|
|
|
Timer &T = GroupEntry.second[Name];
|
|
|
|
if (!T.isInitialized())
|
2016-11-19 03:43:18 +08:00
|
|
|
T.init(Name, Description, *GroupEntry.first);
|
2010-03-30 13:20:02 +08:00
|
|
|
return T;
|
|
|
|
}
|
|
|
|
};
|
2008-07-15 02:19:29 +08:00
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2010-04-16 01:08:50 +08:00
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
static ManagedStatic<Name2PairMap> NamedGroupedTimers;
|
2003-10-06 23:02:31 +08:00
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef Description,
|
|
|
|
StringRef GroupName,
|
|
|
|
StringRef GroupDescription, bool Enabled)
|
|
|
|
: TimeRegion(!Enabled ? nullptr
|
|
|
|
: &NamedGroupedTimers->get(Name, Description, GroupName,
|
|
|
|
GroupDescription)) {}
|
2002-11-19 05:47:09 +08:00
|
|
|
|
2002-10-02 03:36:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TimerGroup Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-10-14 08:17:19 +08:00
|
|
|
/// This is the global list of TimerGroups, maintained by the TimerGroup
|
|
|
|
/// ctor/dtor and is protected by the TimerLock lock.
|
2014-04-07 12:17:22 +08:00
|
|
|
static TimerGroup *TimerGroupList = nullptr;
|
2010-03-30 13:27:58 +08:00
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
TimerGroup::TimerGroup(StringRef Name, StringRef Description)
|
|
|
|
: Name(Name.begin(), Name.end()),
|
|
|
|
Description(Description.begin(), Description.end()) {
|
2010-03-30 13:27:58 +08: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 12:58:26 +08:00
|
|
|
TimerGroup::~TimerGroup() {
|
|
|
|
// If the timer group is destroyed before the timers it owns, accumulate and
|
|
|
|
// print the timing data.
|
2014-04-09 12:20:00 +08:00
|
|
|
while (FirstTimer)
|
2010-03-30 12:58:26 +08:00
|
|
|
removeTimer(*FirstTimer);
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 13:27:58 +08:00
|
|
|
// Remove the group from the TimerGroupList.
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
*Prev = Next;
|
|
|
|
if (Next)
|
|
|
|
Next->Prev = Prev;
|
2010-03-30 12:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
void TimerGroup::removeTimer(Timer &T) {
|
2009-07-08 02:33:04 +08:00
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
// If the timer was started, move its data to TimersToPrint.
|
2015-12-23 01:36:17 +08:00
|
|
|
if (T.hasTriggered())
|
2016-11-19 03:43:24 +08:00
|
|
|
TimersToPrint.emplace_back(T.Time, T.Name, T.Description);
|
2010-03-30 12:58:26 +08:00
|
|
|
|
2014-04-07 12:17:22 +08:00
|
|
|
T.TG = nullptr;
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
// Unlink the timer from our list.
|
|
|
|
*T.Prev = T.Next;
|
|
|
|
if (T.Next)
|
|
|
|
T.Next->Prev = T.Prev;
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
// Print the report when all timers in this group are destroyed if some of
|
|
|
|
// them were started.
|
2014-04-09 12:20:00 +08:00
|
|
|
if (FirstTimer || TimersToPrint.empty())
|
2010-03-30 12:40:01 +08:00
|
|
|
return;
|
2015-12-17 06:28:34 +08:00
|
|
|
|
|
|
|
std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
|
2010-03-30 12:40:01 +08:00
|
|
|
PrintQueuedTimers(*OutStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerGroup::addTimer(Timer &T) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
// Add the timer to our list.
|
|
|
|
if (FirstTimer)
|
|
|
|
FirstTimer->Prev = &T.Next;
|
|
|
|
T.Next = FirstTimer;
|
|
|
|
T.Prev = &FirstTimer;
|
|
|
|
FirstTimer = &T;
|
|
|
|
}
|
2010-03-30 04:35:01 +08:00
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
|
|
|
|
// Sort the timers in descending order by amount of time taken.
|
2010-08-07 21:27:41 +08:00
|
|
|
std::sort(TimersToPrint.begin(), TimersToPrint.end());
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
TimeRecord Total;
|
2016-11-19 03:43:24 +08:00
|
|
|
for (const PrintRecord &Record : TimersToPrint)
|
|
|
|
Total += Record.Time;
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
// Print out timing header.
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << "===" << std::string(73, '-') << "===\n";
|
|
|
|
// Figure out how many spaces to indent TimerGroup name.
|
2016-11-19 03:43:18 +08:00
|
|
|
unsigned Padding = (80-Description.length())/2;
|
2010-03-30 12:40:01 +08:00
|
|
|
if (Padding > 80) Padding = 0; // Don't allow "negative" numbers
|
2016-11-19 03:43:18 +08:00
|
|
|
OS.indent(Padding) << Description << '\n';
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << "===" << std::string(73, '-') << "===\n";
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:03:22 +08: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.
|
2017-02-17 04:19:49 +08:00
|
|
|
if (this != getDefaultTimerGroup())
|
2011-10-17 00:30:34 +08:00
|
|
|
OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
|
|
|
|
Total.getProcessTime(), Total.getWallTime());
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << '\n';
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
if (Total.getUserTime())
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << " ---User Time---";
|
2010-03-30 12:03:22 +08:00
|
|
|
if (Total.getSystemTime())
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << " --System Time--";
|
2010-03-30 12:03:22 +08:00
|
|
|
if (Total.getProcessTime())
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << " --User+System--";
|
|
|
|
OS << " ---Wall Time---";
|
2010-03-30 12:03:22 +08:00
|
|
|
if (Total.getMemUsed())
|
2010-03-30 12:40:01 +08:00
|
|
|
OS << " ---Mem---";
|
|
|
|
OS << " --- Name ---\n";
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:03:22 +08:00
|
|
|
// Loop through all of the timing data, printing it out.
|
2016-11-19 03:43:24 +08:00
|
|
|
for (const PrintRecord &Record : make_range(TimersToPrint.rbegin(),
|
|
|
|
TimersToPrint.rend())) {
|
|
|
|
Record.Time.print(Total, OS);
|
|
|
|
OS << Record.Description << '\n';
|
2010-03-30 12:03:22 +08:00
|
|
|
}
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 12:40:01 +08:00
|
|
|
Total.print(Total, OS);
|
|
|
|
OS << "Total\n\n";
|
|
|
|
OS.flush();
|
2016-06-04 03:20:37 +08:00
|
|
|
|
2010-03-30 04:35:01 +08:00
|
|
|
TimersToPrint.clear();
|
2009-06-24 04:52:29 +08:00
|
|
|
}
|
|
|
|
|
2016-11-19 03:43:24 +08:00
|
|
|
void TimerGroup::prepareToPrintList() {
|
2010-03-30 13:20:02 +08:00
|
|
|
// 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) {
|
2015-12-23 01:36:17 +08:00
|
|
|
if (!T->hasTriggered()) continue;
|
2016-11-19 03:43:24 +08:00
|
|
|
TimersToPrint.emplace_back(T->Time, T->Name, T->Description);
|
2016-10-14 08:17:19 +08:00
|
|
|
|
2010-03-30 13:20:02 +08:00
|
|
|
// Clear out the time.
|
2015-12-23 01:36:17 +08:00
|
|
|
T->clear();
|
2010-03-30 13:20:02 +08:00
|
|
|
}
|
2016-11-19 03:43:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimerGroup::print(raw_ostream &OS) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
|
|
|
|
prepareToPrintList();
|
2010-03-30 13:20:02 +08:00
|
|
|
|
|
|
|
// If any timers were started, print the group.
|
|
|
|
if (!TimersToPrint.empty())
|
|
|
|
PrintQueuedTimers(OS);
|
|
|
|
}
|
2010-03-30 13:27:58 +08:00
|
|
|
|
|
|
|
void TimerGroup::printAll(raw_ostream &OS) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
|
|
|
|
for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
|
|
|
|
TG->print(OS);
|
|
|
|
}
|
2016-11-19 03:43:24 +08:00
|
|
|
|
|
|
|
void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
|
|
|
|
const char *suffix, double Value) {
|
|
|
|
assert(!yaml::needsQuotes(Name) && "TimerGroup name needs no quotes");
|
|
|
|
assert(!yaml::needsQuotes(R.Name) && "Timer name needs no quotes");
|
|
|
|
OS << "\t\"time." << Name << '.' << R.Name << suffix << "\": " << Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *TimerGroup::printJSONValues(raw_ostream &OS, const char *delim) {
|
|
|
|
prepareToPrintList();
|
|
|
|
for (const PrintRecord &R : TimersToPrint) {
|
|
|
|
OS << delim;
|
|
|
|
delim = ",\n";
|
|
|
|
|
|
|
|
const TimeRecord &T = R.Time;
|
|
|
|
printJSONValue(OS, R, ".wall", T.getWallTime());
|
|
|
|
OS << delim;
|
|
|
|
printJSONValue(OS, R, ".user", T.getUserTime());
|
|
|
|
OS << delim;
|
|
|
|
printJSONValue(OS, R, ".sys", T.getSystemTime());
|
|
|
|
}
|
|
|
|
TimersToPrint.clear();
|
|
|
|
return delim;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *TimerGroup::printAllJSONValues(raw_ostream &OS, const char *delim) {
|
|
|
|
sys::SmartScopedLock<true> L(*TimerLock);
|
|
|
|
for (TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
|
|
|
|
delim = TG->printJSONValues(OS, delim);
|
|
|
|
return delim;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerGroup::ConstructTimerLists() {
|
|
|
|
(void)*NamedGroupedTimers;
|
|
|
|
}
|