Use 64-bit integer counters for tracking time, rather than doubles. This will be more atomic op friendly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73974 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-06-23 18:12:30 +00:00
parent d9bc6a92f5
commit cd92c1000e
2 changed files with 27 additions and 27 deletions

View File

@ -34,12 +34,12 @@ class TimerGroup;
/// if they are never started. /// if they are never started.
/// ///
class Timer { class Timer {
double Elapsed; // Wall clock time elapsed in seconds uint64_t Elapsed; // Wall clock time elapsed in seconds
double UserTime; // User time elapsed uint64_t UserTime; // User time elapsed
double SystemTime; // System time elapsed uint64_t SystemTime; // System time elapsed
ssize_t MemUsed; // Memory allocated (in bytes) uint64_t MemUsed; // Memory allocated (in bytes)
size_t PeakMem; // Peak memory used uint64_t PeakMem; // Peak memory used
size_t PeakMemBase; // Temporary for peak calculation... uint64_t PeakMemBase; // Temporary for peak calculation...
std::string Name; // The name of this time variable std::string Name; // The name of this time variable
bool Started; // Has this time variable ever been started? bool Started; // Has this time variable ever been started?
TimerGroup *TG; // The TimerGroup this Timer is in. TimerGroup *TG; // The TimerGroup this Timer is in.
@ -49,10 +49,10 @@ public:
Timer(const Timer &T); Timer(const Timer &T);
~Timer(); ~Timer();
double getProcessTime() const { return UserTime+SystemTime; } uint64_t getProcessTime() const { return UserTime+SystemTime; }
double getWallTime() const { return Elapsed; } uint64_t getWallTime() const { return Elapsed; }
ssize_t getMemUsed() const { return MemUsed; } uint64_t getMemUsed() const { return MemUsed; }
size_t getPeakMem() const { return PeakMem; } uint64_t getPeakMem() const { return PeakMem; }
std::string getName() const { return Name; } std::string getName() const { return Name; }
const Timer &operator=(const Timer &T) { const Timer &operator=(const Timer &T) {

View File

@ -112,8 +112,7 @@ static inline size_t getMemUsage() {
} }
struct TimeRecord { struct TimeRecord {
double Elapsed, UserTime, SystemTime; uint64_t Elapsed, UserTime, SystemTime, MemUsed;
ssize_t MemUsed;
}; };
static TimeRecord getTimeRecord(bool Start) { static TimeRecord getTimeRecord(bool Start) {
@ -123,7 +122,7 @@ static TimeRecord getTimeRecord(bool Start) {
sys::TimeValue user(0,0); sys::TimeValue user(0,0);
sys::TimeValue sys(0,0); sys::TimeValue sys(0,0);
ssize_t MemUsed = 0; uint64_t MemUsed = 0;
if (Start) { if (Start) {
MemUsed = getMemUsage(); MemUsed = getMemUsage();
sys::Process::GetTimeUsage(now,user,sys); sys::Process::GetTimeUsage(now,user,sys);
@ -132,9 +131,9 @@ static TimeRecord getTimeRecord(bool Start) {
MemUsed = getMemUsage(); MemUsed = getMemUsage();
} }
Result.Elapsed = now.seconds() + now.microseconds() / 1000000.0; Result.Elapsed = now.seconds() * 1000000 + now.microseconds();
Result.UserTime = user.seconds() + user.microseconds() / 1000000.0; Result.UserTime = user.seconds() * 1000000 + user.microseconds();
Result.SystemTime = sys.seconds() + sys.microseconds() / 1000000.0; Result.SystemTime = sys.seconds() * 1000000 + sys.microseconds();
Result.MemUsed = MemUsed; Result.MemUsed = MemUsed;
return Result; return Result;
@ -277,12 +276,13 @@ static void printVal(double Val, double Total, std::ostream &OS) {
void Timer::print(const Timer &Total, std::ostream &OS) { void Timer::print(const Timer &Total, std::ostream &OS) {
if (Total.UserTime) if (Total.UserTime)
printVal(UserTime, Total.UserTime, OS); printVal(UserTime / 1000000.0, Total.UserTime / 1000000.0, OS);
if (Total.SystemTime) if (Total.SystemTime)
printVal(SystemTime, Total.SystemTime, OS); printVal(SystemTime / 1000000.0, Total.SystemTime / 1000000.0, OS);
if (Total.getProcessTime()) if (Total.getProcessTime())
printVal(getProcessTime(), Total.getProcessTime(), OS); printVal(getProcessTime() / 1000000.0,
printVal(Elapsed, Total.Elapsed, OS); Total.getProcessTime() / 1000000.0, OS);
printVal(Elapsed / 1000000.0, Total.Elapsed / 1000000.0, OS);
OS << " "; OS << " ";
@ -355,23 +355,23 @@ void TimerGroup::removeTimer() {
if (this != DefaultTimerGroup) { if (this != DefaultTimerGroup) {
*OutStream << " Total Execution Time: "; *OutStream << " Total Execution Time: ";
printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream); printAlignedFP(Total.getProcessTime() / 1000000.0, 4, 5, *OutStream);
*OutStream << " seconds ("; *OutStream << " seconds (";
printAlignedFP(Total.getWallTime(), 4, 5, *OutStream); printAlignedFP(Total.getWallTime() / 1000000.0, 4, 5, *OutStream);
*OutStream << " wall clock)\n"; *OutStream << " wall clock)\n";
} }
*OutStream << "\n"; *OutStream << "\n";
if (Total.UserTime) if (Total.UserTime / 1000000.0)
*OutStream << " ---User Time---"; *OutStream << " ---User Time---";
if (Total.SystemTime) if (Total.SystemTime / 1000000.0)
*OutStream << " --System Time--"; *OutStream << " --System Time--";
if (Total.getProcessTime()) if (Total.getProcessTime() / 1000000.0)
*OutStream << " --User+System--"; *OutStream << " --User+System--";
*OutStream << " ---Wall Time---"; *OutStream << " ---Wall Time---";
if (Total.getMemUsed()) if (Total.getMemUsed() / 1000000.0)
*OutStream << " ---Mem---"; *OutStream << " ---Mem---";
if (Total.getPeakMem()) if (Total.getPeakMem() / 1000000.0)
*OutStream << " -PeakMem-"; *OutStream << " -PeakMem-";
*OutStream << " --- Name ---\n"; *OutStream << " --- Name ---\n";