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-2017 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 profilingInformation;
52 class Ostream;
53 
54 Ostream& operator<<(Ostream& os, const profilingInformation& info);
55 
56 
57 /*---------------------------------------------------------------------------*\
58  Class profilingInformation Declaration
59 \*---------------------------------------------------------------------------*/
60 
62 {
63  // Private Data Members
64 
65  //- Unique id to identify it
66  const label id_;
67 
68  //- What this timer does
69  const string description_;
70 
71  //- Pointer to the parent object (or self for top-level)
72  profilingInformation* parent_;
73 
74  //- Number of times this was called
75  long calls_;
76 
77  //- Total time spent
78  scalar totalTime_;
79 
80  //- Time spent in children
81  scalar childTime_;
82 
83  //- Max memory usage on call.
84  // Only valid when the calling profiling has memInfo active.
85  mutable int maxMem_;
86 
87  //- Is this information active or passive (ie, on the stack)?
88  mutable bool active_;
89 
90 
91  // Private Member Functions
92 
93  //- No copy construct
95 
96  //- No copy assignment
97  void operator=(const profilingInformation&) = delete;
98 
99 
100 protected:
101 
102  // Friendship
103 
104  friend class profiling;
105 
106 
107  // Constructors
108 
109  //- Construct null - only the master-element
111 
112 
113  // Member Functions
114 
115  //- Mark as being active or passive)
116  void setActive(bool state) const;
117 
118  //- Write the profiling times, optionally with additional values
119  // Use dictionary format.
120  Ostream& write
121  (
122  Ostream& os,
123  const bool offset = false,
124  const scalar elapsedTime = 0,
125  const scalar childTime = 0
126  ) const;
127 
128 
129 public:
130 
131  // Constructors
132 
133  //- Construct from components
135  (
137  const string& descr,
138  const label id
139  );
140 
141 
142  //- Destructor
143  ~profilingInformation() = default;
144 
145 
146  // Member Functions
147 
148  // Access
149 
150  inline label id() const
151  {
152  return id_;
153  }
154 
155 
156  inline const string& description() const
157  {
158  return description_;
159  }
160 
161 
162  inline profilingInformation& parent() const
163  {
164  return *parent_;
165  }
166 
167 
168  inline label calls() const
169  {
170  return calls_;
171  }
172 
173 
174  inline scalar totalTime() const
175  {
176  return totalTime_;
177  }
178 
179 
180  inline scalar childTime() const
181  {
182  return childTime_;
183  }
184 
185 
186  inline int maxMem() const
187  {
188  return maxMem_;
189  }
190 
191 
192  inline bool active() const
193  {
194  return active_;
195  }
196 
197 
198  // Edit
199 
200  //- Update it with a new timing information
201  void update(const scalar elapsedTime);
202 
203 
204  // IOstream Operators
205 
206  friend Ostream& operator<<
207  (
208  Ostream& os,
209  const profilingInformation& info
210  );
211 
212 };
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
222 
223 // ************************************************************************* //
Foam::profilingInformation::profilingInformation
profilingInformation()
Construct null - 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:155
Foam::profilingInformation::childTime
scalar childTime() const
Definition: profilingInformation.H:179
Foam::profilingInformation::id
label id() const
Definition: profilingInformation.H:149
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:161
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:185
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:60
Foam::profilingInformation::calls
label calls() const
Definition: profilingInformation.H:167
scalar.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::profilingInformation::totalTime
scalar totalTime() const
Definition: profilingInformation.H:173
label.H
Foam::profiling
Code profiling.
Definition: profiling.H:79
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:191