Skip to content
Snippets Groups Projects
Commit be58ad5f authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: Fully scope methods in clockTime, cpuTime

parent 6c0e040b
Branches
Tags
No related merge requests found
......@@ -24,38 +24,25 @@ License
\*---------------------------------------------------------------------------*/
#include "clockTime.H"
#include "scalar.H"
#include <sys/time.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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
// ************************************************************************* //
......@@ -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
//- Returns CPU time from start of run
double elapsedTime() const;
//- Return time (in seconds) from the start
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;
};
......
......@@ -21,45 +21,32 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Starts timing CPU usage and return elapsed time from start.
\*---------------------------------------------------------------------------*/
#include "cpuTime.H"
#include <unistd.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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
// ************************************************************************* //
......@@ -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
//- Returns CPU time from start of run
double elapsedCpuTime() const;
//- Return CPU time (in seconds) from the start
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;
};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment