forked from OSchip/llvm-project
various timer fixes: move operator= out of line,
eliminate the per-timer lock (timers should be externally locked if needed), the info-output-stream can never be dbgs(), so drop the check. Make some stuff private. llvm-svn: 99839
This commit is contained in:
parent
2788f797ca
commit
b355db7877
|
@ -40,54 +40,27 @@ class Timer {
|
||||||
double SystemTime; // System time elapsed
|
double SystemTime; // System time elapsed
|
||||||
ssize_t MemUsed; // Memory allocated (in bytes)
|
ssize_t MemUsed; // Memory allocated (in bytes)
|
||||||
size_t PeakMem; // Peak memory used
|
size_t PeakMem; // Peak memory used
|
||||||
size_t PeakMemBase; // Temporary for peak calculation...
|
size_t PeakMemBase; // Temporary for peak memory 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.
|
||||||
mutable sys::SmartMutex<true> Lock; // Mutex for the contents of this Timer.
|
|
||||||
public:
|
public:
|
||||||
explicit Timer(const std::string &N);
|
explicit Timer(const std::string &N);
|
||||||
Timer(const std::string &N, TimerGroup &tg);
|
Timer(const std::string &N, TimerGroup &tg);
|
||||||
Timer(const Timer &T);
|
Timer(const Timer &T);
|
||||||
~Timer();
|
~Timer();
|
||||||
|
|
||||||
|
private:
|
||||||
double getProcessTime() const { return UserTime+SystemTime; }
|
double getProcessTime() const { return UserTime+SystemTime; }
|
||||||
double getWallTime() const { return Elapsed; }
|
double getWallTime() const { return Elapsed; }
|
||||||
ssize_t getMemUsed() const { return MemUsed; }
|
ssize_t getMemUsed() const { return MemUsed; }
|
||||||
size_t getPeakMem() const { return PeakMem; }
|
size_t getPeakMem() const { return PeakMem; }
|
||||||
|
public:
|
||||||
std::string getName() const { return Name; }
|
std::string getName() const { return Name; }
|
||||||
|
|
||||||
const Timer &operator=(const Timer &T) {
|
const Timer &operator=(const Timer &T);
|
||||||
if (&T < this) {
|
|
||||||
T.Lock.acquire();
|
|
||||||
Lock.acquire();
|
|
||||||
} else {
|
|
||||||
Lock.acquire();
|
|
||||||
T.Lock.acquire();
|
|
||||||
}
|
|
||||||
|
|
||||||
Elapsed = T.Elapsed;
|
// operator< - Allow sorting.
|
||||||
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!");
|
|
||||||
|
|
||||||
if (&T < this) {
|
|
||||||
T.Lock.release();
|
|
||||||
Lock.release();
|
|
||||||
} else {
|
|
||||||
Lock.release();
|
|
||||||
T.Lock.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// operator< - Allow sorting...
|
|
||||||
bool operator<(const Timer &T) const {
|
bool operator<(const Timer &T) const {
|
||||||
// Sort by Wall Time elapsed, as it is the only thing really accurate
|
// Sort by Wall Time elapsed, as it is the only thing really accurate
|
||||||
return Elapsed < T.Elapsed;
|
return Elapsed < T.Elapsed;
|
||||||
|
|
|
@ -147,7 +147,6 @@ static TimeRecord getTimeRecord(bool Start) {
|
||||||
static ManagedStatic<std::vector<Timer*> > ActiveTimers;
|
static ManagedStatic<std::vector<Timer*> > ActiveTimers;
|
||||||
|
|
||||||
void Timer::startTimer() {
|
void Timer::startTimer() {
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
|
||||||
Started = true;
|
Started = true;
|
||||||
ActiveTimers->push_back(this);
|
ActiveTimers->push_back(this);
|
||||||
TimeRecord TR = getTimeRecord(true);
|
TimeRecord TR = getTimeRecord(true);
|
||||||
|
@ -159,7 +158,6 @@ void Timer::startTimer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::stopTimer() {
|
void Timer::stopTimer() {
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
|
||||||
TimeRecord TR = getTimeRecord(false);
|
TimeRecord TR = getTimeRecord(false);
|
||||||
Elapsed += TR.Elapsed;
|
Elapsed += TR.Elapsed;
|
||||||
UserTime += TR.UserTime;
|
UserTime += TR.UserTime;
|
||||||
|
@ -184,14 +182,26 @@ void Timer::sum(const Timer &T) {
|
||||||
PeakMem += T.PeakMem;
|
PeakMem += T.PeakMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Timer &Timer::operator=(const Timer &T) {
|
||||||
|
Elapsed = T.Elapsed;
|
||||||
|
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!");
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// addPeakMemoryMeasurement - This method should be called whenever memory
|
/// addPeakMemoryMeasurement - This method should be called whenever memory
|
||||||
/// usage needs to be checked. It adds a peak memory measurement to the
|
/// 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
|
/// currently active timers, which will be printed when the timer group prints
|
||||||
///
|
///
|
||||||
void Timer::addPeakMemoryMeasurement() {
|
void Timer::addPeakMemoryMeasurement() {
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
|
||||||
size_t MemUsed = getMemUsage();
|
size_t MemUsed = getMemUsage();
|
||||||
|
|
||||||
for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
|
for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
|
||||||
E = ActiveTimers->end(); I != E; ++I)
|
E = ActiveTimers->end(); I != E; ++I)
|
||||||
(*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
|
(*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
|
||||||
|
@ -208,7 +218,6 @@ static void printVal(double Val, double Total, raw_ostream &OS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::print(const Timer &Total, raw_ostream &OS) {
|
void Timer::print(const Timer &Total, raw_ostream &OS) {
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
|
||||||
if (Total.UserTime)
|
if (Total.UserTime)
|
||||||
printVal(UserTime, Total.UserTime, OS);
|
printVal(UserTime, Total.UserTime, OS);
|
||||||
if (Total.SystemTime)
|
if (Total.SystemTime)
|
||||||
|
@ -219,13 +228,13 @@ void Timer::print(const Timer &Total, raw_ostream &OS) {
|
||||||
|
|
||||||
OS << " ";
|
OS << " ";
|
||||||
|
|
||||||
if (Total.MemUsed) {
|
if (Total.MemUsed)
|
||||||
OS << format("%9lld", (long long)MemUsed) << " ";
|
OS << format("%9lld", (long long)MemUsed) << " ";
|
||||||
}
|
|
||||||
if (Total.PeakMem) {
|
if (Total.PeakMem) {
|
||||||
if (PeakMem) {
|
if (PeakMem)
|
||||||
OS << format("%9lld", (long long)PeakMem) << " ";
|
OS << format("%9lld", (long long)PeakMem) << " ";
|
||||||
} else
|
else
|
||||||
OS << " ";
|
OS << " ";
|
||||||
}
|
}
|
||||||
OS << Name << "\n";
|
OS << Name << "\n";
|
||||||
|
@ -286,15 +295,13 @@ NamedRegionTimer::NamedRegionTimer(const std::string &Name,
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
|
// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
|
||||||
raw_ostream *
|
raw_ostream *llvm::GetLibSupportInfoOutputFile() {
|
||||||
llvm::GetLibSupportInfoOutputFile() {
|
|
||||||
std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
|
std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
|
||||||
if (LibSupportInfoOutputFilename.empty())
|
if (LibSupportInfoOutputFilename.empty())
|
||||||
return &errs();
|
return &errs();
|
||||||
if (LibSupportInfoOutputFilename == "-")
|
if (LibSupportInfoOutputFilename == "-")
|
||||||
return &outs();
|
return &outs();
|
||||||
|
|
||||||
|
|
||||||
std::string Error;
|
std::string Error;
|
||||||
raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
|
raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
|
||||||
Error, raw_fd_ostream::F_Append);
|
Error, raw_fd_ostream::F_Append);
|
||||||
|
@ -373,7 +380,7 @@ void TimerGroup::removeTimer() {
|
||||||
|
|
||||||
TimersToPrint.clear();
|
TimersToPrint.clear();
|
||||||
|
|
||||||
if (OutStream != &errs() && OutStream != &outs() && OutStream != &dbgs())
|
if (OutStream != &errs() && OutStream != &outs())
|
||||||
delete OutStream; // Close the file.
|
delete OutStream; // Close the file.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue