aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2012-06-07 13:42:03 -0500
committerErik Schnetter <schnetter@gmail.com>2012-06-07 13:42:03 -0500
commitd41243c6a61aea192c6698dfda2c25163e012484 (patch)
tree3db29eccae19283a504637e3a0d9acd7a9f02768
parent2c626b4e52af42beedc5a0bc78576c6b42447600 (diff)
Carpet: Separate creating and initialising Timers
Add function Timer::instantiate() that associates a timer with a point in the timer hierarchy. Don't do this automatically when a timer is created. This allows declaring timers ahead of time.
-rw-r--r--Carpet/Carpet/src/TimerNode.cc28
-rw-r--r--Carpet/Carpet/src/TimerNode.hh1
-rw-r--r--Carpet/Carpet/src/Timers.cc11
-rw-r--r--Carpet/Carpet/src/Timers.hh1
4 files changed, 34 insertions, 7 deletions
diff --git a/Carpet/Carpet/src/TimerNode.cc b/Carpet/Carpet/src/TimerNode.cc
index 8942084a2..3c632b3d3 100644
--- a/Carpet/Carpet/src/TimerNode.cc
+++ b/Carpet/Carpet/src/TimerNode.cc
@@ -46,9 +46,8 @@ namespace Carpet {
TimerNode *TimerNode::root_timer = 0;
TimerNode::TimerNode(string name): d_name(name), d_parent(0),
- d_running(false)
+ d_running(false), timer(0)
{
- timer = 0;
}
TimerNode::~TimerNode()
@@ -70,13 +69,23 @@ namespace Carpet {
return getName();
}
+ void TimerNode::instantiate()
+ {
+ assert(!d_running);
+ d_parent = d_current;
+ d_current = this;
+ if (timer == 0)
+ timer = new CactusTimer(pathName());
+ d_current = d_parent;
+ }
+
void TimerNode::start()
{
- if(!d_running)
+ if (!d_running)
{
d_running = true;
d_parent = d_current;
- d_current=this;
+ d_current = this;
if (timer == 0)
timer = new CactusTimer(pathName());
assert(timer);
@@ -90,7 +99,7 @@ namespace Carpet {
void TimerNode::stop()
{
- if(d_running)
+ if (d_running)
{
// A timer can only be stopped if it is the current timer
if(this != d_current)
@@ -99,8 +108,8 @@ namespace Carpet {
timer->stop();
- d_running=false;
- d_current=d_parent;
+ d_running = false;
+ d_current = d_parent;
}
else
{
@@ -212,6 +221,11 @@ namespace Carpet {
}
out.precision (oldprecision);
out.setf (oldflags);
+
+ if (level == 0)
+ {
+ out << "--------" << hyphens << "--------" << hyphens << "-------" << endl;
+ }
}
void TimerNode::outputXML(const string &out_dir, int proc)
diff --git a/Carpet/Carpet/src/TimerNode.hh b/Carpet/Carpet/src/TimerNode.hh
index 642c97089..be932be07 100644
--- a/Carpet/Carpet/src/TimerNode.hh
+++ b/Carpet/Carpet/src/TimerNode.hh
@@ -68,6 +68,7 @@ public:
TimerNode(string name);
~TimerNode();
+ void instantiate();
void start();
void stop();
diff --git a/Carpet/Carpet/src/Timers.cc b/Carpet/Carpet/src/Timers.cc
index 4c8ef0352..313d1d034 100644
--- a/Carpet/Carpet/src/Timers.cc
+++ b/Carpet/Carpet/src/Timers.cc
@@ -38,6 +38,17 @@ namespace Carpet {
{
}
+ /// Insert the timer into the tree of timers as a child of the most
+ /// recently started timer that has not been stopped. Don't start
+ /// the timer. This routine ensures a timer is created even if it is
+ /// never started.
+ void Timer::instantiate ()
+ {
+ TimerNode *current_timer = TimerNode::getCurrentTimer();
+ assert(current_timer);
+ current_timer->getChildTimer(name())->instantiate();
+ }
+
/// Start the timer and insert it into the tree of timers as a child
/// of the most recently started timer that has not been stopped.
void Timer::start ()
diff --git a/Carpet/Carpet/src/Timers.hh b/Carpet/Carpet/src/Timers.hh
index 5a8278cf6..e5de64479 100644
--- a/Carpet/Carpet/src/Timers.hh
+++ b/Carpet/Carpet/src/Timers.hh
@@ -53,6 +53,7 @@ Timer objects can be allocated as "static" or not - it does not matter.
Timer (const string &name);
~Timer ();
+ void instantiate ();
void start ();
void stop ();
string name () const;