39 std::unique_ptr<Foam::profiling> Foam::profiling::singleton_(
nullptr);
55 children_.resize(pool_.size());
56 children_.last().clear();
68 const label parentId = parent->
id();
70 for (Information* child : children_[parentId])
72 if (descr == child->description())
78 Information* info =
new Information(parent, descr, pool_.size());
81 children_.resize(pool_.size());
82 children_.last().clear();
83 children_[parentId].append(info);
99 Information *info = stack_.remove();
103 info->setActive(
false);
113 return allowed && singleton_;
127 return singleton_->writeData(
os);
138 return singleton_->regIOobject::write();
147 const IOobject& ioObj,
151 if (allowed && !singleton_)
153 singleton_.reset(
new profiling(ioObj, owner));
160 const dictionary&
dict,
161 const IOobject& ioObj,
165 if (allowed && !singleton_)
174 if (singleton_ && &owner == &(singleton_->owner_))
176 singleton_.reset(
nullptr);
183 Information *info =
nullptr;
187 Information *parent = singleton_->stack_.last();
189 info = singleton_->create(parent, descr);
190 singleton_->beginTimer(info);
192 if (singleton_->memInfo_)
197 singleton_->memInfo_->update().size()
208 if (active() && info)
210 Information *top = singleton_->endTimer();
212 if (info->id() != top->id())
215 <<
"Profiling information to unstack has different id than" 216 <<
" the top of the profiling stack" <<
nl 217 <<
" info: " << info->id() <<
" (" << info->description()
219 <<
" top: " << top->id() <<
" (" << top->description()
229 Foam::profiling::profiling
233 const bool allEnabled
248 sysInfo_.reset(
new profilingSysInfo);
249 cpuInfo_.reset(
new cpuInfo);
250 memInfo_.reset(
new memInfo);
260 Foam::profiling::profiling
269 if (
dict.getOrDefault(
"sysInfo",
false))
273 if (
dict.getOrDefault(
"cpuInfo",
false))
275 cpuInfo_.reset(
new cpuInfo);
277 if (
dict.getOrDefault(
"memInfo",
false))
288 if (
this == singleton_.get())
290 singleton_.reset(
nullptr);
305 return stack_.size();
315 const label nstack = stack_.size();
319 for (label stacki=0; stacki < nstack; ++stacki)
321 elapsed[stacki] = (now - times_[stacki]);
328 for (label stacki=0; stacki < nstack; ++stacki)
330 if (stacki)
os <<
nl;
332 stack_[stacki]->write
342 for (
const Information& info : pool_)
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...
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual bool writeObject(IOstreamOption, const bool valid) const
Write as uncompressed ASCII.
static bool writeNow()
Write profiling information now.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
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()
Disallow profiling by forcing 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
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Access to high-resolution clock value with some basic operations. Used to calculate time durations...
errorManip< error > abort(error &err)
static profilingInformation * New(const string &descr)
Existing or new element on pool, add to stack.
static void stop(const Time &owner)
Stop profiling, cleanup pool if possible.
static bool active()
True if profiling is allowed and is active.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
static bool print(Ostream &os)
Print profiling information to specified output.
OBJstream os(runTime.globalPath()/outputName)
Memory usage information for the current process, and the system memory that is free.
T & last()
Access last element of the list, position [size()-1].
Information * endTimer()
Remove from stack of active information and update elapsed time.
const Time & owner() const
The owner of the profiling.
~profiling()
Destructor. Top-level clears the singleton.
bool good() const noexcept
True if next operation might succeed.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
InfoProxy< IOobject > info() const
Return info proxy, for printing information to a stream.
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Defines the attributes of an object for which implicit objectRegistry management is supported...
General system information useful for profiling.
Information * create()
Clear all profiling and restart with new profiling.