cpuTime.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::cpuTime
26 
27 Description
28  Starts timing CPU usage and return elapsed time from start.
29 
30 See also
31  clockTime
32 
33 SourceFiles
34  cpuTime.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef cpuTime_H
39 #define cpuTime_H
40 
41 #include <time.h>
42 #include <sys/times.h>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class cpuTime Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class cpuTime
54 {
55  // Private Data
56 
57  //- Time structure used
58  typedef struct tms timeType;
59 
60  //- Clock-ticks per second
61  static const long Hz_;
62 
63  //- The start time
64  timeType startTime_;
65  mutable timeType lastTime_;
66  mutable timeType newTime_;
67 
68  // Private Member Functions
69 
70  //- Retrieve the current time values from the system
71  static void getTime(timeType&);
72 
73  //- Difference between two times
74  static double timeDifference(const timeType& beg, const timeType& end);
75 
76 
77 public:
78 
79  // Constructors
80 
81  //- Construct with the current clock time
82  cpuTime();
83 
84 
85  // Member Functions
86 
87  //- Return CPU time (in seconds) from the start
88  double elapsedCpuTime() const;
89 
90  //- Return CPU time (in seconds) since last call to cpuTimeIncrement()
91  double cpuTimeIncrement() const;
92 };
93 
94 
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 
97 } // End namespace Foam
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 #endif
102 
103 // ************************************************************************* //
cpuTime()
Construct with the current clock time.
Definition: cpuTime.C:57
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Definition: cpuTime.C:74
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
Definition: cpuTime.C:67
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:52
Namespace for OpenFOAM.