diff --git a/src/OSspecific/POSIX/clockTime/clockTime.C b/src/OSspecific/POSIX/clockTime/clockTime.C index 31a6d2c4bd..3c65d023ff 100644 --- a/src/OSspecific/POSIX/clockTime/clockTime.C +++ b/src/OSspecific/POSIX/clockTime/clockTime.C @@ -24,38 +24,25 @@ License \*---------------------------------------------------------------------------*/ #include "clockTime.H" -#include "scalar.H" #include -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * // - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void clockTime::getTime(struct timeval& t) +void Foam::clockTime::getTime(timeType& t) { - gettimeofday(&t, NULL); + gettimeofday(&t, 0); } -double clockTime::timeDifference -( - const struct timeval& start, - const struct timeval& end -) +double Foam::clockTime::timeDifference(const timeType& beg, const timeType& end) { - return end.tv_sec - start.tv_sec + 1E-6*(end.tv_usec - start.tv_usec); + return end.tv_sec - beg.tv_sec + 1E-6*(end.tv_usec - beg.tv_usec); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -clockTime::clockTime() +Foam::clockTime::clockTime() { getTime(startTime_); lastTime_ = startTime_; @@ -65,14 +52,14 @@ clockTime::clockTime() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -double clockTime::elapsedTime() const +double Foam::clockTime::elapsedTime() const { getTime(newTime_); return timeDifference(startTime_, newTime_); } -double clockTime::timeIncrement() const +double Foam::clockTime::timeIncrement() const { lastTime_ = newTime_; getTime(newTime_); @@ -80,8 +67,4 @@ double clockTime::timeIncrement() const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OSspecific/POSIX/clockTime/clockTime.H b/src/OSspecific/POSIX/clockTime/clockTime.H index 5237233f05..c8bbbdba6c 100644 --- a/src/OSspecific/POSIX/clockTime/clockTime.H +++ b/src/OSspecific/POSIX/clockTime/clockTime.H @@ -44,43 +44,45 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class clockTime Declaration + Class clockTime Declaration \*---------------------------------------------------------------------------*/ class clockTime { // Private data - struct timeval startTime_; - mutable struct timeval lastTime_; - mutable struct timeval newTime_; + //- Time structure used + typedef struct timeval timeType; - static void getTime(struct timeval& t); + timeType startTime_; - static double timeDifference - ( - const struct timeval& start, - const struct timeval& end - ); + mutable timeType lastTime_; + mutable timeType newTime_; + + // Private Member Functions + + //- Retrieve the current time values from the system + static void getTime(timeType&); + + //- Difference between two times + static double timeDifference(const timeType& beg, const timeType& end); public: // Constructors - //- Construct from components + //- Construct with the current clock time clockTime(); // Member Functions - // Access + //- Return time (in seconds) from the start + double elapsedTime() const; - //- Returns CPU time from start of run - double elapsedTime() const; - - //- Returns CPU time from last call of clockTimeIncrement() - double timeIncrement() const; + //- Return time (in seconds) since last call to timeIncrement() + double timeIncrement() const; }; diff --git a/src/OSspecific/POSIX/cpuTime/cpuTime.C b/src/OSspecific/POSIX/cpuTime/cpuTime.C index b5ef0c4283..5af53026fd 100644 --- a/src/OSspecific/POSIX/cpuTime/cpuTime.C +++ b/src/OSspecific/POSIX/cpuTime/cpuTime.C @@ -21,45 +21,32 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Description - Starts timing CPU usage and return elapsed time from start. - \*---------------------------------------------------------------------------*/ #include "cpuTime.H" - #include -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - // * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * // -long cpuTime::Hz_(sysconf(_SC_CLK_TCK)); +const long Foam::cpuTime::Hz_(sysconf(_SC_CLK_TCK)); // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void cpuTime::getTime(struct tms& t) +void Foam::cpuTime::getTime(timeType& t) { times(&t); } -double cpuTime::timeDifference -( - const struct tms& start, - const struct tms& end -) +double Foam::cpuTime::timeDifference(const timeType& beg, const timeType& end) { return ( double ( (end.tms_utime + end.tms_stime) - - (start.tms_utime + start.tms_stime) + - (beg.tms_utime + beg.tms_stime) )/Hz_ ); } @@ -67,7 +54,7 @@ double cpuTime::timeDifference // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -cpuTime::cpuTime() +Foam::cpuTime::cpuTime() { getTime(startTime_); lastTime_ = startTime_; @@ -77,14 +64,14 @@ cpuTime::cpuTime() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -double cpuTime::elapsedCpuTime() const +double Foam::cpuTime::elapsedCpuTime() const { getTime(newTime_); return timeDifference(startTime_, newTime_); } -double cpuTime::cpuTimeIncrement() const +double Foam::cpuTime::cpuTimeIncrement() const { lastTime_ = newTime_; getTime(newTime_); @@ -92,8 +79,4 @@ double cpuTime::cpuTimeIncrement() const } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OSspecific/POSIX/cpuTime/cpuTime.H b/src/OSspecific/POSIX/cpuTime/cpuTime.H index e3a6376360..33e3259304 100644 --- a/src/OSspecific/POSIX/cpuTime/cpuTime.H +++ b/src/OSspecific/POSIX/cpuTime/cpuTime.H @@ -54,38 +54,41 @@ class cpuTime { // Private data - static long Hz_; + //- Time structure used + typedef struct tms timeType; - struct tms startTime_; - mutable struct tms lastTime_; - mutable struct tms newTime_; + //- Clock-ticks per second + static const long Hz_; - static void getTime(struct tms& t); + //- The start time + timeType startTime_; + mutable timeType lastTime_; + mutable timeType newTime_; - static double timeDifference - ( - const struct tms& start, - const struct tms& end - ); + // Private Member Functions + + //- Retrieve the current time values from the system + static void getTime(timeType&); + + //- Difference between two times + static double timeDifference(const timeType& beg, const timeType& end); public: // Constructors - //- Construct from components + //- Construct with the current clock time cpuTime(); // Member Functions - // Access + //- Return CPU time (in seconds) from the start + double elapsedCpuTime() const; - //- Returns CPU time from start of run - double elapsedCpuTime() const; - - //- Returns CPU time from last call of cpuTimeIncrement() - double cpuTimeIncrement() const; + //- Return CPU time (in seconds) since last call to cpuTimeIncrement() + double cpuTimeIncrement() const; };