50 #include "Teuchos_FancyOStream.hpp"
67 template <
class TagName>
70 timer_(
rcp(new Teuchos::Time(name, false))),
77 template <
class TagName>
82 GetOStream(
Errors) <<
"MutuallyExclusiveTime::~MutuallyExclusiveTime(): Error: destructor called on a paused timer." << std::endl;
89 template <
class TagName>
93 if (isRunning()) {
return; }
97 if (!timerStack_.empty()) {
98 GetOStream(
Debug) <<
"pausing parent timer " << timerStack_.top()->name_ << std::endl;
99 timerStack_.top()->pause();
100 GetOStream(
Debug) <<
"starting child timer " << this->name_ << std::endl;
101 myParent_[this->name_] = timerStack_.top()->name_;
103 GetOStream(
Debug) <<
"starting orphan timer " << this->name_ << std::endl;
108 timer_->start(reset);
109 timerStack_.push(
this);
112 template <
class TagName>
115 GetOStream(
Errors) <<
"MueLu::MutuallyExclusiveTime::stop(): timer is paused. Use resume()" << std::endl;
117 if (!isRunning()) {
return timer_->stop(); }
123 double r = timer_->stop();
125 if (!timerStack_.empty()) {
126 GetOStream(
Debug) <<
"resuming timer " << timerStack_.top()->name_ << std::endl;
127 timerStack_.top()->resume();
133 template <
class TagName>
144 template <
class TagName>
152 timer_->start(
false);
156 template <
class TagName>
158 if (timer_->isRunning()) {
162 return timer_->isRunning();
165 template <
class TagName>
171 template <
class TagName>
178 template <
class TagName>
181 template <
class TagName>
185 *fos <<
"Parent Child Map" << std::endl;
186 std::map<std::string, std::string >::const_iterator
iter;
188 *fos <<
"Key: " << iter->first <<
" Value: " << iter->second << std::endl;
192 template <
class TagName>
194 : timer_(timer), isPaused_(false)
197 template <
class TagName>
204 template <
class TagName>
void TopOfTheStack()
Check if 'this' is the head of the stack.
std::map< std::string, std::string > myParent_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
~MutuallyExclusiveTime()
Destructor.
Print additional debugging information.
static RCP< MutuallyExclusiveTime< TagName > > getNewTimer(const std::string &name)
Return a new MutuallyExclusiveTime that is registered with the Teuchos::TimeMonitor (for timer summar...
static void PrintParentChildPairs()
Print std::map of (child,parent) pairs for post-run analysis.
void start(bool reset=false)
Starts the timer. If a MutuallyExclusiveTime timer is running, it will be stopped.
static RCP< Time > getNewTimer(const std::string &name)
double stop()
Stops the timer. The previous MutuallyExclusiveTime that has been paused when this timer was started ...
void start(bool reset=false)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void incrementNumCalls()
Increment the number of times this timer has been called.
RCP< Teuchos::Time > timer_
Using an RCP allows to use Teuchos::TimeMonitor to keep track of the timer.
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void pause()
Pause running timer. Used internally by start().
void resume()
Resume paused timer. Used internally by stop(). Timer is not reset.
This class wraps a Teuchos::Time and maintains a mutually exclusive property between wrapped timers...
Exception throws to report errors in the internal logical of the program.
MutuallyExclusiveTime(const std::string &name, bool startFlag=false)
Constructor.