#define LLVM_SUPPORT_TIMER_H
#include "llvm/System/DataTypes.h"
-#include "llvm/System/Mutex.h"
#include <string>
#include <vector>
#include <cassert>
double UserTime; // User time elapsed
double SystemTime; // System time elapsed
ssize_t MemUsed; // Memory allocated (in bytes)
- size_t PeakMem; // Peak memory used
- size_t PeakMemBase; // Temporary for peak memory calculation.
std::string Name; // The name of this time variable.
bool Started; // Has this time variable ever been started?
TimerGroup *TG; // The TimerGroup this Timer is in.
double getProcessTime() const { return UserTime+SystemTime; }
double getWallTime() const { return Elapsed; }
ssize_t getMemUsed() const { return MemUsed; }
- size_t getPeakMem() const { return PeakMem; }
public:
std::string getName() const { return Name; }
///
void stopTimer();
- /// addPeakMemoryMeasurement - This method should be called whenever memory
- /// usage needs to be checked. It adds a peak memory measurement to the
- /// currently active timers, which will be printed when the timer group prints
- ///
- static void addPeakMemoryMeasurement();
-
/// print - Print the current timer to standard error, and reset the "Started"
/// flag.
void print(const Timer &Total, raw_ostream &OS);
//
//===----------------------------------------------------------------------===//
-#include "llvm/Support/Debug.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Format.h"
+#include "llvm/System/Mutex.h"
#include "llvm/System/Process.h"
-#include <algorithm>
-#include <functional>
#include <map>
using namespace llvm;
//===----------------------------------------------------------------------===//
Timer::Timer(const std::string &N)
- : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
+ : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), Name(N),
Started(false), TG(getDefaultTimerGroup()) {
TG->addTimer();
}
Timer::Timer(const std::string &N, TimerGroup &tg)
- : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), PeakMem(0), Name(N),
+ : Elapsed(0), UserTime(0), SystemTime(0), MemUsed(0), Name(N),
Started(false), TG(&tg) {
TG->addTimer();
}
UserTime -= TR.UserTime;
SystemTime -= TR.SystemTime;
MemUsed -= TR.MemUsed;
- PeakMemBase = TR.MemUsed;
}
void Timer::stopTimer() {
UserTime += T.UserTime;
SystemTime += T.SystemTime;
MemUsed += T.MemUsed;
- PeakMem += T.PeakMem;
}
const Timer &Timer::operator=(const Timer &T) {
UserTime = T.UserTime;
SystemTime = T.SystemTime;
MemUsed = T.MemUsed;
- PeakMem = T.PeakMem;
- PeakMemBase = T.PeakMemBase;
Name = T.Name;
Started = T.Started;
assert(TG == T.TG && "Can only assign timers in the same TimerGroup!");
}
-/// addPeakMemoryMeasurement - This method should be called whenever memory
-/// usage needs to be checked. It adds a peak memory measurement to the
-/// currently active timers, which will be printed when the timer group prints
-///
-void Timer::addPeakMemoryMeasurement() {
- size_t MemUsed = getMemUsage();
- for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
- E = ActiveTimers->end(); I != E; ++I)
- (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
-}
-
-
static void printVal(double Val, double Total, raw_ostream &OS) {
if (Total < 1e-7) // Avoid dividing by zero.
OS << " ----- ";
if (Total.MemUsed)
OS << format("%9lld", (long long)MemUsed) << " ";
- if (Total.PeakMem) {
- if (PeakMem)
- OS << format("%9lld", (long long)PeakMem) << " ";
- else
- OS << " ";
- }
OS << Name << "\n";
Started = false; // Once printed, don't print again
*OutStream << " ---Wall Time---";
if (Total.getMemUsed())
*OutStream << " ---Mem---";
- if (Total.getPeakMem())
- *OutStream << " -PeakMem-";
*OutStream << " --- Name ---\n";
// Loop through all of the timing data, printing it out.