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\*---------------------------------------------------------------------------*/
28
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 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 * * * * * * * * * * * * * //
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// ************************************************************************* //
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:62
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:105
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:87
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:251
virtual bool write()
Write the output fields.
virtual bool update()
Update the mesh for both mesh motion and topology change.
Code profiling information in terms of time spent, number of calls etc.
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()
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:68
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59