aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet
diff options
context:
space:
mode:
Diffstat (limited to 'Carpet/Carpet')
-rw-r--r--Carpet/Carpet/src/CallFunction.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/Carpet/Carpet/src/CallFunction.cc b/Carpet/Carpet/src/CallFunction.cc
index 6bc22ae9a..9239935b8 100644
--- a/Carpet/Carpet/src/CallFunction.cc
+++ b/Carpet/Carpet/src/CallFunction.cc
@@ -1,6 +1,8 @@
#include <algorithm>
#include <cassert>
#include <cstdlib>
+#include <map>
+#include <string>
#include <cctk.h>
#include <cctk_Parameters.h>
@@ -317,9 +319,33 @@ namespace Carpet {
attribute->where,
attribute->thorn, attribute->routine);
CallBeforeRoutines (cctkGH, function, attribute, data);
+
+ typedef std::map <string, Timer *> timers_t;
+ static timers_t * timersp = NULL;
+ if (not timersp) timersp = new timers_t;
+ timers_t & timers = * timersp;
+
+ // Obtain timer, creating a new one if it does not yet exist
+ ostringstream timernamebuf;
+ timernamebuf << "CallFunction/"
+ << attribute->where << "::" << attribute->routine;
+ string const timername = timernamebuf.str();
+ timers_t::iterator ti = timers.find (timername);
+ if (ti == timers.end()) {
+ pair <string, Timer *> const
+ newtimer (timername, new Timer (timername.c_str()));
+ ti = timers.insert(newtimer).first;
+ // It is possible to find and insert with the same function
+ // call, but this makes the code significantly more complicated
+ }
+ Timer & timer = * ti->second;
+
user_timer.start();
+ timer.start();
int const res = CCTK_CallFunction (function, attribute, data);
+ timer.stop();
user_timer.stop();
+
CallAfterRoutines (cctkGH, function, attribute, data);
assert (res==0);
}