48 TrackSpace(
"track-memory",
cl::desc(
"Enable -time-passes memory " 49 "tracking (this may be slow)"),
54 cl::desc(
"File to append -stats and -timer output to"),
60 if (OutputFilename.empty())
61 return std::make_unique<raw_fd_ostream>(2,
false);
62 if (OutputFilename ==
"-")
63 return std::make_unique<raw_fd_ostream>(1,
false);
70 auto Result = std::make_unique<raw_fd_ostream>(
75 errs() <<
"Error opening info-output-file '" 76 << OutputFilename <<
" for appending!\n";
77 return std::make_unique<raw_fd_ostream>(2,
false);
81 struct CreateDefaultTimerGroup {
83 return new TimerGroup(
"misc",
"Miscellaneous Ungrouped Timers");
100 assert(!TG &&
"Timer already initialized");
102 Description.assign(TimerDescription.
begin(), TimerDescription.
end());
103 Running = Triggered =
false;
110 TG->removeTimer(*
this);
114 if (!TrackSpace)
return 0;
119 using Seconds = std::chrono::duration<double, std::ratio<1>>;
122 std::chrono::nanoseconds user, sys;
132 Result.WallTime = Seconds(now.time_since_epoch()).
count();
133 Result.UserTime = Seconds(user).count();
134 Result.SystemTime = Seconds(sys).count();
139 assert(!Running &&
"Cannot start a running timer");
140 Running = Triggered =
true;
146 assert(Running &&
"Cannot stop a paused timer");
154 Running = Triggered =
false;
162 OS <<
format(
" %7.4f (%5.1f%%)", Val, Val*100/Total);
177 OS <<
format(
"%9" PRId64
" ", (int64_t)getMemUsed());
193 for (
StringMap<std::pair<TimerGroup*, Name2TimerMap> >::iterator
195 delete I->second.first;
202 std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
204 if (!GroupEntry.first)
205 GroupEntry.first =
new TimerGroup(GroupName, GroupDescription);
209 T.
init(Name, Description, *GroupEntry.first);
222 : &NamedGroupedTimers->get(Name, Description, GroupName,
223 GroupDescription)) {}
235 Description(Description.
begin(), Description.
end()) {
239 TimerGroupList->Prev = &Next;
242 TimerGroupList =
this;
248 TimersToPrint.reserve(Records.
size());
249 for (
const auto &
P : Records)
250 TimersToPrint.emplace_back(
P.getValue(),
P.getKey(),
P.getKey());
251 assert(TimersToPrint.size() == Records.size() &&
"Size mismatch");
258 removeTimer(*FirstTimer);
268 void TimerGroup::removeTimer(
Timer &
T) {
273 TimersToPrint.emplace_back(T.Time, T.Name, T.Description);
280 T.Next->Prev = T.Prev;
284 if (FirstTimer || TimersToPrint.empty())
288 PrintQueuedTimers(*OutStream);
291 void TimerGroup::addTimer(
Timer &T) {
296 FirstTimer->Prev = &T.Next;
298 T.Prev = &FirstTimer;
302 void TimerGroup::PrintQueuedTimers(
raw_ostream &OS) {
307 for (
const PrintRecord &
Record : TimersToPrint)
311 OS <<
"===" << std::string(73,
'-') <<
"===\n";
313 unsigned Padding = (80-Description.length())/2;
314 if (Padding > 80) Padding = 0;
315 OS.
indent(Padding) << Description <<
'\n';
316 OS <<
"===" << std::string(73,
'-') <<
"===\n";
322 OS <<
format(
" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
327 OS <<
" ---User Time---";
329 OS <<
" --System Time--";
331 OS <<
" --User+System--";
332 OS <<
" ---Wall Time---";
335 OS <<
" --- Name ---\n";
339 TimersToPrint.rend())) {
341 OS <<
Record.Description <<
'\n';
344 Total.
print(Total, OS);
348 TimersToPrint.clear();
351 void TimerGroup::prepareToPrintList(
bool ResetTime) {
353 for (
Timer *T = FirstTimer;
T; T = T->Next) {
359 TimersToPrint.emplace_back(T->Time, T->Name, T->Description);
373 prepareToPrintList(ResetAfterPrint);
377 if (!TimersToPrint.empty())
378 PrintQueuedTimers(OS);
383 for (
Timer *T = FirstTimer;
T; T = T->Next)
390 for (
TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
396 for (
TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
400 void TimerGroup::printJSONValue(
raw_ostream &OS,
const PrintRecord &R,
401 const char *suffix,
double Value) {
403 "TimerGroup name should not need quotes");
405 "Timer name should not need quotes");
406 constexpr
auto max_digits10 = std::numeric_limits<double>::max_digits10;
407 OS <<
"\t\"time." << Name <<
'.' << R.Name << suffix
408 <<
"\": " <<
format(
"%.*e", max_digits10 - 1, Value);
414 prepareToPrintList(
false);
415 for (
const PrintRecord &R : TimersToPrint) {
427 printJSONValue(OS, R,
".mem", T.
getMemUsed());
430 TimersToPrint.clear();
436 for (
TimerGroup *TG = TimerGroupList; TG; TG = TG->Next)
437 delim = TG->printJSONValues(OS, delim);
442 (void)*NamedGroupedTimers;
446 return std::unique_ptr<TimerGroup>(DefaultTimerGroup.
claim());
const_iterator end(StringRef path)
Get end iterator over path.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static TimeRecord getCurrentTime(bool Start=true)
Get the current time and memory usage.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
const char * printJSONValues(raw_ostream &OS, const char *delim)
This class represents lattice values for constants.
void print(raw_ostream &OS) const
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void stopTimer()
Stop the timer.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
static ManagedStatic< SignpostEmitter > Signposts
Allows llvm::Timer to emit signposts when supported.
bool isRunning() const
Check if the timer is currently running.
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
void init(StringRef TimerName, StringRef TimerDescription)
double getUserTime() const
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
static std::unique_ptr< TimerGroup > aquireDefaultGroup()
This makes the default group unmanaged, and lets the user manage the group's lifetime.
void print(const TimeRecord &Total, raw_ostream &OS) const
Print the current time record to OS, with a breakdown showing contributions to the Total time record...
static void printVal(double Val, double Total, raw_ostream &OS)
The file should be opened in text mode on platforms that make this distinction.
std::unique_ptr< raw_fd_ostream > CreateInfoOutputFile()
Return a file stream to print our output on.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static TimerGroup * TimerGroupList
This is the global list of TimerGroups, maintained by the TimerGroup ctor/dtor and is protected by th...
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void print(raw_ostream &OS, bool ResetAfterPrint=false)
Print any started timers in this group, optionally resetting timers after printing them...
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
void clear()
Clear the timer state.
static ManagedStatic< std::string > LibSupportInfoOutputFilename
void startTimerInterval(Timer *T)
Begin a signposted interval for the given timer.
static ManagedStatic< Name2PairMap > NamedGroupedTimers
static size_t GetMallocUsage()
Return process memory usage.
void sort(IteratorTy Start, IteratorTy End)
ssize_t getMemUsed() const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
double getProcessTime() const
static TimerGroup * getDefaultTimerGroup()
double getSystemTime() const
The file should be opened in append mode.
bool isInitialized() const
void startTimer()
Start the timer running.
static void clearAll()
Clear out all timers.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static std::string & getLibSupportInfoOutputFilename()
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
void clear()
Clear all timers in this group.
static ManagedStatic< TimerGroup, CreateDefaultTimerGroup > DefaultTimerGroup
static const char * printAllJSONValues(raw_ostream &OS, const char *delim)
Prints all timers as JSON key/value pairs.
Provides a library for accessing information about this process and other processes on the operating ...
The TimerGroup class is used to group together related timers into a single report that is printed wh...
double getWallTime() const
static void GetTimeUsage(TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, std::chrono::nanoseconds &sys_time)
This static function will set user_time to the amount of CPU time spent in user (non-kernel) mode and...
NamedRegionTimer(StringRef Name, StringRef Description, StringRef GroupName, StringRef GroupDescription, bool Enabled=true)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void ConstructTimerLists()
Ensure global timer group lists are initialized.
LLVM Value Representation.
static void printAll(raw_ostream &OS)
This static method prints all timers.
This class implements an extremely fast bulk output stream that can only output to a stream...
static size_t getMemUsage()
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
void endTimerInterval(Timer *T)
End a signposted interval for the given timer.
LocationClass< Ty > location(Ty &L)
static ManagedStatic< sys::SmartMutex< true > > TimerLock
bool hasTriggered() const
Check if startTimer() has ever been called on this timer.
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.