1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "profilingPool.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 Foam::profilingPool* Foam::profilingPool::thePool_(NULL);
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 Foam::profilingPool::profilingPool(
50 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
52 Foam::profilingPool::~profilingPool()
54 for(mapIterator it = map().begin(); it != map().end(); ++it)
59 map().erase(allInfo_.begin(), allInfo_.end());
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 void Foam::profilingPool::initProfiling(
72 thePool_ = new profilingPool(ob,owner);
73 profilingInfo *master=new profilingInfo();
74 thePool_->map().insert(make_pair(master->description(),master));
75 thePool_->stack().push(*master);
76 profilingPool::rememberTimer(*master,thePool_->globalTime_);
80 void Foam::profilingPool::stopProfiling(
84 if (thePool_ && (&owner)==&(thePool_->owner()))
91 Foam::profilingInfo &Foam::profilingPool::getInfo(const string& name)
95 FatalErrorIn("profilingPool::addInfo(const string& name)")
96 << "Singleton not initialized\n" << endl
100 profilingStack& stack = thePool_->stack();
101 mapType& map = thePool_->map();
103 profilingInfo* found = NULL;
107 mapIterator it = map.lower_bound(name);
108 it != map.upper_bound(name);
112 if (it->second->parent().id()==stack.top().id())
121 found = new profilingInfo(stack.top(),name);
123 map.insert(make_pair(name,found));
131 void Foam::profilingPool::rememberTimer
133 const profilingInfo& info,
141 "profilingPool::rememberTimer(const profilingInfo Foam&info, "
143 ) << "Singleton not initialized\n" << endl
144 << abort(FatalError);
147 thePool_->stack().addTimer(info, timer);
151 void Foam::profilingPool::remove(const profilingInfo &info)
155 FatalErrorIn("profilingPool::addInfo(const string& name)")
156 << "Singleton not initialized\n" << endl
157 << abort(FatalError);
160 profilingStack& stack = thePool_->stack();
162 if(info.id() != stack.top().id())
164 FatalErrorIn("profilingPool::update(const string &name)")
165 << "The id " << info.id() << " of the updated info "
166 << info.description()
167 << " is no the same as the one on top of the stack: "
168 << stack.top().id() << " (" << stack.top().description()
170 << abort(FatalError);
177 bool Foam::profilingPool::writeData(Ostream& os) const
179 os << "profilingInfo" << nl << indent
180 << token::BEGIN_LIST << incrIndent << nl;
182 stack().writeStackContents(os);
184 for(mapConstIterator it = map().begin(); it != map().end(); ++it)
186 if(!it->second->onStack())
192 os << decrIndent << indent << token::END_LIST
193 << token::END_STATEMENT << endl;
198 // ************************************************************************* //