Commit 1d1d0b3c authored by mark's avatar mark
Browse files

ENH: support '-profiling' command-line option

- this option overrides any controlDict settings as a convenient means
  to selecting profiling without messing with the controlDict.

- provide Profiling::writeNow() to emit profiling for utilities that
  don't have any natural time increment mechanism to trigger it.
parent 6b9d6c17
......@@ -334,11 +334,17 @@ void Foam::Time::setControls()
}
void Foam::Time::setMonitoring()
void Foam::Time::setMonitoring(bool forceProfiling)
{
// initialize profiling on request
// skip if 'active' keyword is explicitly set to false
const dictionary* profilingDict = controlDict_.subDictPtr("profiling");
const dictionary* profilingDict =
(
forceProfiling
? &dictionary::null
: controlDict_.subDictPtr("profiling")
);
if
(
profilingDict
......@@ -526,7 +532,9 @@ Foam::Time::Time
readOpt() = IOobject::MUST_READ_IF_MODIFIED;
setControls();
setMonitoring();
// '-profiling' = force profiling, ignore controlDict entry
setMonitoring(args.optionFound("profiling"));
}
......
......@@ -182,7 +182,8 @@ protected:
void setControls();
//- Set file monitoring, profiling, etc
void setMonitoring();
// Optionally force profiling without inspecting the controlDict
void setMonitoring(const bool forceProfiling=false);
//- Read the control dictionary and set the write controls etc.
virtual void readDict();
......
......@@ -67,6 +67,27 @@ void Foam::Profiling::Information::raiseID(label maxVal)
}
bool Foam::Profiling::active()
{
return pool_;
}
bool Foam::Profiling::writeNow()
{
if (pool_)
{
Info<<"Profiling::writeNow() at time = "
<< pool_->owner().timeName() << endl;
return pool_->write();
}
else
{
return false;
}
}
void Foam::Profiling::initialize
(
const IOobject& ioObj,
......@@ -298,6 +319,17 @@ Foam::Profiling::Trigger::~Trigger()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::Time& Foam::Profiling::owner() const
{
return owner_;
}
Foam::label Foam::Profiling::size() const
{
return stack_.size();
}
Foam::Profiling::Information* Foam::Profiling::find(const string& name)
{
StorageContainer::iterator iter = hash_.find(name);
......
......@@ -191,19 +191,17 @@ public:
// Member Functions
//- The owner of the profiling
const Time& owner() const
{
return owner_;
}
//- True if profiling is active
static bool active();
//- Write profiling information now
static bool writeNow();
//- The size of the current stack
Foam::label size() const
{
return stack_.size();
}
//- The owner of the profiling
const Time& owner() const;
//- The size of the current stack
Foam::label size() const;
//- writeData member function required by regIOobject
virtual bool writeData(Ostream&) const;
......@@ -394,10 +392,14 @@ public:
// Constructors
//- Construct profiling with given name
//- Construct profiling with given description.
// Descriptions beginning with 'application::' are reserved for
// internal use.
Trigger(const char* name);
//- Construct profiling with given name
//- Construct profiling with given description.
// Descriptions beginning with 'application::' are reserved for
// internal use.
Trigger(const string& name);
......@@ -430,23 +432,23 @@ public:
// Macros
//- Define profiling with specified name and description correspond to the name
// \sa addProfiling
// \sa endProfiling
// \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
// \sa addProfiling0
// \sa endProfiling
#define addProfiling(name,descr) \
Foam::Profiling::Trigger profilingTriggerFor##name(descr)
//- Remove profiling with specified name
// \sa addProfiling
// \sa addProfiling0
// \sa addProfiling
// \sa addProfiling0
#define endProfiling(name) profilingTriggerFor##name.stop()
......
Foam::argList::addBoolOption
(
"profiling",
"activate application-level profiling"
);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment