Applied PIMPL to sig{Fpe,Int,Quit,Segv} and {cpu,clock}Time classes
[freefoam.git] / src / OSspecific / Unix / cpuTime / cpuTimeImpl.H
blob61dcb77e9354e9fd45c337b0d66d1f9fd69a387f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::cpuTimeImpl
28 Description
29     Starts timing CPU usage and return elapsed time from start.
31     This is the platform specific opaque implementation for class cpuTime.
33 SeeAlso
34     clockTime
36 SourceFiles
37     cpuTimeImpl.C
39 \*---------------------------------------------------------------------------*/
41 #ifndef cpuTimeImpl_H
42 #define cpuTimeImpl_H
44 #include <time.h>
45 #include <sys/times.h>
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 /*---------------------------------------------------------------------------*\
53                            Class cpuTimeImpl Declaration
54 \*---------------------------------------------------------------------------*/
56 class cpuTimeImpl
58     // Private data
60         static long Hz_;
62         struct tms startTime_;
63         mutable struct tms lastTime_;
64         mutable struct tms newTime_;
66         static void getTime(struct tms& t);
68         static double timeDifference
69         (
70             const struct tms& start,
71             const struct tms& end
72         );
75 public:
77     // Constructors
79         //- Construct from components
80         cpuTimeImpl();
83     // Member Functions
85         // Access
87             //- Returns CPU time from start of run
88             double elapsedCpuTime() const;
90             //- Returns CPU time from last call of cpuTimeIncrement()
91             double cpuTimeIncrement() const;
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 } // End namespace Foam
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
101 #endif
103 // ************************************************************************* //