Loading...
Searching...
No Matches
cpuTimePosix.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2014 OpenFOAM Foundation
9 Copyright (C) 2018-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::cpuTimePosix
29
30Description
31 Starts timing CPU usage and return elapsed time from start.
32
33See also
34 clockTime
35
36SourceFiles
37 cpuTimePosix.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_cpuTimePosix_H
42#define Foam_cpuTimePosix_H
43
44#include <string>
45#include <ctime>
46#include <sys/times.h>
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
53/*---------------------------------------------------------------------------*\
54 Class cpuTimePosix Declaration
55\*---------------------------------------------------------------------------*/
56
57class cpuTimePosix
58{
59 //- Time structure used, with additional methods
60 struct value_type : tms
61 {
62 //- Construct with the current clock time
63 value_type();
64
65 //- Update with the current clock time
66 void update();
67 };
68
69
70 // Private Data
71
72 //- Start time, at the time of construction
73 value_type start_;
74
75 //- Last time when elapsedCpuTime or cpuTimeIncrement was called.
76 //- Also affected by resetCpuTime and resetCpuTimeIncrement.
77 mutable value_type last_;
78
79
80 // Private Member Functions
81
82 //- Difference between two times (a - b)
83 inline static double diff(const value_type& a, const value_type& b);
84
85
86public:
87
88 // Constructors
89
90 //- Construct with the current clock time
92
93
94 // Member Functions
95
96 //- Reset to use the current time for the start time
97 void resetCpuTime();
98
99 //- Reset to use the current time for the increment point
100 void resetCpuTimeIncrement() const;
101
102 //- Return CPU time [seconds] from the start
103 double elapsedCpuTime() const;
104
105 //- Return CPU time [seconds] since last call to cpuTimeIncrement(),
106 //- resetCpuTimeIncrement().
107 double cpuTimeIncrement() const;
108};
109
110
111// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112
113} // End namespace Foam
114
115// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116
117#endif
118
119// ************************************************************************* //
void resetCpuTime()
Reset to use the current time for the start time.
void resetCpuTimeIncrement() const
Reset to use the current time for the increment point.
cpuTimePosix()
Construct with the current clock time.
double cpuTimeIncrement() const
Return CPU time [seconds] since last call to cpuTimeIncrement(), resetCpuTimeIncrement().
double elapsedCpuTime() const
Return CPU time [seconds] from the start.
mesh update()
Namespace for OpenFOAM.
volScalarField & b