45 TrackSpace(
"track-memory",
cl::desc(
"Enable -time-passes memory "
46 "tracking (this may be slow)"),
51 cl::desc(
"File to append -stats and -timer output to"),
58 if (OutputFilename.empty())
60 if (OutputFilename ==
"-")
73 errs() <<
"Error opening info-output-file '"
74 << OutputFilename <<
" for appending!\n";
89 tmp =
new TimerGroup(
"Miscellaneous Ungrouped Timers");
102 assert(!TG &&
"Timer already initialized");
110 assert(!TG &&
"Timer already initialized");
119 TG->removeTimer(*
this);
123 if (!TrackSpace)
return 0;
140 Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
159 std::vector<Timer*>::iterator
I =
161 assert(I !=
ActiveTimers->end() &&
"stop but no startTimer?");
170 OS <<
format(
" %7.4f (%5.1f%%)", Val, Val*100/Total);
201 for (
StringMap<std::pair<TimerGroup*, Name2TimerMap> >::iterator
202 I = Map.begin(), E = Map.end();
I != E; ++
I)
203 delete I->second.first;
209 std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
211 if (!GroupEntry.first)
267 removeTimer(*FirstTimer);
277 void TimerGroup::removeTimer(
Timer &
T) {
282 TimersToPrint.push_back(std::make_pair(T.Time, T.Name));
289 T.Next->Prev = T.Prev;
293 if (FirstTimer || TimersToPrint.empty())
297 PrintQueuedTimers(*OutStream);
301 void TimerGroup::addTimer(
Timer &T) {
306 FirstTimer->Prev = &T.Next;
308 T.Prev = &FirstTimer;
312 void TimerGroup::PrintQueuedTimers(
raw_ostream &OS) {
314 std::sort(TimersToPrint.begin(), TimersToPrint.end());
317 for (
unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
318 Total += TimersToPrint[i].first;
321 OS <<
"===" << std::string(73,
'-') <<
"===\n";
323 unsigned Padding = (80-Name.length())/2;
324 if (Padding > 80) Padding = 0;
325 OS.
indent(Padding) << Name <<
'\n';
326 OS <<
"===" << std::string(73,
'-') <<
"===\n";
332 OS <<
format(
" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
333 Total.getProcessTime(), Total.getWallTime());
336 if (Total.getUserTime())
337 OS <<
" ---User Time---";
338 if (Total.getSystemTime())
339 OS <<
" --System Time--";
340 if (Total.getProcessTime())
341 OS <<
" --User+System--";
342 OS <<
" ---Wall Time---";
343 if (Total.getMemUsed())
345 OS <<
" --- Name ---\n";
348 for (
unsigned i = 0, e = TimersToPrint.size(); i != e; ++i) {
349 const std::pair<TimeRecord, std::string> &Entry = TimersToPrint[e-i-1];
350 Entry.first.print(Total, OS);
351 OS << Entry.second <<
'\n';
354 Total.print(Total, OS);
358 TimersToPrint.clear();
367 for (
Timer *T = FirstTimer;
T; T = T->Next) {
368 if (!T->Started)
continue;
369 TimersToPrint.push_back(std::make_pair(T->Time, T->Name));
377 if (!TimersToPrint.empty())
378 PrintQueuedTimers(OS);
bool isInitialized() const
const_iterator end(StringRef path)
Get end iterator over path.
F_Append - When opening a file, if it already exists append to the existing file instead of returning...
void print(const TimeRecord &Total, raw_ostream &OS) const
print - Print the current timer to standard error, and reset the "Started" flag.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static TimeRecord getCurrentTime(bool Start=true)
getCurrentTime - Get the current time and memory usage.
void stopTimer()
stopTimer - Stop the timer.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
const_iterator begin(StringRef path)
Get begin iterator over path.
NamedRegionTimer(StringRef Name, bool Enabled=true)
The TimeRegion class is used as a helper class to call the startTimer() and stopTimer() methods of th...
SecondsType seconds() const
Returns only the seconds component of the TimeValue.
double getProcessTime() const
static cl::opt< bool > Enabled("stats", cl::desc("Enable statistics output from program (available with Asserts)"))
-stats - Command line option to cause transformations to emit stats about what they did...
double getWallTime() const
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
Timer - This class is used to track the amount of time spent between invocations of its startTimer()/...
static ManagedStatic< Name2TimerMap > NamedTimers
double getUserTime() const
static void printVal(double Val, double Total, raw_ostream &OS)
static TimerGroup * DefaultTimerGroup
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
static TimerGroup * TimerGroupList
TimerGroupList - This is the global list of TimerGroups, maintained by the TimerGroup ctor/dtor and i...
static void GetTimeUsage(TimeValue &elapsed, TimeValue &user_time, TimeValue &sys_time)
This static function will set user_time to the amount of CPU time spent in user (non-kernel) mode and...
ssize_t getMemUsed() const
static ManagedStatic< std::string > LibSupportInfoOutputFilename
static ManagedStatic< Name2PairMap > NamedGroupedTimers
static ManagedStatic< std::vector< Timer * > > ActiveTimers
static size_t GetMallocUsage()
Return process memory usage.
void print(raw_ostream &OS)
print - Print any started timers in this group and zero them.
static TimerGroup * getDefaultTimerGroup()
double getSystemTime() const
void startTimer()
startTimer - Start the timer running.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static std::string & getLibSupportInfoOutputFilename()
The file should be opened in text mode on platforms that make this distinction.
Provides a library for accessing information about this process and other processes on the operating ...
raw_ostream * CreateInfoOutputFile()
A raw_ostream that writes to a file descriptor.
The TimerGroup class is used to group together related timers into a single report that is printed wh...
This class is used where a precise fixed point in time is required.
static void printAll(raw_ostream &OS)
printAll - This static method prints all timers and clears them all out.
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...
uint32_t microseconds() const
Returns only the fractional portion of the TimeValue rounded down to the nearest microsecond (divide ...
static Timer & getNamedRegionTimer(StringRef Name)
LocationClass< Ty > location(Ty &L)
static ManagedStatic< sys::SmartMutex< true > > TimerLock
static sys::TimeValue now(bool Deterministic)