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-2020 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 profilingInformation_H
39 #define profilingInformation_H
40 
41 #include "label.H"
42 #include "scalar.H"
43 #include "string.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 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 
101  // Protected Member Functions
102 
103  //- Mark as being active or passive)
104  void setActive(bool state) const;
105 
106  //- No copy construct
108 
109  //- No copy assignment
110  void operator=(const profilingInformation&) = delete;
111 
112 public:
113 
114  // Constructors
115 
116  //- Construct from components
118  (
120  const 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
134  {
135  return id_;
136  }
137 
138  const string& description() const
139  {
140  return description_;
141  }
142 
144  {
145  return *parent_;
146  }
147 
148  label calls() const
149  {
150  return calls_;
151  }
152 
153  scalar totalTime() const
154  {
155  return totalTime_;
156  }
157 
158  scalar childTime() const
159  {
160  return childTime_;
161  }
162 
163  int maxMem() const
164  {
165  return maxMem_;
166  }
167 
168  bool active() const
169  {
170  return active_;
171  }
172 
173 
174  // Edit
175 
176  //- Update it with a new timing information
177  void update(const scalar elapsedTime);
178 
179 
180  // Write
181 
182  //- Write the profiling times, optionally with additional values
183  // Uses dictionary format.
184  Ostream& write
185  (
186  Ostream& os,
187  const bool offset = false,
188  const scalar elapsedTime = 0,
189  const scalar childTime = 0
190  ) const;
191 };
192 
193 
194 // Global Operators
195 
196 Ostream& operator<<(Ostream& os, const profilingInformation& info);
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace Foam
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 
206 #endif
207 
208 // ************************************************************************* //
Foam::profilingInformation::profilingInformation
profilingInformation()
Default construct - only the master-element.
Definition: profilingInformation.C:35
Foam::profilingInformation::update
void update(const scalar elapsedTime)
Update it with a new timing information.
Definition: profilingInformation.C:68
Foam::profilingInformation::description
const string & description() const
Definition: profilingInformation.H:137
Foam::profilingInformation::childTime
scalar childTime() const
Definition: profilingInformation.H:157
Foam::profilingInformation::id
label id() const
Definition: profilingInformation.H:132
Foam::profilingInformation::setActive
void setActive(bool state) const
Mark as being active or passive)
Definition: profilingInformation.C:82
string.H
Foam::profilingInformation::parent
profilingInformation & parent() const
Definition: profilingInformation.H:142
Foam::profilingInformation::write
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.
Definition: profilingInformation.C:89
Foam::profilingInformation::maxMem
int maxMem() const
Definition: profilingInformation.H:162
Foam::profilingInformation::~profilingInformation
~profilingInformation()=default
Destructor.
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::profilingInformation
Code profiling information in terms of time spent, number of calls etc.
Definition: profilingInformation.H:56
Foam::profilingInformation::operator=
void operator=(const profilingInformation &)=delete
No copy assignment.
Foam::profilingInformation::calls
label calls() const
Definition: profilingInformation.H:147
scalar.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::profilingInformation::totalTime
scalar totalTime() const
Definition: profilingInformation.H:152
label.H
Foam::profiling
Code profiling.
Definition: profiling.H:82
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::profilingInformation::active
bool active() const
Definition: profilingInformation.H:167