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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::cpuTimePosix
29 
30 Description
31  Starts timing CPU usage and return elapsed time from start.
32 
33 See also
34  clockTime
35 
36 SourceFiles
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 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class cpuTimePosix Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class 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 
86 public:
87 
88  // Constructors
89 
90  //- Construct with the current clock time
91  cpuTimePosix();
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 resetCpuTimeIncrement() const
Reset to use the current time for the increment point.
Definition: cpuTimePosix.C:73
void resetCpuTime()
Reset to use the current time for the start time.
Definition: cpuTimePosix.C:66
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
mesh update()
double cpuTimeIncrement() const
Return CPU time [seconds] since last call to cpuTimeIncrement(), resetCpuTimeIncrement().
Definition: cpuTimePosix.C:86
double elapsedCpuTime() const
Return CPU time [seconds] from the start.
Definition: cpuTimePosix.C:79
cpuTimePosix()
Construct with the current clock time.
Definition: cpuTimePosix.C:51
Namespace for OpenFOAM.
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTimePosix.H:52