profiling.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) 2009-2016 Bernhard Gschaider
9 Copyright (C) 2016-2020 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::profiling
29
30Description
31 Code profiling.
32
33 This is typically activated from within system/controlDict as follows
34 (defaults shown):
35 \code
36 profiling
37 {
38 active true;
39 cpuInfo false;
40 memInfo false;
41 sysInfo false;
42 }
43 \endcode
44 or simply using all defaults:
45 \code
46 profiling
47 {}
48 \endcode
49
50SourceFiles
51 profiling.C
52
53\*---------------------------------------------------------------------------*/
54
55#ifndef profiling_H
56#define profiling_H
57
58#include "profilingTrigger.H"
59#include "IOdictionary.H"
60#include "DynamicList.H"
61#include "PtrDynList.H"
62#include "Time.H"
63#include "clockTime.H"
64#include <memory>
65
66// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67
68namespace Foam
69{
70
71// Forward Declarations
72class Ostream;
73class cpuInfo;
74class memInfo;
75class profilingInformation;
76class profilingSysInfo;
77class profilingTrigger;
78
79/*---------------------------------------------------------------------------*\
80 Class profiling Declaration
81\*---------------------------------------------------------------------------*/
83class profiling
84:
85 public IOdictionary
86{
87public:
88
89 // Public Typedefs
93
94
95 // Static Data Members
96
97 //- Flag if profiling is allowed
98 static int allowed;
99
100private:
101
102 // Private Typedefs
103
105
106
107 // Private Static Data Members
108
109 //- Only one global object is possible
110 static std::unique_ptr<profiling> singleton_;
111
112
113 // Private Data Members
114
115 //- The owner of the profiling
116 const Time& owner_;
117
118 //- Storage of profiling information (memory management)
120
121 //- Parent/child relationships for lookup purposes
123
124 //- LIFO stack of profiling information
126
127 //- LIFO stack of clock values
129
130 //- General system information (optional)
131 std::unique_ptr<sysInfo> sysInfo_;
132
133 //- CPU-Information (optional)
134 std::unique_ptr<cpuInfo> cpuInfo_;
135
136 //- MEM-Information (optional)
137 std::unique_ptr<memInfo> memInfo_;
138
139
140 // Private Member Functions
141
142 //- No copy construct
143 profiling(const profiling&) = delete;
144
145 //- No copy assignment
146 void operator=(const profiling&) = delete;
147
148
149protected:
150
151 // Friendship
153 friend class profilingTrigger;
154 friend class Time;
155
156
157 // Constructors
158
159 //- Construct IO object, everything enabled
161 (
162 const IOobject& io,
163 const Time& owner,
164 const bool allEnabled = true
165 );
166
167 //- Construct IO object with finer control over behaviour
169 (
170 const dictionary& dict,
171 const IOobject& io,
172 const Time& owner
173 );
174
175
176 // Protected Member Functions
177
178 //- Clear all profiling and restart with new profiling
179 // \return pointer to stored information element
181
182 //- Get or create named profiling information element with the
183 //- specified parent.
184 // \return pointer to stored information element
186 (
188 const string& descr
189 );
190
191 //- Add to stack of active information and begin timer datum
193
194 //- Remove from stack of active information and update elapsed time
195 // \return pointer to profiling information element (for reference)
197
198
199 // Static control elements
200
201 //- Singleton to initialize profiling pool, everything enabled
202 static void initialize
203 (
204 const IOobject& ioObj,
205 const Time& owner
206 );
207
208 //- Singleton to initialize profiling pool with finer control
209 static void initialize
210 (
211 const dictionary& dict,
212 const IOobject& ioObj,
213 const Time& owner
214 );
215
216 //- Stop profiling, cleanup pool if possible
217 static void stop(const Time& owner);
218
219 //- Existing or new element on pool, add to stack.
220 // Returns nullptr if profiling has not been initialized
221 static profilingInformation* New(const string& descr);
222
223 //- Remove the information from the top of the stack
224 static void unstack(const profilingInformation* info);
225
226
227public:
228
229 //- Destructor. Top-level clears the singleton.
230 ~profiling();
231
232
233 // Static Member Functions
234
235 //- True if profiling is allowed and is active
236 static bool active();
237
238 //- Disallow profiling by forcing the InfoSwitch off.
239 static void disable();
240
241 //- Print profiling information to specified output
242 // Forwards to writeData member of top-level object
243 static bool print(Ostream& os);
244
245 //- Write profiling information now
246 static bool writeNow();
247
248
249 // Member Functions
250
251 //- The owner of the profiling
252 const Time& owner() const;
253
254 //- The size of the current stack
255 label size() const noexcept;
256
257 //- writeData member function required by regIOobject
258 virtual bool writeData(Ostream& os) const;
259
260 //- Write as uncompressed ASCII
261 virtual bool writeObject
262 (
263 IOstreamOption /*ignore*/,
264 const bool valid
265 ) const;
266};
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269
270} // End namespace Foam
271
272// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273
274#endif
275
276// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
InfoProxy< IOobject > info() const
Return info proxy, for printing information to a stream.
Definition: IOobject.H:690
The IOstreamOption is a simple container for options an IOstream can normally have.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A dynamically resizable PtrList with allocation management.
Definition: PtrDynList.H:64
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & parent() const noexcept
Return the parent dictionary.
Definition: dictionaryI.H:80
Code profiling information in terms of time spent, number of calls etc.
General system information useful for profiling.
Triggers for starting/stopping code profiling.
Code profiling.
Definition: profiling.H:85
static bool active()
True if profiling is allowed and is active.
Definition: profiling.C:111
Information * endTimer()
Remove from stack of active information and update elapsed time.
Definition: profiling.C:97
profilingTrigger Trigger
Definition: profiling.H:91
virtual bool writeObject(IOstreamOption, const bool valid) const
Write as uncompressed ASCII.
Definition: profiling.C:385
profilingInformation Information
Definition: profiling.H:90
static bool writeNow()
Write profiling information now.
Definition: profiling.C:134
static profilingInformation * New(const string &descr)
Existing or new element on pool, add to stack.
Definition: profiling.C:181
static bool print(Ostream &os)
Print profiling information to specified output.
Definition: profiling.C:123
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
Definition: profiling.C:309
const Time & owner() const
The owner of the profiling.
Definition: profiling.C:297
static void unstack(const profilingInformation *info)
Remove the information from the top of the stack.
Definition: profiling.C:206
static int allowed
Flag if profiling is allowed.
Definition: profiling.H:97
Information * create()
Clear all profiling and restart with new profiling.
Definition: profiling.C:44
static void disable()
Disallow profiling by forcing the InfoSwitch off.
Definition: profiling.C:117
label size() const noexcept
The size of the current stack.
Definition: profiling.C:303
void beginTimer(Information *info)
Add to stack of active information and begin timer datum.
Definition: profiling.C:89
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
Definition: profiling.C:172
~profiling()
Destructor. Top-level clears the singleton.
Definition: profiling.C:286
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
Definition: profiling.C:146
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
dictionary dict