#define LLVM_SUPPORT_TIMER_H
#include "llvm/Support/DataTypes.h"
+#include "llvm/System/Mutex.h"
#include <string>
#include <vector>
#include <iosfwd>
/// if they are never started.
///
class Timer {
- uint64_t Elapsed; // Wall clock time elapsed in seconds
- uint64_t UserTime; // User time elapsed
- uint64_t SystemTime; // System time elapsed
- uint64_t MemUsed; // Memory allocated (in bytes)
- uint64_t PeakMem; // Peak memory used
- uint64_t PeakMemBase; // Temporary for peak calculation...
+ double Elapsed; // Wall clock time elapsed in seconds
+ 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 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.
+ mutable sys::SmartMutex<true> Lock; // Mutex for the contents of this Timer.
public:
explicit Timer(const std::string &N);
Timer(const std::string &N, TimerGroup &tg);
Timer(const Timer &T);
~Timer();
- uint64_t getProcessTime() const { return UserTime+SystemTime; }
- uint64_t getWallTime() const { return Elapsed; }
- uint64_t getMemUsed() const { return MemUsed; }
- uint64_t getPeakMem() const { return PeakMem; }
+ double getProcessTime() const { return UserTime+SystemTime; }
+ double getWallTime() const { return Elapsed; }
+ ssize_t getMemUsed() const { return MemUsed; }
+ size_t getPeakMem() const { return PeakMem; }
std::string getName() const { return Name; }
const Timer &operator=(const Timer &T) {
+ if (&T < this) {
+ T.Lock.acquire();
+ Lock.acquire();
+ } else {
+ Lock.acquire();
+ T.Lock.acquire();
+ }
+
Elapsed = T.Elapsed;
UserTime = T.UserTime;
SystemTime = T.SystemTime;
Name = T.Name;
Started = T.Started;
assert(TG == T.TG && "Can only assign timers in the same TimerGroup!");
+
+ if (&T < this) {
+ T.Lock.release();
+ Lock.release();
+ } else {
+ Lock.release();
+ T.Lock.release();
+ }
+
return *this;
}
private:
friend class Timer;
- void addTimer() { ++NumTimers; }
+ void addTimer();
void removeTimer();
- void addTimerToPrint(const Timer &T) {
- TimersToPrint.push_back(Timer(true, T));
- }
+ void addTimerToPrint(const Timer &T);
};
} // End llvm namespace