Loading...
Searching...
No Matches
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-2023 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 Foam_profiling_H
56#define Foam_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 cpuInfo;
73class memInfo;
78/*---------------------------------------------------------------------------*\
79 Class profiling Declaration
80\*---------------------------------------------------------------------------*/
81
82class profiling
83:
84 public IOdictionary
86public:
87
88 // Public Typedefs
89
92
93
94 // Static Data Members
95
96 //- Flag if profiling is allowed
97 static int allowed;
98
99private:
100
101 // Private Typedefs
102
103 typedef profilingSysInfo sysInfo;
104
105
106 // Private Static Data Members
107
108 //- Only one global object is possible
109 static std::unique_ptr<profiling> singleton_;
110
111
112 // Private Data Members
113
114 //- The owner of the profiling
115 const Time& owner_;
116
117 //- Storage of profiling information (memory management)
119
120 //- Parent/child relationships for lookup purposes
122
123 //- LIFO stack of profiling information
125
126 //- LIFO stack of clock values
128
129 //- General system information (optional)
130 std::unique_ptr<sysInfo> sysInfo_;
131
132 //- CPU-Information (optional)
133 std::unique_ptr<cpuInfo> cpuInfo_;
134
135 //- MEM-Information (optional)
136 std::unique_ptr<memInfo> memInfo_;
137
138
139protected:
140
141 // Friendship
142
143 friend class profilingTrigger;
144 friend class Time;
145
146
147 // Generated Methods
148
149 //- No copy construct
150 profiling(const profiling&) = delete;
151
152 //- No copy assignment
153 void operator=(const profiling&) = delete;
154
155
156 // Constructors
157
158 //- Construct IO object, everything enabled
160 (
161 const IOobject& io,
162 const Time& owner,
163 const bool allEnabled = true
164 );
165
166 //- Construct IO object with finer control over behaviour
168 (
169 const dictionary& dict,
170 const IOobject& io,
171 const Time& owner
172 );
173
174
175 // Protected Member Functions
176
177 //- Clear all profiling and restart with new profiling
178 // \return pointer to stored information element
180
181 //- Get or create named profiling information element with the
182 //- specified parent.
183 // \return pointer to stored information element
185 (
187 const std::string& descr
188 );
189
190 //- Add to stack of active information and begin timer datum
192
193 //- Remove from stack of active information and update elapsed time
194 // \return pointer to profiling information element (for reference)
196
197
198 // Static control elements
199
200 //- Singleton to initialize profiling pool, everything enabled
201 static void initialize
202 (
203 const IOobject& ioObj,
204 const Time& owner
205 );
206
207 //- Singleton to initialize profiling pool with finer control
208 static void initialize
209 (
210 const dictionary& dict,
211 const IOobject& ioObj,
212 const Time& owner
213 );
214
215 //- Stop profiling, cleanup pool if possible
216 static void stop(const Time& owner);
217
218 //- Existing or new element on pool, add to stack.
219 // Returns nullptr if profiling has not been initialized
220 static profilingInformation* New(const std::string& descr);
221
222 //- Remove the information from the top of the stack
223 static void unstack(const profilingInformation* info);
224
225
226public:
227
228 //- Destructor. Top-level clears the singleton.
229 ~profiling();
230
231
232 // Static Member Functions
233
234 //- True if profiling is allowed and is active
235 static bool active() noexcept;
236
237 //- Disallow profiling - turns the InfoSwitch off
238 static void disable() noexcept;
239
240 //- Print profiling information to specified output
241 // Forwards to writeData member of top-level object
242 static bool print(Ostream& os);
243
244 //- Write profiling information now
245 static bool writeNow();
246
247
248 // Member Functions
249
250 //- The owner of the profiling
251 const Time& owner() const noexcept;
252
253 //- The size of the current stack
254 label size() const noexcept;
255
256 //- writeData member function required by regIOobject
257 virtual bool writeData(Ostream& os) const;
258
259 //- Write as uncompressed ASCII
260 virtual bool writeObject
261 (
262 IOstreamOption /*ignore*/,
263 const bool writeOnProc
264 ) const;
265};
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269} // End namespace Foam
270
271// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272
273#endif
274
275// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
Definition IOobject.H:1041
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:59
A dynamically resizable PtrList with allocation management.
Definition PtrDynList.H:58
General CPU characteristics.
Definition cpuInfo.H:57
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary & parent() const noexcept
Return the parent dictionary.
Definition dictionaryI.H:77
Memory usage information for the current process, and the system memory that is free.
Definition memInfo.H:59
Code profiling information in terms of time spent, number of calls etc.
General system information useful for profiling.
Triggers for starting/stopping code profiling.
Information * endTimer()
Remove from stack of active information and update elapsed time.
Definition profiling.C:91
profilingTrigger Trigger
Definition profiling.H:86
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
Definition profiling.C:113
profilingInformation Information
Definition profiling.H:85
static bool writeNow()
Write profiling information now.
Definition profiling.C:130
static bool print(Ostream &os)
Print profiling information to specified output.
Definition profiling.C:119
friend class Time
Definition profiling.H:159
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
Definition profiling.C:304
profiling(const profiling &)=delete
No copy construct.
void operator=(const profiling &)=delete
No copy assignment.
static void unstack(const profilingInformation *info)
Remove the information from the top of the stack.
Definition profiling.C:204
static int allowed
Flag if profiling is allowed.
Definition profiling.H:94
static bool active() noexcept
True if profiling is allowed and is active.
Definition profiling.C:107
friend class profilingTrigger
Definition profiling.H:158
Information * create()
Clear all profiling and restart with new profiling.
Definition profiling.C:38
const Time & owner() const noexcept
The owner of the profiling.
Definition profiling.C:292
label size() const noexcept
The size of the current stack.
Definition profiling.C:298
static profilingInformation * New(const std::string &descr)
Existing or new element on pool, add to stack.
Definition profiling.C:177
void beginTimer(Information *info)
Add to stack of active information and begin timer datum.
Definition profiling.C:83
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
Definition profiling.C:168
virtual bool writeObject(IOstreamOption, const bool writeOnProc) const
Write as uncompressed ASCII.
Definition profiling.C:372
~profiling()
Destructor. Top-level clears the singleton.
Definition profiling.C:281
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
Definition profiling.C:142
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265
dictionary dict