-// getNumBytesToNotCount - This function is supposed to return the number of
-// bytes that are to be considered not allocated, even though malloc thinks they
-// are allocated.
-//
-static unsigned getNumBytesToNotCount() {
-#ifdef HAVE_POOL
- // If we have GCC 3.2.0, we can subtract off pool allocation bookkeeping info
-
- // Size of the free slab section...
- unsigned FreePoolMem = (unsigned)(EndFree-StartFree);
-
- // Walk all of the free lists, adding memory to the free counter whenever we
- // have a free bucket.
- for (unsigned i = 0; i != NFREE; ++i) {
- unsigned NumEntries = 0;
- for (FreeList *FL = TheFreeList[i]; FL; ++NumEntries, FL = FL->Next)
- /*empty*/ ;
-
-#if 0
- if (NumEntries)
- std::cerr << " For Size[" << (i+1)*_ALIGN << "]: " << NumEntries
- << " Free entries\n";
-#endif
- FreePoolMem += NumEntries*(i+1)*_ALIGN;
+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;
+}
+
+void TimerGroup::PrintQueuedTimers(raw_ostream &OS) {
+ // Sort the timers in descending order by amount of time taken.
+ std::sort(TimersToPrint.begin(), TimersToPrint.end());
+
+ TimeRecord Total;
+ for (unsigned i = 0, e = TimersToPrint.size(); i != e; ++i)
+ Total += TimersToPrint[i].first;
+
+ // Print out timing header.
+ 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";
+
+ // 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.
+ if (this != DefaultTimerGroup)
+ OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
+ Total.getProcessTime(), Total.getWallTime());
+ OS << '\n';
+
+ if (Total.getUserTime())
+ OS << " ---User Time---";
+ if (Total.getSystemTime())
+ OS << " --System Time--";
+ if (Total.getProcessTime())
+ OS << " --User+System--";
+ OS << " ---Wall Time---";
+ if (Total.getMemUsed())
+ OS << " ---Mem---";
+ OS << " --- Name ---\n";
+
+ // 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];
+ Entry.first.print(Total, OS);
+ OS << Entry.second << '\n';