Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
27\*---------------------------------------------------------------------------*/
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(
51 const std::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
68void 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 * * * * * * * * * * * * * //
82void Foam::profilingInformation::setActive(bool state) const
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();
109 return os;
110}
111
112
113// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
114
115Foam::Ostream& Foam::operator<<(Ostream& os, const profilingInformation& info)
116{
117 return info.write(os);
118}
119
120
121// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
static const char * name(bool b) noexcept
A string representation of bool as "false" / "true".
Code profiling information in terms of time spent, number of calls etc.
scalar totalTime() const noexcept
void update(const scalar elapsedTime)
Update it with a new timing information.
const std::string & description() const noexcept
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.
profilingInformation & parent() const noexcept
scalar childTime() const noexcept
profilingInformation()
Default construct - only the master-element.
void setActive(bool state) const
Mark as being active or passive.
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127