40 std::unique_ptr<Foam::profiling> Foam::profiling::singleton_(
nullptr);
55 pool_.push_back(
info);
56 children_.resize(pool_.size());
57 children_.back().clear();
66 const std::string& descr
69 const label parentId = parent->
id();
71 for (Information* child : children_[parentId])
73 if (descr == child->description())
79 Information* info =
new Information(parent, descr, pool_.size());
81 pool_.push_back(info);
82 children_.resize(pool_.size());
83 children_.back().clear();
84 children_[parentId].push_back(info);
92 stack_.push_back(info);
100 Information *info = stack_.back();
106 info->setActive(
false);
116 return allowed && singleton_;
128 if (allowed && singleton_)
130 return singleton_->writeData(
os);
139 if (allowed && singleton_)
141 return singleton_->regIOobject::write();
150 const IOobject& ioObj,
154 if (allowed && !singleton_)
156 singleton_.reset(
new profiling(ioObj, owner));
163 const dictionary&
dict,
164 const IOobject& ioObj,
168 if (allowed && !singleton_)
177 if (singleton_ && &owner == &(singleton_->owner_))
179 singleton_.reset(
nullptr);
186 Information *info =
nullptr;
190 Information *parent = singleton_->stack_.back();
192 info = singleton_->create(parent, descr);
193 singleton_->beginTimer(info);
195 if (singleton_->memInfo_)
197 singleton_->memInfo_->
update();
202 singleton_->memInfo_->size()
213 if (active() && info)
215 Information *top = singleton_->endTimer();
217 if (info->id() != top->id())
220 <<
"Profiling information to unstack has different id than" 221 <<
" the top of the profiling stack" <<
nl 222 <<
" info: " << info->id() <<
" (" << info->description()
224 <<
" top: " << top->id() <<
" (" << top->description()
238 const bool allEnabled
246 sysInfo_.reset(
new profilingSysInfo);
247 cpuInfo_.reset(
new cpuInfo);
248 memInfo_.reset(
new memInfo);
270 if (
dict.readIfPresent(
"sysInfo", on) && on)
274 if (
dict.readIfPresent(
"cpuInfo", on) && on)
276 cpuInfo_.reset(
new cpuInfo);
278 if (
dict.readIfPresent(
"memInfo", on) && on)
280 memInfo_.reset(
new memInfo);
290 if (
this == singleton_.get())
292 singleton_.reset(
nullptr);
307 return stack_.size();
317 const label nstack = stack_.size();
321 for (label stacki=0; stacki < nstack; ++stacki)
323 elapsed[stacki] = (now - times_[stacki]);
330 for (label stacki=0; stacki < nstack; ++stacki)
332 if (stacki)
os <<
nl;
334 stack_[stacki]->write
344 for (
const Information& info : pool_)
358 sysInfo_->writeEntry(
"sysInfo",
os);
364 cpuInfo_->writeEntry(
"cpuInfo",
os);
371 memInfo_->writeEntry(
"memInfo",
os);
381 const bool writeOnProc
label size() const noexcept
The size of the current stack.
clockValue elapsed() const
The time duration elapsed until now() since the start point.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
profilingInformation Information
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
void resize(const label len)
Alter addressable list size, allocating new space if required while recovering old content...
static bool active() noexcept
True if profiling is allowed and is active.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool writeNow()
Write profiling information now.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
static void unstack(const profilingInformation *info)
Remove the information from the top of the stack.
void beginTimer(Information *info)
Add to stack of active information and begin timer datum.
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
void update()
Update to the current now() time from the system.
static clockValue now()
The current clock value from the system.
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
virtual Ostream & endBlock()
Write end block group.
static int allowed
Flag if profiling is allowed.
static profilingInformation * New(const std::string &descr)
Existing or new element on pool, add to stack.
Access to high-resolution clock value with some basic operations. Used to calculate time durations...
errorManip< error > abort(error &err)
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
virtual bool writeObject(IOstreamOption, const bool writeOnProc) const
Write as uncompressed ASCII.
static bool print(Ostream &os)
Print profiling information to specified output.
OBJstream os(runTime.globalPath()/outputName)
Information * endTimer()
Remove from stack of active information and update elapsed time.
~profiling()
Destructor. Top-level clears the singleton.
bool good() const noexcept
True if next operation might succeed.
T & back()
Access last element of the list, position [size()-1].
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
const Time & owner() const noexcept
The owner of the profiling.
Defines the attributes of an object for which implicit objectRegistry management is supported...
profiling(const profiling &)=delete
No copy construct.
General system information useful for profiling.
Information * create()
Clear all profiling and restart with new profiling.