diff --git a/applications/test/OSspecific/Make/files b/applications/test/OSspecific/Make/files
new file mode 100644
index 0000000000..b493846698
--- /dev/null
+++ b/applications/test/OSspecific/Make/files
@@ -0,0 +1,3 @@
+Test-OSspecific.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-OSspecific
diff --git a/applications/test/POSIX/Make/options b/applications/test/OSspecific/Make/options
similarity index 100%
rename from applications/test/POSIX/Make/options
rename to applications/test/OSspecific/Make/options
diff --git a/applications/test/OSspecific/Test-OSspecific.C b/applications/test/OSspecific/Test-OSspecific.C
new file mode 100644
index 0000000000..91e18644de
--- /dev/null
+++ b/applications/test/OSspecific/Test-OSspecific.C
@@ -0,0 +1,59 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / 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 .
+
+Description
+ Report some basic os-specific values
+
+\*---------------------------------------------------------------------------*/
+
+#include "OSspecific.H"
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+ Info<< "Report some basic OS-specific values" << nl;
+
+ Info<< nl
+ << "host : " << hostName() << nl
+ << "user : " << userName() << nl
+ << "home : " << home() << nl;
+
+ Info<< nl
+ << "cwd : " << cwd() << nl
+ << "cwd -P : " << cwd(false) << nl
+ << "cwd -L : " << cwd(true) << nl;
+
+ Info<< nl
+ << "libs : " << dlLoaded() << nl;
+
+ Info<< "\nEnd\n" << endl;
+
+ return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/POSIX/Make/files b/applications/test/POSIX/Make/files
deleted file mode 100644
index 491f2572f3..0000000000
--- a/applications/test/POSIX/Make/files
+++ /dev/null
@@ -1,2 +0,0 @@
-Test-POSIX.C
-EXE = $(FOAM_USER_APPBIN)/Test-POSIX
diff --git a/applications/test/clock/Make/files b/applications/test/clock/Make/files
new file mode 100644
index 0000000000..549cc0ca51
--- /dev/null
+++ b/applications/test/clock/Make/files
@@ -0,0 +1,3 @@
+Test-clock.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-clock
diff --git a/applications/test/clock/Make/options b/applications/test/clock/Make/options
new file mode 100644
index 0000000000..4e772fdf9d
--- /dev/null
+++ b/applications/test/clock/Make/options
@@ -0,0 +1,2 @@
+/* EXE_INC = -I$(LIB_SRC)/finiteVolume/lnInclude */
+/* EXE_LIBS = -lfiniteVolume */
diff --git a/applications/test/POSIX/Test-POSIX.C b/applications/test/clock/Test-clock.C
similarity index 68%
rename from applications/test/POSIX/Test-POSIX.C
rename to applications/test/clock/Test-clock.C
index e60c2e6af0..c9ad63ff29 100644
--- a/applications/test/POSIX/Test-POSIX.C
+++ b/applications/test/clock/Test-clock.C
@@ -2,10 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
--------------------------------------------------------------------------------
- | Copyright (C) 2011 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -24,6 +22,7 @@ License
along with OpenFOAM. If not, see .
Description
+ Test some clock-related routines
\*---------------------------------------------------------------------------*/
@@ -31,21 +30,59 @@ Description
#include "clock.H"
#include "clockTime.H"
#include "cpuTime.H"
+#include "clockValue.H"
using namespace Foam;
+
+template
+void testEpoch()
+{
+ Info<< nl << "Test epoch" << nl;
+
+ ClockValue now(true);
+
+ Info<< "epoch = " << now.str() << " # day-hh:mm::ss" << nl
+ << "epoch = " << now << nl;
+}
+
+
+template
+void testElapsed()
+{
+ Info<< nl << "Test elapsed" << nl;
+
+ ClockValue a;
+
+ Info<< "clockValue() " << a << nl;
+ a.update();
+ Info<< "updated " << a << nl;
+
+ Info<< "sleep 4..." << endl;
+ sleep(4);
+
+ a.update();
+ Info<< " = " << a.seconds() << nl;
+
+ Info<< "sleep 2..." << endl;
+ sleep(2);
+
+ Info<< "elapsed = " << a.elapsed() << nl
+ << "elapsed = " << a.elapsed().seconds() << nl
+ << "elapsed = " << a.elapsed().str() << nl;
+
+ ClockValue b(true);
+
+ Info<< "(" << b << " - " << a << ") = " << (b - a) << nl;
+ Info<< "(" << b << " + " << a << ") = " << (b + a) << nl;
+}
+
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
- Info<<"cwd() " << cwd() << nl;
- Info<<"cwd(-P) " << cwd(false) << nl;
- Info<<"cwd(-L) " << cwd(true) << nl;
-
- Info<<"rmDir" << nl;
- rmDir("hmm");
-
{
Foam::clock sysClock();
@@ -54,33 +91,10 @@ int main(int argc, char *argv[])
<< "clock: iso " << clock::dateTime() << nl;
}
- Info<< "since epoch = " << clockValue::now().str() << nl;
+ testEpoch();
- {
- clockValue a;
+ testElapsed();
- Info<< "clockValue() " << a << nl;
- a.update();
- Info<< "updated " << a << nl;
-
- Info<< "sleep 4..." << endl;
- sleep(4);
-
- a.update();
- Info<< " = " << a.seconds() << nl;
-
- Info<< "sleep 2..." << endl;
- sleep(2);
-
- Info<< "elapsed = " << a.elapsed() << nl;
- Info<< "elapsed = " << a.elapsed().seconds() << nl;
- Info<< "elapsed = " << a.elapsed().str() << nl;
-
- clockValue b = clockValue::now();
-
- Info<< "(" << b << " - " << a << ") = " << (b - a) << nl;
- Info<< "(" << b << " + " << a << ") = " << (b + a) << nl;
- }
{
clockTime clk;
diff --git a/src/OSspecific/POSIX/Make/files b/src/OSspecific/POSIX/Make/files
index 1f91738212..7ce5e03c60 100644
--- a/src/OSspecific/POSIX/Make/files
+++ b/src/OSspecific/POSIX/Make/files
@@ -1,5 +1,3 @@
-clockTime/clockTime.C
-clockValue/clockValue.C
cpuInfo/cpuInfo.C
cpuTime/cpuTime.C
memInfo/memInfo.C
diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index 0e7ae03ba7..5a35b70613 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -4,6 +4,8 @@ global/global.Cver
global/argList/argList.C
global/argList/argListHelp.C
global/clock/clock.C
+global/clockTime/clockTime.C
+global/clockValue/clockValue.C
global/profiling/profiling.C
global/profiling/profilingInformation.C
global/profiling/profilingSysInfo.C
diff --git a/src/OpenFOAM/global/clock/clock.C b/src/OpenFOAM/global/clock/clock.C
index b9f150ab5e..6a9b930b87 100644
--- a/src/OpenFOAM/global/clock/clock.C
+++ b/src/OpenFOAM/global/clock/clock.C
@@ -75,6 +75,7 @@ std::string Foam::clock::dateTime()
return os.str();
}
+
std::string Foam::clock::date()
{
time_t t = getTime();
diff --git a/src/OSspecific/POSIX/clockTime/clockTime.C b/src/OpenFOAM/global/clockTime/clockTime.C
similarity index 100%
rename from src/OSspecific/POSIX/clockTime/clockTime.C
rename to src/OpenFOAM/global/clockTime/clockTime.C
diff --git a/src/OSspecific/POSIX/clockTime/clockTime.H b/src/OpenFOAM/global/clockTime/clockTime.H
similarity index 99%
rename from src/OSspecific/POSIX/clockTime/clockTime.H
rename to src/OpenFOAM/global/clockTime/clockTime.H
index 646cc2d47a..1f279301d1 100644
--- a/src/OSspecific/POSIX/clockTime/clockTime.H
+++ b/src/OpenFOAM/global/clockTime/clockTime.H
@@ -62,6 +62,7 @@ class clockTime
//- Last time when elapsedTime or timeIncrement was called
mutable value_type last_;
+
public:
// Constructors
diff --git a/src/OSspecific/POSIX/clockValue/clockValue.C b/src/OpenFOAM/global/clockValue/clockValue.C
similarity index 65%
rename from src/OSspecific/POSIX/clockValue/clockValue.C
rename to src/OpenFOAM/global/clockValue/clockValue.C
index 7e1447d978..0fff3629a4 100644
--- a/src/OSspecific/POSIX/clockValue/clockValue.C
+++ b/src/OpenFOAM/global/clockValue/clockValue.C
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -25,40 +25,32 @@ License
#include "clockValue.H"
#include "IOstreams.H"
-#include
+
#include
#include
-// * * * * * * * * * * * * * * * * Local Data * * * * * * * * * * * * * * * //
-
-namespace
-{
-
- constexpr int factorMicro = (1000000); //!< From usec to sec
- constexpr int factorMicro2 = (500000); //!< Rounding usec to sec
- constexpr int factorHundred = (10000); //!< From usec to 0.01 sec
-
-} // End anonymous namespace
-
-
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::clockValue::clockValue()
:
- clockValue(false)
+ value_(value_type::zero())
+{}
+
+
+Foam::clockValue::clockValue(const value_type& value)
+:
+ value_(value)
{}
Foam::clockValue::clockValue(bool useNow)
+:
+ value_(value_type::zero())
{
if (useNow)
{
update();
}
- else
- {
- clear();
- }
}
@@ -66,14 +58,13 @@ Foam::clockValue::clockValue(bool useNow)
void Foam::clockValue::clear()
{
- value_.tv_sec = 0;
- value_.tv_usec = 0;
+ value_ = value_type::zero();
}
void Foam::clockValue::update()
{
- gettimeofday(&value_, 0);
+ value_ = std::chrono::high_resolution_clock::now().time_since_epoch();
}
@@ -85,13 +76,7 @@ Foam::clockValue Foam::clockValue::elapsed() const
long Foam::clockValue::seconds() const
{
- long sec = value_.tv_sec;
- if (sec > 0 && value_.tv_usec > factorMicro2)
- {
- ++sec;
- }
-
- return sec;
+ return std::chrono::duration_cast(value_).count();
}
@@ -99,23 +84,24 @@ std::string Foam::clockValue::str() const
{
std::ostringstream os;
- const unsigned long ss = value_.tv_sec;
+ // seconds
+ const unsigned long ss =
+ std::chrono::duration_cast(value_).count();
// days
const auto dd = (ss / 86400);
- if (dd) os << dd << '-';
-
// hours
const int hh = ((ss / 3600) % 24);
+ if (dd) os << dd << '-';
+
if (dd || hh)
{
os << std::setw(2) << std::setfill('0')
<< hh << ':';
}
-
// minutes
os << std::setw(2) << std::setfill('0')
<< ((ss / 60) % 60) << ':';
@@ -124,12 +110,16 @@ std::string Foam::clockValue::str() const
os << std::setw(2) << std::setfill('0')
<< (ss % 60);
- // 1/100th seconds. As none or 2 decimal places
- const int hundredths = (value_.tv_sec % factorHundred);
+ // milliseconds. As none or 3 decimal places
+ const long ms =
+ (
+ std::chrono::duration_cast(value_).count()
+ - (ss * 1000)
+ );
- if (hundredths)
+ if (ms > 0)
{
- os << '.' << std::setw(2) << std::setfill('0') << hundredths;
+ os << '.' << std::setw(3) << std::setfill('0') << ms;
}
return os.str();
@@ -140,38 +130,24 @@ std::string Foam::clockValue::str() const
Foam::clockValue::operator double () const
{
- return (value_.tv_sec + 1e-6*value_.tv_usec);
+ return
+ (
+ (double(value_.count()) * value_type::period::num)
+ / value_type::period::den
+ );
}
Foam::clockValue& Foam::clockValue::operator-=(const clockValue& rhs)
{
- const value_type& b = rhs.value_;
-
- value_.tv_sec -= b.tv_sec;
-
- if (value_.tv_usec < b.tv_usec)
- {
- --(value_.tv_sec);
- value_.tv_usec += factorMicro;
- }
-
- value_.tv_usec -= b.tv_usec;
-
+ value_ -= rhs.value_;
return *this;
}
Foam::clockValue& Foam::clockValue::operator+=(const clockValue& rhs)
{
- const value_type& b = rhs.value_;
-
- // Microseconds first
- value_.tv_usec += b.tv_usec;
-
- value_.tv_sec += b.tv_sec + (value_.tv_usec / factorMicro);
- value_.tv_usec %= factorMicro;
-
+ value_ += rhs.value_;
return *this;
}
@@ -180,19 +156,13 @@ Foam::clockValue& Foam::clockValue::operator+=(const clockValue& rhs)
Foam::clockValue Foam::operator-(const clockValue& a, const clockValue& b)
{
- clockValue result(a);
- result -= b;
-
- return result;
+ return clockValue(a.value() - b.value());
}
Foam::clockValue Foam::operator+(const clockValue& a, const clockValue& b)
{
- clockValue result(a);
- result += b;
-
- return result;
+ return clockValue(a.value() + b.value());
}
diff --git a/src/OSspecific/POSIX/clockValue/clockValue.H b/src/OpenFOAM/global/clockValue/clockValue.H
similarity index 83%
rename from src/OSspecific/POSIX/clockValue/clockValue.H
rename to src/OpenFOAM/global/clockValue/clockValue.H
index 0109af083b..206967fe02 100644
--- a/src/OSspecific/POSIX/clockValue/clockValue.H
+++ b/src/OpenFOAM/global/clockValue/clockValue.H
@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
- \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
+ \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@@ -25,8 +25,7 @@ Class
Foam::clockValue
Description
- Access to clock value (approx. 2 microsecond resolution) with
- some and basic operations.
+ Access to high-resolution clock value with some basic operations.
SourceFiles
clockValue.C
@@ -36,11 +35,8 @@ SourceFiles
#ifndef clockValue_H
#define clockValue_H
+#include
#include
-#include
-#ifdef darwin
- #include
-#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -56,19 +52,23 @@ class clockValue
// Private Data
//- Time structure used
- typedef struct timeval value_type;
+ typedef std::chrono::high_resolution_clock::duration value_type;
value_type value_;
+
public:
// Constructors
- //- Construct null, zero initialized
+ //- Construct zero initialized
clockValue();
+ //- Construct from duration with the same clock base
+ explicit clockValue(const value_type& value);
+
//- Construct zero initialized or with current time
- clockValue(bool useNow);
+ explicit clockValue(bool useNow);
// Factory Methods
@@ -82,6 +82,12 @@ public:
// Member Functions
+ //- Return the value
+ inline const value_type& value() const
+ {
+ return value_;
+ }
+
//- Reset to zero
void clear();
@@ -100,7 +106,7 @@ public:
// Operators
- //- Conversion operator to seconds
+ //- Conversion operator to seconds in floating point
operator double() const;
//- Subtract time value