Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPUTimer: switch to clock_gettime #4667

Merged
merged 1 commit into from Jul 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions FWCore/Utilities/interface/CPUTimer.h
Expand Up @@ -20,10 +20,8 @@

// system include files
#ifdef __linux__
//NOTE: clock_gettime is not available on OS X and is slower
// than getrusage and gettimeofday on linux but gives greater
// timing accuracy so we may want to revisit this in the future
//#define USE_CLOCK_GETTIME
//clock_gettime is not available on OS X
#define USE_CLOCK_GETTIME
#endif

#ifdef USE_CLOCK_GETTIME
Expand Down
8 changes: 4 additions & 4 deletions FWCore/Utilities/src/CPUTimer.cc
Expand Up @@ -74,7 +74,7 @@ void
CPUTimer::start() {
if(kStopped == state_) {
#ifdef USE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &startRealTime_);
clock_gettime(CLOCK_MONOTONIC, &startRealTime_);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &startCPUTime_);
#else
gettimeofday(&startRealTime_, 0);
Expand All @@ -83,8 +83,8 @@ CPUTimer::start() {
if(0 != getrusage(RUSAGE_SELF, &theUsage)) {
throw cms::Exception("CPUTimerFailed")<<errno;
}
startCPUTime_.tv_sec =theUsage.ru_stime.tv_sec+theUsage.ru_utime.tv_sec;
startCPUTime_.tv_usec =theUsage.ru_stime.tv_usec+theUsage.ru_utime.tv_usec;
startCPUTime_.tv_sec = theUsage.ru_stime.tv_sec + theUsage.ru_utime.tv_sec;
startCPUTime_.tv_usec = theUsage.ru_stime.tv_usec + theUsage.ru_utime.tv_usec;
#endif
state_ = kRunning;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ CPUTimer::calculateDeltaTime() const {
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
returnValue.cpu_ = tp.tv_sec - startCPUTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startCPUTime_.tv_nsec);

clock_gettime(CLOCK_REALTIME, &tp);
clock_gettime(CLOCK_MONOTONIC, &tp);
returnValue.real_ = tp.tv_sec - startRealTime_.tv_sec + nanosecToSec * (tp.tv_nsec - startRealTime_.tv_nsec);
#else
rusage theUsage;
Expand Down