Commit c5d2831f authored by mark's avatar mark
Browse files

ENH: add possibility to enable/disable profiling globally (issue #441)

- use InfoSwitch to disable, or via static method.

- respect the state of the argList banner when deciding to emit
  initialization information. Can otherwise end up with unwanted
  output rubbish on things like foamDictionary and foamListTimes.
parent 99e90b4e
......@@ -112,6 +112,7 @@ Usage
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "profiling.H"
#include "Time.H"
#include "IFstream.H"
#include "OFstream.H"
......@@ -289,6 +290,7 @@ int main(int argc, char *argv[])
"disableFunctionEntries",
"Disable expansion of dictionary directives - #include, #codeStream etc"
);
profiling::disable(); // Disable profiling (and its output)
argList args(argc, argv);
......
......@@ -45,6 +45,7 @@ Usage
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "profiling.H"
#include "timeSelector.H"
#include "Time.H"
......@@ -70,6 +71,8 @@ int main(int argc, char *argv[])
"rm",
"remove selected time directories"
);
profiling::disable(); // Disable profiling (and its output)
#include "setRootCase.H"
label nProcs = 0;
......
......@@ -62,6 +62,7 @@ Note
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "profiling.H"
#include "Time.H"
#include "UnsortedMeshedSurfaces.H"
......@@ -98,6 +99,7 @@ int main(int argc, char *argv[])
"xml",
"write output in XML format"
);
profiling::disable(); // Disable profiling (and its output)
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
......
......@@ -40,6 +40,9 @@ InfoSwitches
writeDictionaries 0;
writeOptionalEntries 0;
// Allow profiling
allowProfiling 1;
// Allow case-supplied C++ code (#codeStream, codedFixedValue)
allowSystemOperations 1;
}
......
......@@ -42,7 +42,7 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
bool Foam::argList::bannerEnabled = true;
bool Foam::argList::bannerEnabled_ = true;
Foam::SLList<Foam::string> Foam::argList::validArgs;
Foam::HashTable<Foam::string> Foam::argList::validOptions;
Foam::HashTable<Foam::string> Foam::argList::validParOptions;
......@@ -154,7 +154,13 @@ void Foam::argList::removeOption(const word& opt)
void Foam::argList::noBanner()
{
bannerEnabled = false;
bannerEnabled_ = false;
}
bool Foam::argList::bannerEnabled()
{
return bannerEnabled_;
}
......@@ -596,7 +602,7 @@ void Foam::argList::parse
const string timeString = clock::clockTime();
// Print the banner once only for parallel runs
if (Pstream::master() && bannerEnabled)
if (Pstream::master() && bannerEnabled_)
{
IOobject::writeBanner(Info, true)
<< "Build : " << Foam::FOAMbuild << nl
......@@ -891,7 +897,7 @@ void Foam::argList::parse
}
if (Pstream::master() && bannerEnabled)
if (Pstream::master() && bannerEnabled_)
{
Info<< "Case : " << (rootPath_/globalCase_).c_str() << nl
<< "nProcs : " << nProcs << endl;
......@@ -930,12 +936,12 @@ void Foam::argList::parse
// Switch on signal trapping. We have to wait until after Pstream::init
// since this sets up its own ones.
sigFpe::set(bannerEnabled);
sigInt::set(bannerEnabled);
sigQuit::set(bannerEnabled);
sigSegv::set(bannerEnabled);
sigFpe::set(bannerEnabled_);
sigInt::set(bannerEnabled_);
sigQuit::set(bannerEnabled_);
sigSegv::set(bannerEnabled_);
if (bannerEnabled)
if (Pstream::master() && bannerEnabled_)
{
Info<< "fileModificationChecking : "
<< "Monitoring run-time modified files using "
......@@ -958,23 +964,19 @@ void Foam::argList::parse
Info<< " (fileModificationSkew "
<< regIOobject::fileModificationSkew << ")";
}
Info<< endl;
Info<< nl;
Info<< "allowSystemOperations : ";
if (dynamicCode::allowSystemOperations)
{
Info<< "Allowing user-supplied system call operations" << endl;
Info<< "Allowing";
}
else
{
Info<< "Disallowing user-supplied system call operations"
<< endl;
Info<< "Disallowing";
}
}
if (Pstream::master() && bannerEnabled)
{
Info<< endl;
Info<< " user-supplied system call operations" << nl
<< endl;
IOobject::writeDivider(Info);
}
}
......
......@@ -98,7 +98,9 @@ namespace Foam
class argList
{
// Private data
static bool bannerEnabled;
//- Track enabled/disabled banner state
static bool bannerEnabled_;
//- Switch on/off parallel mode. Has to be first to be constructed
// so destructor is done last.
......@@ -353,6 +355,9 @@ public:
//- Disable emitting the banner information
static void noBanner();
//- Banner status (enabled/disabled)
static bool bannerEnabled();
//- Remove the 'noFunctionObjects' option,
// optionally adding a 'withFunctionObjects' option instead
static void noFunctionObjects(bool addWithOption = false);
......
......@@ -23,6 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "profiling.H"
#include "profilingInformation.H"
#include "profilingSysInfo.H"
......@@ -32,8 +33,12 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::profiling* Foam::profiling::pool_(0);
int Foam::profiling::allowed
(
Foam::debug::infoSwitch("allowProfiling", 1)
);
Foam::profiling* Foam::profiling::pool_(0);
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -78,13 +83,19 @@ Foam::profilingInformation* Foam::profiling::pop()
bool Foam::profiling::active()
{
return pool_;
return allowed && pool_;
}
void Foam::profiling::disable()
{
allowed = 0;
}
bool Foam::profiling::print(Ostream& os)
{
if (pool_)
if (active())
{
return pool_->writeData(os);
}
......@@ -97,7 +108,7 @@ bool Foam::profiling::print(Ostream& os)
bool Foam::profiling::writeNow()
{
if (pool_)
if (active())
{
return pool_->write();
}
......@@ -114,7 +125,7 @@ void Foam::profiling::initialize
const Time& owner
)
{
if (!pool_)
if (allowed && !pool_)
{
pool_ = new profiling(ioObj, owner);
......@@ -124,7 +135,10 @@ void Foam::profiling::initialize
);
pool_->push(info, pool_->clockTime_);
Info<< "profiling initialized" << nl;
if (argList::bannerEnabled())
{
Info<< "profiling initialized" << nl;
}
}
// silently ignore multiple initializations
......@@ -139,7 +153,7 @@ void Foam::profiling::initialize
const Time& owner
)
{
if (!pool_)
if (allowed && !pool_)
{
pool_ = new profiling(dict, ioObj, owner);
......@@ -149,7 +163,10 @@ void Foam::profiling::initialize
);
pool_->push(info, pool_->clockTime_);
Info<< "profiling initialized" << nl;
if (argList::bannerEnabled())
{
Info<< "profiling initialized" << nl;
}
}
// silently ignore multiple initializations
......@@ -175,7 +192,7 @@ Foam::profilingInformation* Foam::profiling::New
{
profilingInformation *info = 0;
if (pool_)
if (active())
{
profilingInformation *parent = pool_->stack_.top();
......@@ -203,7 +220,7 @@ Foam::profilingInformation* Foam::profiling::New
void Foam::profiling::unstack(const profilingInformation *info)
{
if (pool_ && info)
if (active() && info)
{
profilingInformation *top = pool_->pop();
......
......@@ -85,6 +85,11 @@ public:
typedef profilingInformation Information;
typedef profilingTrigger Trigger;
// Static data members
//- Flag if profiling is allowed
static int allowed;
private:
// Private classes, typedefs
......@@ -240,9 +245,12 @@ public:
// Static Member Functions
//- True if profiling is active
//- True if profiling is allowed and is active
static bool active();
//- Disallow profiling by forcing the InfoSwitch off.
static void disable();
//- Print profiling information to specified output
// Forwards to writeData member of top-level object
static bool print(Ostream& os);
......
Markdown is supported
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