mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: reorganize cpuTime into C++ and POSIX versions (#1238)
This commit is contained in:
committed by
Andrew Heather
parent
b56fbc4377
commit
f76733711b
@ -1,5 +1,5 @@
|
||||
cpuInfo/cpuInfo.C
|
||||
cpuTime/cpuTime.C
|
||||
cpuTime/cpuTimePosix.C
|
||||
memInfo/memInfo.C
|
||||
|
||||
signals/sigFpe.C
|
||||
|
||||
40
src/OSspecific/POSIX/cpuTime.H
Normal file
40
src/OSspecific/POSIX/cpuTime.H
Normal file
@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::cpuTime
|
||||
|
||||
Description
|
||||
Selection of preferred clock mechanism for the elapsed cpu time.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cpuTime_H
|
||||
#define cpuTime_H
|
||||
|
||||
#include "cpuTimePosix.H"
|
||||
#include "cpuTimeFwd.H"
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -25,17 +25,18 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "cpuTime.H"
|
||||
#include "cpuTimePosix.H"
|
||||
#include <unistd.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
|
||||
|
||||
const long Foam::cpuTime::clockTicks_(sysconf(_SC_CLK_TCK));
|
||||
// Clock-ticks per second
|
||||
static const long clockTicks_(sysconf(_SC_CLK_TCK));
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
double Foam::cpuTime::diff(const value_type& a, const value_type& b)
|
||||
inline double Foam::cpuTimePosix::diff(const value_type& a, const value_type& b)
|
||||
{
|
||||
return
|
||||
(
|
||||
@ -47,13 +48,13 @@ double Foam::cpuTime::diff(const value_type& a, const value_type& b)
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cpuTime::value_type::value_type()
|
||||
Foam::cpuTimePosix::value_type::value_type()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Foam::cpuTime::cpuTime()
|
||||
Foam::cpuTimePosix::cpuTimePosix()
|
||||
:
|
||||
start_(),
|
||||
last_(start_)
|
||||
@ -62,27 +63,27 @@ Foam::cpuTime::cpuTime()
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::cpuTime::value_type::update()
|
||||
void Foam::cpuTimePosix::value_type::update()
|
||||
{
|
||||
::times(this);
|
||||
}
|
||||
|
||||
|
||||
void Foam::cpuTime::resetCpuTime()
|
||||
void Foam::cpuTimePosix::resetCpuTime()
|
||||
{
|
||||
last_.update();
|
||||
start_ = last_;
|
||||
}
|
||||
|
||||
|
||||
double Foam::cpuTime::elapsedCpuTime() const
|
||||
double Foam::cpuTimePosix::elapsedCpuTime() const
|
||||
{
|
||||
last_.update();
|
||||
return diff(last_, start_);
|
||||
}
|
||||
|
||||
|
||||
double Foam::cpuTime::cpuTimeIncrement() const
|
||||
double Foam::cpuTimePosix::cpuTimeIncrement() const
|
||||
{
|
||||
const value_type prev(last_);
|
||||
last_.update();
|
||||
@ -24,7 +24,7 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::cpuTime
|
||||
Foam::cpuTimePosix
|
||||
|
||||
Description
|
||||
Starts timing CPU usage and return elapsed time from start.
|
||||
@ -33,12 +33,12 @@ See also
|
||||
clockTime
|
||||
|
||||
SourceFiles
|
||||
cpuTime.C
|
||||
cpuTimePosix.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cpuTime_H
|
||||
#define cpuTime_H
|
||||
#ifndef cpuTimePosix_H
|
||||
#define cpuTimePosix_H
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
@ -50,10 +50,10 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class cpuTime Declaration
|
||||
Class cpuTimePosix Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class cpuTime
|
||||
class cpuTimePosix
|
||||
{
|
||||
//- Time structure used, with additional methods
|
||||
struct value_type : tms
|
||||
@ -74,14 +74,11 @@ class cpuTime
|
||||
//- Last time when elapsedTime or timeIncrement was called
|
||||
mutable value_type last_;
|
||||
|
||||
//- Clock-ticks per second
|
||||
static const long clockTicks_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Difference between two times (a - b)
|
||||
static double diff(const value_type& a, const value_type& b);
|
||||
//- Difference between two times (a - b)
|
||||
inline static double diff(const value_type& a, const value_type& b);
|
||||
|
||||
|
||||
public:
|
||||
@ -89,7 +86,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct with the current clock time
|
||||
cpuTime();
|
||||
cpuTimePosix();
|
||||
|
||||
|
||||
// Member Functions
|
||||
49
src/OSspecific/POSIX/cpuTimeFwd.H
Normal file
49
src/OSspecific/POSIX/cpuTimeFwd.H
Normal file
@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::cpuTime
|
||||
|
||||
Description
|
||||
Selection of preferred clock mechanism for the elapsed cpu time.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cpuTimeFwd_H
|
||||
#define cpuTimeFwd_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
class cpuTimeCxx;
|
||||
class cpuTimePosix;
|
||||
|
||||
typedef cpuTimePosix cpuTime;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -6,6 +6,7 @@ global/argList/argListHelp.C
|
||||
global/clock/clock.C
|
||||
global/clockTime/clockTime.C
|
||||
global/clockValue/clockValue.C
|
||||
global/cpuTime/cpuTimeCxx.C
|
||||
global/profiling/profiling.C
|
||||
global/profiling/profilingInformation.C
|
||||
global/profiling/profilingSysInfo.C
|
||||
|
||||
81
src/OpenFOAM/global/cpuTime/cpuTimeCxx.C
Normal file
81
src/OpenFOAM/global/cpuTime/cpuTimeCxx.C
Normal file
@ -0,0 +1,81 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "cpuTimeCxx.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
inline double Foam::cpuTimeCxx::diff(const value_type& a, const value_type& b)
|
||||
{
|
||||
return std::difftime(a.value, b.value) / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cpuTimeCxx::value_type::value_type()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Foam::cpuTimeCxx::cpuTimeCxx()
|
||||
:
|
||||
start_(),
|
||||
last_(start_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::cpuTimeCxx::value_type::update()
|
||||
{
|
||||
value = std::clock();
|
||||
}
|
||||
|
||||
|
||||
void Foam::cpuTimeCxx::resetCpuTime()
|
||||
{
|
||||
last_.update();
|
||||
start_ = last_;
|
||||
}
|
||||
|
||||
|
||||
double Foam::cpuTimeCxx::elapsedCpuTime() const
|
||||
{
|
||||
last_.update();
|
||||
return diff(last_, start_);
|
||||
}
|
||||
|
||||
|
||||
double Foam::cpuTimeCxx::cpuTimeIncrement() const
|
||||
{
|
||||
const value_type prev(last_);
|
||||
last_.update();
|
||||
return diff(last_, prev);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
111
src/OpenFOAM/global/cpuTime/cpuTimeCxx.H
Normal file
111
src/OpenFOAM/global/cpuTime/cpuTimeCxx.H
Normal file
@ -0,0 +1,111 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::cpuTimeCxx
|
||||
|
||||
Description
|
||||
Starts timing CPU usage and return elapsed time from start.
|
||||
|
||||
See also
|
||||
clockTime
|
||||
|
||||
SourceFiles
|
||||
cpuTimeCxx.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cpuTimeCxx_H
|
||||
#define cpuTimeCxx_H
|
||||
|
||||
#include <ctime>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class cpuTimeCxx Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class cpuTimeCxx
|
||||
{
|
||||
//- Time structure used, with additional methods
|
||||
struct value_type
|
||||
{
|
||||
std::clock_t value;
|
||||
|
||||
//- Construct with the current clock time
|
||||
value_type();
|
||||
|
||||
//- Update with the current clock time
|
||||
void update();
|
||||
};
|
||||
|
||||
|
||||
// Private Data
|
||||
|
||||
//- Start time, at the time of construction
|
||||
value_type start_;
|
||||
|
||||
//- Last time when elapsedTime or timeIncrement was called
|
||||
mutable value_type last_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Difference between two times (a - b)
|
||||
static inline double diff(const value_type& a, const value_type& b);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct with the current clock time
|
||||
cpuTimeCxx();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Reset to use the current time for the start time
|
||||
void resetCpuTime();
|
||||
|
||||
//- Return CPU time (in seconds) from the start
|
||||
double elapsedCpuTime() const;
|
||||
|
||||
//- Return CPU time (in seconds) since last call to cpuTimeIncrement()
|
||||
double cpuTimeIncrement() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user