profilingInformation.C
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 \*---------------------------------------------------------------------------*/
28 
29 #include "profilingInformation.H"
30 #include "IOstreams.H"
31 #include "Switch.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
37  id_(0),
38  description_("application::main"),
39  parent_(this),
40  calls_(0),
41  totalTime_(0),
42  childTime_(0),
43  maxMem_(0),
44  active_(false)
45 {}
46 
47 
49 (
50  profilingInformation *parent,
51  const string& descr,
52  const label id
53 )
54 :
55  id_(id),
56  description_(descr),
57  parent_(parent),
58  calls_(0),
59  totalTime_(0),
60  childTime_(0),
61  maxMem_(0),
62  active_(false)
63 {}
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
68 void Foam::profilingInformation::update(const scalar elapsed)
69 {
70  ++calls_;
71  totalTime_ += elapsed;
72 
73  if (id_ != parent_->id())
74  {
75  parent_->childTime_ += elapsed;
76  }
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
83 {
84  active_ = state;
85 }
86 
87 
89 (
90  Ostream& os,
91  const bool offset,
92  const scalar elapsedTime,
93  const scalar childTimes
94 ) const
95 {
96  os.beginBlock(word("trigger" + Foam::name(id_)));
97 
98  os.writeEntry("id", id_);
99  os.writeEntryIfDifferent("parentId", id_, parent().id());
100  os.writeEntry("description", description());
101  os.writeEntry("calls", calls() + (offset ? 1 : 0));
102  os.writeEntry("totalTime", totalTime() + elapsedTime);
103  os.writeEntry("childTime", childTime() + childTimes);
104  os.writeEntryIfDifferent<int>("maxMem", 0, maxMem_);
105  os.writeEntry("active", Switch::name(active()));
106 
107  os.endBlock();
108 
109  return os;
110 }
111 
112 
113 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
114 
116 {
117  return info.write(os);
118 }
119 
120 
121 // ************************************************************************* //
Foam::Ostream::writeEntryIfDifferent
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
Definition: Ostream.H:248
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::profilingInformation::profilingInformation
profilingInformation()
Default construct - only the master-element.
Definition: profilingInformation.C:35
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::profilingInformation::update
void update(const scalar elapsedTime)
Update it with a new timing information.
Definition: profilingInformation.C:68
Foam::profilingInformation::setActive
void setActive(bool state) const
Mark as being active or passive)
Definition: profilingInformation.C:82
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
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::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
profilingInformation.H
Foam::profilingInformation
Code profiling information in terms of time spent, number of calls etc.
Definition: profilingInformation.H:56
Switch.H
Foam::Switch::name
static const char * name(const bool b) noexcept
A string representation of bool as "false" / "true".
Definition: Switch.C:145
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:109
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56