40std::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);
94 info->setActive(
true);
100 Information *info = stack_.back();
106 info->setActive(
false);
128 if (allowed && singleton_)
130 return singleton_->writeData(
os);
139 if (allowed && singleton_)
141 return singleton_->regIOobject::write();
150 const IOobject& ioObj,
164 const IOobject& ioObj,
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]);
327 os.beginBlock(
"profiling");
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
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void resize(const label len)
Alter addressable list size, allocating new space if required while recovering old content.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
A simple container for options an IOstream can normally have.
@ ASCII
"ascii" (normal default)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & endBlock()
Write end block group.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
T & back()
Access last element of the list, position [size()-1].
Access to high-resolution clock value with some basic operations. Used to calculate time durations,...
static clockValue now()
The current clock value from the system.
void update()
Update to the current now() time from the system.
clockValue elapsed() const
The time duration elapsed until now() since the start point.
General CPU characteristics.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const dictionary & parent() const noexcept
Return the parent dictionary.
Memory usage information for the current process, and the system memory that is free.
General system information useful for profiling.
Information * endTimer()
Remove from stack of active information and update elapsed time.
static void disable() noexcept
Disallow profiling - turns the InfoSwitch off.
profilingInformation Information
static bool writeNow()
Write profiling information now.
static bool print(Ostream &os)
Print profiling information to specified output.
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
profiling(const profiling &)=delete
No copy construct.
static void unstack(const profilingInformation *info)
Remove the information from the top of the stack.
static int allowed
Flag if profiling is allowed.
static bool active() noexcept
True if profiling is allowed and is active.
Information * create()
Clear all profiling and restart with new profiling.
const Time & owner() const noexcept
The owner of the profiling.
label size() const noexcept
The size of the current stack.
static profilingInformation * New(const std::string &descr)
Existing or new element on pool, add to stack.
void beginTimer(Information *info)
Add to stack of active information and begin timer datum.
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
virtual bool writeObject(IOstreamOption, const bool writeOnProc) const
Write as uncompressed ASCII.
~profiling()
Destructor. Top-level clears the singleton.
static void initialize(const IOobject &ioObj, const Time &owner)
Singleton to initialize profiling pool, everything enabled.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
constexpr char nl
The newline '\n' character (0x0a).