profilingInformation.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 -------------------------------------------------------------------------------
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::profilingInformation
29 
30 Description
31  Code profiling information in terms of time spent, number of calls etc.
32 
33 SourceFiles
34  profilingInformation.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_profilingInformation_H
39 #define Foam_profilingInformation_H
40 
41 #include "labelFwd.H"
42 #include "scalarFwd.H"
43 #include "word.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class profiling;
52 
53 /*---------------------------------------------------------------------------*\
54  Class profilingInformation Declaration
55 \*---------------------------------------------------------------------------*/
56 
58 {
59  // Private Data
60 
61  //- Unique id to identify it
62  const label id_;
63 
64  //- What this timer does
65  const std::string description_;
66 
67  //- Pointer to the parent object (or self for top-level)
68  profilingInformation* parent_;
69 
70  //- Number of times this was called
71  long calls_;
72 
73  //- Total time spent
74  scalar totalTime_;
75 
76  //- Time spent in children
77  scalar childTime_;
78 
79  //- Max memory usage on call.
80  // Only valid when the calling profiling has memInfo active.
81  mutable int maxMem_;
82 
83  //- Is this information active or passive (ie, on the stack)?
84  mutable bool active_;
85 
86 
87 protected:
88 
89  // Friendship
90 
91  //- Allow creation of master-element, setActive etc.
92  friend class profiling;
93 
94 
95  // Constructors
96 
97  //- Default construct - only the master-element
99 
100  //- No copy construct
102 
103  //- No copy assignment
104  void operator=(const profilingInformation&) = delete;
105 
107  // Protected Member Functions
108 
109  //- Mark as being active or passive
110  void setActive(bool state) const;
111 
112 public:
113 
114  // Constructors
115 
116  //- Construct from components
118  (
120  const std::string& descr,
121  const label id
122  );
123 
124 
125  //- Destructor
126  ~profilingInformation() = default;
127 
128 
129  // Member Functions
130 
131  // Access
132 
133  label id() const noexcept { return id_; }
134 
135  const std::string& description() const noexcept { return description_; }
136 
137  profilingInformation& parent() const noexcept { return *parent_; }
138 
139  label calls() const noexcept { return calls_; }
140 
141  scalar totalTime() const noexcept { return totalTime_; }
142 
143  scalar childTime() const noexcept { return childTime_; }
144 
145  int maxMem() const noexcept { return maxMem_; }
146 
147  bool active() const noexcept { return active_; }
148 
149 
150  // Edit
151 
152  //- Update it with a new timing information
153  void update(const scalar elapsedTime);
154 
155 
156  // Write
157 
158  //- Write the profiling times, optionally with additional values
159  // Uses dictionary format.
160  Ostream& write
161  (
162  Ostream& os,
163  const bool offset = false,
164  const scalar elapsedTime = 0,
165  const scalar childTime = 0
166  ) const;
167 };
168 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 // Global Operators
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 
184 #endif
185 
186 // ************************************************************************* //
label calls() const noexcept
scalar childTime() const noexcept
Code profiling.
Definition: profiling.H:77
Typedefs for label/uLabel without requiring label.H.
Ostream & write(Ostream &os, const bool offset=false, const scalar elapsedTime=0, const scalar childTime=0) const
Write the profiling times, optionally with additional values.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
void update(const scalar elapsedTime)
Update it with a new timing information.
const std::string & description() const noexcept
void setActive(bool state) const
Mark as being active or passive.
Typedefs for float/double/scalar without requiring scalar.H.
bool active() const noexcept
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
profilingInformation()
Default construct - only the master-element.
~profilingInformation()=default
Destructor.
scalar totalTime() const noexcept
void operator=(const profilingInformation &)=delete
No copy assignment.
profilingInformation & parent() const noexcept
Code profiling information in terms of time spent, number of calls etc.
Namespace for OpenFOAM.