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 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 cpuTimePosix_H
42 #define 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 elapsedTime or timeIncrement was called
76  mutable value_type last_;
77 
78 
79  // Private Member Functions
80 
81  //- Difference between two times (a - b)
82  inline static double diff(const value_type& a, const value_type& b);
83 
84 
85 public:
86 
87  // Constructors
88 
89  //- Construct with the current clock time
90  cpuTimePosix();
91 
92 
93  // Member Functions
94 
95  //- Reset to use the current time for the start time
96  void resetCpuTime();
97 
98  //- Return CPU time (in seconds) from the start
99  double elapsedCpuTime() const;
100 
101  //- Return CPU time (in seconds) since last call to cpuTimeIncrement()
102  double cpuTimeIncrement() const;
103 };
104 
105 
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 
108 } // End namespace Foam
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 #endif
113 
114 // ************************************************************************* //
update
mesh update()
Foam::cpuTimePosix::elapsedCpuTime
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
Definition: cpuTimePosix.C:80
Foam::cpuTimePosix
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTimePosix.H:56
Foam::cpuTimePosix::cpuTimeIncrement
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTimePosix.C:87
Foam::cpuTimePosix::cpuTimePosix
cpuTimePosix()
Construct with the current clock time.
Definition: cpuTimePosix.C:58
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cpuTimePosix::resetCpuTime
void resetCpuTime()
Reset to use the current time for the start time.
Definition: cpuTimePosix.C:73