mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add profiling code from Bernhard Gschaider
- activate via the case's <system/controlDict>:
profiling yes;
This commit is contained in:
@ -3,6 +3,7 @@ global/global.Cver
|
||||
/* global/constants/dimensionedConstants.C in global.Cver */
|
||||
global/argList/argList.C
|
||||
global/clock/clock.C
|
||||
global/profiling/Profiling.C
|
||||
|
||||
bools = primitives/bools
|
||||
$(bools)/bool/bool.C
|
||||
|
||||
@ -27,6 +27,7 @@ License
|
||||
#include "PstreamReduceOps.H"
|
||||
#include "argList.H"
|
||||
#include "HashSet.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -335,6 +336,24 @@ void Foam::Time::setControls()
|
||||
|
||||
void Foam::Time::setMonitoring()
|
||||
{
|
||||
// initialize profiling on request
|
||||
if (controlDict_.lookupOrDefault<Switch>("profiling", false))
|
||||
{
|
||||
Profiling::initialize
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"profiling",
|
||||
timeName(),
|
||||
"uniform",
|
||||
*this,
|
||||
IOobject::NO_READ,
|
||||
IOobject::AUTO_WRITE
|
||||
),
|
||||
*this
|
||||
);
|
||||
}
|
||||
|
||||
// Time objects not registered so do like objectRegistry::checkIn ourselves.
|
||||
if (runTimeModifiable_)
|
||||
{
|
||||
@ -651,6 +670,9 @@ Foam::Time::~Time()
|
||||
|
||||
// destroy function objects first
|
||||
functionObjects_.clear();
|
||||
|
||||
// cleanup profiling
|
||||
Profiling::stop(*this);
|
||||
}
|
||||
|
||||
|
||||
@ -892,9 +914,13 @@ bool Foam::Time::run() const
|
||||
{
|
||||
// Ensure functionObjects execute on last time step
|
||||
// (and hence write uptodate functionObjectProperties)
|
||||
addProfiling(foExec, "functionObjects.execute()");
|
||||
functionObjects_.execute();
|
||||
endProfiling(foExec);
|
||||
|
||||
addProfiling(foEnd, "functionObjects.end()");
|
||||
functionObjects_.end();
|
||||
endProfiling(foEnd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -906,10 +932,12 @@ bool Foam::Time::run() const
|
||||
|
||||
if (timeIndex_ == startTimeIndex_)
|
||||
{
|
||||
addProfiling(functionObjects, "functionObjects.start()");
|
||||
functionObjects_.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
addProfiling(functionObjects, "functionObjects.execute()");
|
||||
functionObjects_.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,7 @@ License
|
||||
#include "Pstream.H"
|
||||
#include "simpleObjectRegistry.H"
|
||||
#include "dimensionedConstants.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -518,6 +519,8 @@ bool Foam::Time::writeObject
|
||||
{
|
||||
if (outputTime())
|
||||
{
|
||||
addProfiling(writing, "objectRegistry::writeObject");
|
||||
|
||||
const word tmName(timeName());
|
||||
|
||||
IOdictionary timeDict
|
||||
|
||||
@ -26,6 +26,7 @@ License
|
||||
#include "functionObjectList.H"
|
||||
#include "Time.H"
|
||||
#include "mapPolyMesh.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
@ -220,6 +221,12 @@ bool Foam::functionObjectList::execute(const bool forceWrite)
|
||||
|
||||
forAll(*this, objectI)
|
||||
{
|
||||
addProfiling
|
||||
(
|
||||
fo,
|
||||
"functionObject::" + operator[](objectI).name() + "::execute"
|
||||
);
|
||||
|
||||
ok = operator[](objectI).execute(forceWrite) && ok;
|
||||
}
|
||||
}
|
||||
@ -257,6 +264,12 @@ bool Foam::functionObjectList::end()
|
||||
|
||||
forAll(*this, objectI)
|
||||
{
|
||||
addProfiling
|
||||
(
|
||||
fo,
|
||||
"functionObject::" + operator[](objectI).name() + "::end"
|
||||
);
|
||||
|
||||
ok = operator[](objectI).end() && ok;
|
||||
}
|
||||
}
|
||||
@ -339,6 +352,8 @@ bool Foam::functionObjectList::read()
|
||||
|
||||
label nFunc = 0;
|
||||
|
||||
addProfiling(fo,"functionObjects::read");
|
||||
|
||||
if (entryPtr->isDict())
|
||||
{
|
||||
// A dictionary of functionObjects
|
||||
@ -366,12 +381,24 @@ bool Foam::functionObjectList::read()
|
||||
// An existing functionObject, and dictionary changed
|
||||
if (newDigs[nFunc] != digests_[oldIndex])
|
||||
{
|
||||
addProfiling
|
||||
(
|
||||
fo2,
|
||||
"functionObject::" + objPtr->name() + "::read"
|
||||
);
|
||||
|
||||
ok = objPtr->read(dict) && ok;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// New functionObject
|
||||
addProfiling
|
||||
(
|
||||
fo2,
|
||||
"functionObject::" + key + "::start"
|
||||
);
|
||||
|
||||
objPtr = functionObject::New(key, time_, dict).ptr();
|
||||
ok = objPtr->start() && ok;
|
||||
}
|
||||
|
||||
373
src/OpenFOAM/global/profiling/Profiling.C
Normal file
373
src/OpenFOAM/global/profiling/Profiling.C
Normal file
@ -0,0 +1,373 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2016 Bernhard Gschaider
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Profiling.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Profiling* Foam::Profiling::pool_(0);
|
||||
|
||||
Foam::label Foam::Profiling::Information::nextId_(0);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::Profiling::Information::getNextId()
|
||||
{
|
||||
return nextId_++;
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::Information::raiseID(label maxVal)
|
||||
{
|
||||
if (nextId_ < maxVal)
|
||||
{
|
||||
nextId_ = maxVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::initialize
|
||||
(
|
||||
const IOobject& ioObj,
|
||||
const Time& owner
|
||||
)
|
||||
{
|
||||
if (pool_)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Already initialized" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
pool_ = new Profiling(ioObj, owner);
|
||||
|
||||
Information *info = pool_->store
|
||||
(
|
||||
new Information()
|
||||
);
|
||||
|
||||
pool_->push(info, pool_->clockTime_);
|
||||
info->push(); // mark as on stack
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::stop(const Time& owner)
|
||||
{
|
||||
if (pool_ && &owner == &(pool_->owner_))
|
||||
{
|
||||
delete pool_;
|
||||
pool_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Profiling::Information* Foam::Profiling::New
|
||||
(
|
||||
const string& name,
|
||||
clockTime& timer
|
||||
)
|
||||
{
|
||||
Information *info = 0;
|
||||
|
||||
if (pool_)
|
||||
{
|
||||
info = pool_->find(name);
|
||||
if (!info)
|
||||
{
|
||||
info = pool_->store
|
||||
(
|
||||
new Information(pool_->stack_.top(), name)
|
||||
);
|
||||
}
|
||||
|
||||
pool_->push(info, timer);
|
||||
info->push(); // mark as on stack
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::unstack(const Information *info)
|
||||
{
|
||||
if (pool_ && info)
|
||||
{
|
||||
Information *top = pool_->stack_.pop();
|
||||
top->pop(); // mark as off stack
|
||||
|
||||
if (info->id() != top->id())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "The profiling information to unstack has different"
|
||||
<< " id than on the top of the profiling stack" << nl
|
||||
<< " info: " << info->id() << " (" << info->description()
|
||||
<< ")\n"
|
||||
<< " top: " << top->id() << " (" << top->description()
|
||||
<< ")\n" << endl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Profiling::Profiling
|
||||
(
|
||||
const IOobject& io,
|
||||
const Time& owner
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
owner_(owner),
|
||||
clockTime_(),
|
||||
hash_(),
|
||||
stack_(),
|
||||
timers_()
|
||||
{}
|
||||
|
||||
|
||||
Foam::Profiling::Information::Information()
|
||||
:
|
||||
id_(getNextId()),
|
||||
description_("application::main"),
|
||||
parent_(this),
|
||||
calls_(0),
|
||||
totalTime_(0),
|
||||
childTime_(0),
|
||||
onStack_(false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::Profiling::Information::Information
|
||||
(
|
||||
Information *parent,
|
||||
const string& descr
|
||||
)
|
||||
:
|
||||
id_(getNextId()),
|
||||
description_(descr),
|
||||
parent_(parent),
|
||||
calls_(0),
|
||||
totalTime_(0),
|
||||
childTime_(0),
|
||||
onStack_(false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::Profiling::Trigger::Trigger(const char* name)
|
||||
:
|
||||
clock_(),
|
||||
ptr_(Profiling::New(name, clock_))
|
||||
{}
|
||||
|
||||
|
||||
Foam::Profiling::Trigger::Trigger(const string& name)
|
||||
:
|
||||
clock_(),
|
||||
ptr_(Profiling::New(name, clock_))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Profiling::~Profiling()
|
||||
{
|
||||
if (pool_ == this)
|
||||
{
|
||||
pool_ = 0;
|
||||
Information::nextId_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Profiling::Information::~Information()
|
||||
{}
|
||||
|
||||
|
||||
Foam::Profiling::Trigger::~Trigger()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Profiling::Information* Foam::Profiling::find(const string& name)
|
||||
{
|
||||
StorageContainer::iterator iter = hash_.find(name);
|
||||
return (iter != hash_.end() ? iter() : 0);
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::Information::update(const scalar& elapsed)
|
||||
{
|
||||
++calls_;
|
||||
totalTime_ += elapsed;
|
||||
|
||||
if (id_ != parent().id())
|
||||
{
|
||||
parent().childTime_ += elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::Profiling::writeData(Ostream& os) const
|
||||
{
|
||||
os << indent << "profiling" << nl
|
||||
<< indent << token::BEGIN_LIST << incrIndent << nl;
|
||||
|
||||
// write on-stack items
|
||||
// newest is first on the stack, top-level is at the end
|
||||
// this is how the child times are summed
|
||||
{
|
||||
scalar oldElapsed = 0;
|
||||
forAllConstIter(StackContainer, stack_, iter)
|
||||
{
|
||||
const Information *info = *iter;
|
||||
scalar elapsed = timers_[info->id()]->elapsedTime();
|
||||
|
||||
info->write(os, true, elapsed, oldElapsed);
|
||||
oldElapsed = elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write off-stack items
|
||||
// using an additional Map to sort by Id
|
||||
{
|
||||
typedef Map<const Information*> LookupContainer;
|
||||
LookupContainer lookup;
|
||||
|
||||
forAllConstIter(StorageContainer, hash_, iter)
|
||||
{
|
||||
const Information *info = iter();
|
||||
|
||||
if (!info->onStack())
|
||||
{
|
||||
lookup.set(info->id(), info);
|
||||
}
|
||||
}
|
||||
|
||||
forAllConstIter(LookupContainer, lookup, iter)
|
||||
{
|
||||
iter()->write(os);
|
||||
}
|
||||
}
|
||||
|
||||
os << decrIndent
|
||||
<< indent << token::END_LIST << token::END_STATEMENT << nl;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Profiling::Information* Foam::Profiling::store(Information *info)
|
||||
{
|
||||
hash_.insert(info->description(), info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::push(Information *info, clockTime& timer)
|
||||
{
|
||||
stack_.push(info);
|
||||
timers_.insert(info->id(), &timer);
|
||||
}
|
||||
|
||||
|
||||
void Foam::Profiling::Trigger::stop()
|
||||
{
|
||||
if (ptr_)
|
||||
{
|
||||
ptr_->update(clock_.elapsedTime());
|
||||
Profiling::unstack(ptr_);
|
||||
// pointer is managed by pool storage -> thus no delete here
|
||||
}
|
||||
ptr_ = 0;
|
||||
}
|
||||
|
||||
|
||||
// file-scope function
|
||||
template<class T>
|
||||
inline static void writeEntry
|
||||
(
|
||||
Foam::Ostream& os, const Foam::word& key, const T& value
|
||||
)
|
||||
{
|
||||
os.writeKeyword(key) << value << Foam::token::END_STATEMENT << '\n';
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::Profiling::Information::write
|
||||
(
|
||||
Ostream& os,
|
||||
const bool offset,
|
||||
const scalar& elapsedTime,
|
||||
const scalar& childTimes
|
||||
) const
|
||||
{
|
||||
// write in dictionary format
|
||||
|
||||
// os.beginBlock("_" + Foam::name(id_)) << nl;
|
||||
os.beginBlock() << nl; // FUTURE: without nl
|
||||
|
||||
// FUTURE: os.writeEntry(key, value);
|
||||
|
||||
writeEntry(os, "id", id_);
|
||||
if (id_ != parent().id())
|
||||
{
|
||||
writeEntry(os, "parentId", parent().id());
|
||||
}
|
||||
writeEntry(os, "description", description());
|
||||
writeEntry(os, "calls", calls() + (offset ? 1 : 0));
|
||||
writeEntry(os, "totalTime", totalTime() + elapsedTime);
|
||||
writeEntry(os, "childTime", childTime() + childTimes);
|
||||
writeEntry(os, "onStack", Switch(onStack()));
|
||||
|
||||
os.endBlock() << nl; // FUTURE: without nl
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const Profiling::Information& info
|
||||
)
|
||||
{
|
||||
return info.write(os);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
424
src/OpenFOAM/global/profiling/Profiling.H
Normal file
424
src/OpenFOAM/global/profiling/Profiling.H
Normal file
@ -0,0 +1,424 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2009-2016 Bernhard Gschaider
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::Profiling
|
||||
|
||||
Description
|
||||
Code profiling.
|
||||
|
||||
SourceFiles
|
||||
Profiling.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Profiling_H
|
||||
#define Profiling_H
|
||||
|
||||
#include "HashPtrTable.H"
|
||||
#include "LIFOStack.H"
|
||||
#include "Map.H"
|
||||
#include "Time.H"
|
||||
#include "clockTime.H"
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Ostream;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Profiling Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Profiling
|
||||
:
|
||||
public regIOobject
|
||||
{
|
||||
public:
|
||||
|
||||
// Forward declarations of components
|
||||
|
||||
class Information;
|
||||
class Trigger;
|
||||
|
||||
private:
|
||||
|
||||
// Private Static Data Members
|
||||
|
||||
//- Only one global pool object is possible
|
||||
static Profiling *pool_;
|
||||
|
||||
|
||||
// Private Data Members
|
||||
|
||||
typedef HashPtrTable<Information, string> StorageContainer;
|
||||
typedef LIFOStack<Information*> StackContainer;
|
||||
|
||||
|
||||
//- The owner of the profiling
|
||||
const Time& owner_;
|
||||
|
||||
//- A global timer for the profiling
|
||||
clockTime clockTime_;
|
||||
|
||||
//- Storage of profiling information
|
||||
StorageContainer hash_;
|
||||
|
||||
//- Local stack of profiling information
|
||||
StackContainer stack_;
|
||||
|
||||
//- Note the timers (by Id) for the correct stack-output
|
||||
Map<clockTime*> timers_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
Profiling(const Profiling&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const Profiling&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Friendship
|
||||
|
||||
friend class Time;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct IO object
|
||||
Profiling(const IOobject&, const Time&);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~Profiling();
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Find profiling information element or null on failure
|
||||
Information* find(const string& name);
|
||||
|
||||
//- Add to hashed storage,
|
||||
// returns pointer to newly stored element for chaining
|
||||
Information* store(Information*);
|
||||
|
||||
//- Add to stack and set timer lookup (based on Id)
|
||||
void push(Information*, clockTime& timer);
|
||||
|
||||
|
||||
// Static control elements
|
||||
|
||||
//- Singleton to initialize profiling pool
|
||||
static void initialize(const IOobject&, const Time&);
|
||||
|
||||
//- Stop profiling, cleanup pool if possible
|
||||
static void stop(const Time&);
|
||||
|
||||
//- Existing or new element on pool, add to stack
|
||||
// Returns null if profiling has not been initialized
|
||||
static Information* New(const string& name, clockTime& timer);
|
||||
|
||||
//- Remove the information from the top of the stack
|
||||
static void unstack(const Information*);
|
||||
|
||||
public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The owner of the profiling
|
||||
const Time& owner() const
|
||||
{
|
||||
return owner_;
|
||||
}
|
||||
|
||||
|
||||
//- The size of the current stack
|
||||
Foam::label size() const
|
||||
{
|
||||
return stack_.size();
|
||||
}
|
||||
|
||||
|
||||
//- writeData member function required by regIOobject
|
||||
virtual bool writeData(Ostream&) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Profiling::Information Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Profiling::Information
|
||||
{
|
||||
// Private Static Data Members
|
||||
|
||||
//- Counter to generate the ids
|
||||
static label nextId_;
|
||||
|
||||
//- get a new ID and update the counter
|
||||
static label getNextId();
|
||||
|
||||
//- raise the next possible ID (to avoid ID-clashes during reading)
|
||||
static void raiseID(label maxVal);
|
||||
|
||||
|
||||
// Private Data Members
|
||||
|
||||
//- Unique id to identify it
|
||||
const label id_;
|
||||
|
||||
//- What this timer does
|
||||
const string description_;
|
||||
|
||||
//- Pointer to the parent object (or self for top-level)
|
||||
Information* parent_;
|
||||
|
||||
//- Nr of times this was called
|
||||
label calls_;
|
||||
|
||||
//- Total time spent
|
||||
scalar totalTime_;
|
||||
|
||||
//- Time spent in children
|
||||
scalar childTime_;
|
||||
|
||||
//- Is this information currently on the stack?
|
||||
mutable bool onStack_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
Information(const Information&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const Information&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Friendship
|
||||
|
||||
friend class Profiling;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null - only the master-element
|
||||
Information();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Mark as being on the stack
|
||||
void push() const
|
||||
{
|
||||
onStack_ = true;
|
||||
}
|
||||
|
||||
|
||||
//- Mark as being off the stack
|
||||
void pop() const
|
||||
{
|
||||
onStack_ = false;
|
||||
}
|
||||
|
||||
|
||||
//- Write the profiling times, optionally with additional values
|
||||
// Use dictionary format.
|
||||
Ostream& write
|
||||
(
|
||||
Ostream& os,
|
||||
const bool offset = false,
|
||||
const scalar& elapsedTime = 0,
|
||||
const scalar& childTime = 0
|
||||
) const;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
Information(Information* parent, const string& descr);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~Information();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
inline label id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
|
||||
inline const string& description() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
|
||||
inline Information& parent() const
|
||||
{
|
||||
return *parent_;
|
||||
}
|
||||
|
||||
|
||||
inline label calls() const
|
||||
{
|
||||
return calls_;
|
||||
}
|
||||
|
||||
|
||||
inline const scalar& totalTime() const
|
||||
{
|
||||
return totalTime_;
|
||||
}
|
||||
|
||||
|
||||
inline const scalar& childTime() const
|
||||
{
|
||||
return childTime_;
|
||||
}
|
||||
|
||||
|
||||
inline bool onStack() const
|
||||
{
|
||||
return onStack_;
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Update it with a new timing information
|
||||
void update(const scalar& elapsedTime);
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const Information&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Profiling::Trigger Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class Profiling::Trigger
|
||||
{
|
||||
// Private Data Members
|
||||
|
||||
//- The timer for the profiling information
|
||||
clockTime clock_;
|
||||
|
||||
//- The profiling information
|
||||
Information *ptr_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
Trigger(const Trigger&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const Trigger&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct profiling with given name
|
||||
Trigger(const char* name);
|
||||
|
||||
//- Construct profiling with given name
|
||||
Trigger(const string& name);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~Trigger();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- True if the triggered profiling is active
|
||||
inline bool running() const
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Stop triggered profiling
|
||||
void stop();
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Macros
|
||||
|
||||
//- Define profiling with specified name and description correspond to the name
|
||||
// \sa addProfiling
|
||||
// \sa endProfiling
|
||||
#define addProfiling0(name) \
|
||||
Foam::Profiling::Trigger profilingTriggerFor##name(#name)
|
||||
|
||||
|
||||
//- Define profiling with specified name and description string
|
||||
// This is required if the description contains space, colons etc.
|
||||
// \sa addProfiling0
|
||||
// \sa endProfiling
|
||||
#define addProfiling(name,descr) \
|
||||
Foam::Profiling::Trigger profilingTriggerFor##name(descr)
|
||||
|
||||
|
||||
//- Remove profiling with specified name
|
||||
// \sa addProfiling
|
||||
// \sa addProfiling0
|
||||
#define endProfiling(name) profilingTriggerFor##name.stop()
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -59,6 +59,7 @@ SourceFiles
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "solverPerformance.H"
|
||||
#include "InfoProxy.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -116,6 +117,7 @@ public:
|
||||
//- Convergence tolerance relative to the initial
|
||||
scalar relTol_;
|
||||
|
||||
Profiling::Trigger profiling_;
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -147,7 +147,8 @@ Foam::lduMatrix::solver::solver
|
||||
interfaceBouCoeffs_(interfaceBouCoeffs),
|
||||
interfaceIntCoeffs_(interfaceIntCoeffs),
|
||||
interfaces_(interfaces),
|
||||
controlDict_(solverControls)
|
||||
controlDict_(solverControls),
|
||||
profiling_("lduMatrix::solver." + fieldName)
|
||||
{
|
||||
readControls();
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,6 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "smoothSolver.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -87,6 +88,8 @@ Foam::solverPerformance Foam::smoothSolver::solve
|
||||
// If the nSweeps_ is negative do a fixed number of sweeps
|
||||
if (nSweeps_ < 0)
|
||||
{
|
||||
addProfiling(solve, "lduMatrix::smoother." + fieldName_);
|
||||
|
||||
autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
|
||||
(
|
||||
fieldName_,
|
||||
@ -144,6 +147,8 @@ Foam::solverPerformance Foam::smoothSolver::solve
|
||||
|| !solverPerf.checkConvergence(tolerance_, relTol_)
|
||||
)
|
||||
{
|
||||
addProfiling(solve, "lduMatrix::smoother." + fieldName_);
|
||||
|
||||
autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
|
||||
(
|
||||
fieldName_,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -23,6 +23,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
@ -57,6 +59,8 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
|
||||
|
||||
if (fieldI != -1)
|
||||
{
|
||||
addProfiling(fvopt, "fvOption()." + source.name());
|
||||
|
||||
source.setApplied(fieldI);
|
||||
|
||||
if (source.isActive())
|
||||
@ -113,6 +117,8 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
|
||||
|
||||
if (fieldI != -1)
|
||||
{
|
||||
addProfiling(fvopt, "fvOption()." + source.name());
|
||||
|
||||
source.setApplied(fieldI);
|
||||
|
||||
if (source.isActive())
|
||||
@ -172,6 +178,8 @@ Foam::tmp<Foam::fvMatrix<Type>> Foam::fv::optionList::operator()
|
||||
|
||||
if (fieldI != -1)
|
||||
{
|
||||
addProfiling(fvopt, "fvOption()." + source.name());
|
||||
|
||||
source.setApplied(fieldI);
|
||||
|
||||
if (source.isActive())
|
||||
@ -255,6 +263,8 @@ void Foam::fv::optionList::constrain(fvMatrix<Type>& eqn)
|
||||
|
||||
if (fieldI != -1)
|
||||
{
|
||||
addProfiling(fvopt, "fvOption::constrain." + eqn.psi().name());
|
||||
|
||||
source.setApplied(fieldI);
|
||||
|
||||
if (source.isActive())
|
||||
@ -288,6 +298,8 @@ void Foam::fv::optionList::correct
|
||||
|
||||
if (fieldI != -1)
|
||||
{
|
||||
addProfiling(fvopt, "fvOption::correct." + source.name());
|
||||
|
||||
source.setApplied(fieldI);
|
||||
|
||||
if (source.isActive())
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,6 +25,7 @@ License
|
||||
|
||||
#include "LduMatrix.H"
|
||||
#include "diagTensorField.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -58,6 +59,8 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solve
|
||||
const dictionary& solverControls
|
||||
)
|
||||
{
|
||||
addProfiling(solve, "fvMatrix::solve." + psi_.name());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info.masterStream(this->mesh().comm())
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,6 +25,7 @@ License
|
||||
|
||||
#include "fvScalarMatrix.H"
|
||||
#include "extrapolatedCalculatedFvPatchFields.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
@ -59,6 +60,8 @@ Foam::fvMatrix<Foam::scalar>::solver
|
||||
const dictionary& solverControls
|
||||
)
|
||||
{
|
||||
addProfiling(solve, "fvMatrix::solve." + psi_.name());
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info.masterStream(this->mesh().comm())
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,6 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "IMULES.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -36,6 +37,8 @@ void Foam::MULES::implicitSolve
|
||||
const scalar psiMin
|
||||
)
|
||||
{
|
||||
addProfiling(solve, "MULES::implicitSolve");
|
||||
|
||||
implicitSolve
|
||||
(
|
||||
geometricOneField(),
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -29,6 +29,7 @@ License
|
||||
#include "fvmDdt.H"
|
||||
#include "fvmSup.H"
|
||||
#include "fvcDiv.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -65,6 +66,8 @@ void Foam::MULES::implicitSolve
|
||||
const scalar psiMin
|
||||
)
|
||||
{
|
||||
addProfiling(solve, "MULES::implicitSolve");
|
||||
|
||||
const fvMesh& mesh = psi.mesh();
|
||||
|
||||
const dictionary& MULEScontrols = mesh.solverDict(psi.name());
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,6 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "MULES.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -36,6 +37,8 @@ void Foam::MULES::explicitSolve
|
||||
const scalar psiMin
|
||||
)
|
||||
{
|
||||
addProfiling(solve, "MULES::explicitSolve");
|
||||
|
||||
explicitSolve
|
||||
(
|
||||
geometricOneField(),
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,6 +33,7 @@ License
|
||||
#include "PatchInteractionModel.H"
|
||||
#include "StochasticCollisionModel.H"
|
||||
#include "SurfaceFilmModel.H"
|
||||
#include "Profiling.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
@ -90,6 +91,8 @@ template<class CloudType>
|
||||
template<class TrackData>
|
||||
void Foam::KinematicCloud<CloudType>::solve(TrackData& td)
|
||||
{
|
||||
addProfiling(prof, "cloud::solve");
|
||||
|
||||
if (solution_.steadyState())
|
||||
{
|
||||
td.cloud().storeState();
|
||||
|
||||
Reference in New Issue
Block a user