aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2010-03-14 15:18:02 -0500
committerBarry Wardell <barry.wardell@gmail.com>2011-12-14 16:45:32 +0000
commite344dae5a9b9b4f3cde4ff612f6076a4fe12dac7 (patch)
tree28c3e9a1b056826148e18ea964df53141ed2914f /Carpet/Carpet
parent9bd1509bd6a1a437bf62dc65c084068634571200 (diff)
Carpet: Add timer around scheduled functions
Create a timer for each scheduled function, measuring only the time spent in the function itself, and excluding AMR overhead and synchronisation.
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);
}