summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/CactusTimers.h14
-rw-r--r--src/main/DefaultTimers.c491
-rw-r--r--src/main/InitialiseDataStructures.c3
-rw-r--r--src/main/make.code.defn1
-rw-r--r--src/util/CactusTimers.c16
5 files changed, 511 insertions, 14 deletions
diff --git a/src/include/CactusTimers.h b/src/include/CactusTimers.h
index a4885879..f5f75531 100644
--- a/src/include/CactusTimers.h
+++ b/src/include/CactusTimers.h
@@ -26,6 +26,18 @@ typedef struct
cInternalTimer last;
} cTimer;
+typedef struct
+{
+ void *(*create)(int);
+ void (*destroy)(int, void *);
+ void (*start)(int, void *);
+ void (*stop)(int, void *);
+ void (*reset)(int, void *);
+ double (*get)(int, void *);
+ void (*set)(int, void *, double);
+} t_TimerFuncs;
+
+
/* Function prototypes */
#ifdef __cplusplus
@@ -38,6 +50,8 @@ void CactusStartTimer(cTimer *timer);
void CactusStopTimer(cTimer *timer);
void CactusResetTimer(cTimer *timer);
+int CCTK_TimerRegister(const char *name, t_TimerFuncs *functions);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/main/DefaultTimers.c b/src/main/DefaultTimers.c
new file mode 100644
index 00000000..60c07e86
--- /dev/null
+++ b/src/main/DefaultTimers.c
@@ -0,0 +1,491 @@
+ /*@@
+ @file DefaultTimers.c
+ @date Wed Oct 20 16:17:42 1999
+ @author Tom Goodale
+ @desc
+ Default Cactus timers
+ @enddesc
+ @@*/
+
+static char *rcsid = "$Header$";
+
+#include <stdlib.h>
+
+#include "config.h"
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+#include "CactusTimers.h"
+
+/* Prototypes for registration functions */
+
+#ifdef HAVE_GETTIMEOFDAY
+void CCTKi_RegisterTimersGetTimeOfDay(void);
+#endif
+
+#ifdef HAVE_GETRUSAGE
+void CCTKi_RegisterTimersGetrUsage(void);
+#endif
+
+ /*@@
+ @routine CCTKi_RegisterDefaultTimerFunctions
+ @date Wed Oct 20 18:27:20 1999
+ @author Tom Goodale
+ @desc
+
+ Master flesh timer registration function./
+
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTKi_RegisterDefaultTimerFunctions(void)
+{
+
+#ifdef HAVE_GETTIMEOFDAY
+ CCTKi_RegisterTimersGetTimeOfDay();
+#endif
+
+#ifdef HAVE_GETRUSAGE
+ CCTKi_RegisterTimersGetrUsage();
+#endif
+
+}
+
+
+
+/*********************************************************************
+ **************** Actual timers *********************
+ *********************************************************************/
+
+
+
+/*********************************************************************
+ **************** gettimeofday based timer *********************
+ *********************************************************************/
+
+#ifdef HAVE_GETTIMEOFDAY
+
+#include <unistd.h>
+
+/* A structure to hold the relevent data */
+typedef struct
+{
+ double total;
+ double last;
+} t_GetTimeOfDayTimer;
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDayCreate
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Create the timer structure for use with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void *CCTKi_TimerGetTimeOfDayCreate(int timernum)
+{
+ t_GetTimeOfDayTimer *this;
+
+ this = malloc(sizeof(t_GetTimeOfDayTimer));
+
+ if(this)
+ {
+ this->total = 0;
+ this->last = 0;
+ }
+
+ return this;
+}
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDayDestroy
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Destroy the timer structure for use with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetTimeOfDayDestroy(int timernum, t_GetTimeOfDayTimer *data)
+{
+ if(data)
+ {
+ free(data);
+ }
+}
+
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDayStart
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Start the timer with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetTimeOfDayStart(int timernum, t_GetTimeOfDayTimer *data)
+{
+ struct timeval tp;
+ struct timezone tzp;
+
+ gettimeofday(&tp, &tzp);
+
+ data->last = tp.tv_sec + (double)tp.tv_usec/1000000.0;
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDayStart
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Stop the timer with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetTimeOfDayStop(int timernum, t_GetTimeOfDayTimer *data)
+{
+ struct timeval tp;
+ struct timezone tzp;
+
+ gettimeofday(&tp, &tzp);
+
+ data->total += (tp.tv_sec + (double)tp.tv_usec/1000000.0 - data->last);
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDayReset
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Reset the timer with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetTimeOfDayReset(int timernum, t_GetTimeOfDayTimer *data)
+{
+
+ data->last = 0;
+ data->total = 0;
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDayGet
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Get the time recorded with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+double CCTKi_TimerGetTimeOfDayGet(int timernum, t_GetTimeOfDayTimer *data)
+{
+
+ return data->total;
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetTimeOfDaySet
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Set the time for a gettimeofday function based timer.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetTimeOfDaySet(int timernum, t_GetTimeOfDayTimer *data, double val)
+{
+ data->total = val;
+}
+
+ /*@@
+ @routine CCTKi_RegisterTimersGetTimeOfDay
+ @date Wed Oct 20 18:32:17 1999
+ @author Tom Goodale
+ @desc
+ Register all the timer functions associated with the gettimeofday function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_RegisterTimersGetTimeOfDay(void)
+{
+ t_TimerFuncs functions;
+
+ functions.create = CCTKi_TimerGetTimeOfDayCreate;
+ functions.destroy = CCTKi_TimerGetTimeOfDayDestroy;
+ functions.start = CCTKi_TimerGetTimeOfDayStart;
+ functions.stop = CCTKi_TimerGetTimeOfDayStop;
+ functions.reset = CCTKi_TimerGetTimeOfDayReset;
+ functions.get = CCTKi_TimerGetTimeOfDayGet;
+ functions.set = CCTKi_TimerGetTimeOfDaySet;
+
+}
+
+#endif /* HAVE_GETTIMEOFDAY */
+
+
+/*********************************************************************
+ **************** getrusage based timers *******************
+ *********************************************************************/
+
+#ifdef HAVE_GETRUSAGE
+
+#include <sys/resource.h>
+
+/* A structure to hold the relevent data */
+typedef struct
+{
+ double total;
+ double last;
+} t_GetrUsageTimer;
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageCreate
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Create the timer structure for use with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void *CCTKi_TimerGetrUsageCreate(int timernum)
+{
+ t_GetrUsageTimer *this;
+
+ this = malloc(sizeof(t_GetrUsageTimer));
+
+ if(this)
+ {
+ this->total = 0;
+ this->last = 0;
+ }
+
+ return this;
+}
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageDestroy
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Destroy the timer structure for use with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetrUsageDestroy(int timernum, t_GetrUsageTimer *data)
+{
+ if(data)
+ {
+ free(data);
+ }
+}
+
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageStart
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Start the timer with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetrUsageStart(int timernum, t_GetrUsageTimer *data)
+{
+ struct rusage ru;
+
+ getrusage(RUSAGE_SELF, &ru);
+
+ data->last = ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec/1000000.0;
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageStart
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Stop the timer with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetrUsageStop(int timernum, t_GetrUsageTimer *data)
+{
+ struct rusage ru;
+
+ getrusage(RUSAGE_SELF, &ru);
+
+ data->total += (ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec/1000000.0 - data->last);
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageReset
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Reset the timer with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetrUsageReset(int timernum, t_GetrUsageTimer *data)
+{
+
+ data->last = 0;
+ data->total = 0;
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageGet
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Get the time recorded with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+double CCTKi_TimerGetrUsageGet(int timernum, t_GetrUsageTimer *data)
+{
+
+ return data->total;
+
+}
+
+ /*@@
+ @routine CCTKi_TimerGetrUsageSet
+ @date Wed Oct 20 18:28:19 1999
+ @author Tom Goodale
+ @desc
+ Set the time for a getrusage function based timer.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_TimerGetrUsageSet(int timernum, t_GetrUsageTimer *data, double val)
+{
+ data->total = val;
+}
+
+ /*@@
+ @routine CCTKi_RegisterTimersGetrUsage
+ @date Wed Oct 20 18:32:17 1999
+ @author Tom Goodale
+ @desc
+ Register all the timer functions associated with the getrusage function.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+void CCTKi_RegisterTimersGetrUsage(void)
+{
+ t_TimerFuncs functions;
+
+ functions.create = CCTKi_TimerGetrUsageCreate;
+ functions.destroy = CCTKi_TimerGetrUsageDestroy;
+ functions.start = CCTKi_TimerGetrUsageStart;
+ functions.stop = CCTKi_TimerGetrUsageStop;
+ functions.reset = CCTKi_TimerGetrUsageReset;
+ functions.get = CCTKi_TimerGetrUsageGet;
+ functions.set = CCTKi_TimerGetrUsageSet;
+
+}
+
+#endif /* HAVE_GETRUSAGE */
diff --git a/src/main/InitialiseDataStructures.c b/src/main/InitialiseDataStructures.c
index 1391b6ec..28a08fd5 100644
--- a/src/main/InitialiseDataStructures.c
+++ b/src/main/InitialiseDataStructures.c
@@ -38,6 +38,9 @@ static char *rcsid = "$Id$";
int InitialiseDataStructures(tFleshConfig *ConfigData)
{
+
+ CCTKi_RegisterDefaultTimerFunctions();
+
ConfigData->nGHs = 0;
ConfigData->GH = NULL;
diff --git a/src/main/make.code.defn b/src/main/make.code.defn
index 98d15f5d..8546d4cc 100644
--- a/src/main/make.code.defn
+++ b/src/main/make.code.defn
@@ -12,6 +12,7 @@ CallStartupFunctions.c\
CommandLine.c\
ConfigData.c\
Coord.c\
+DefaultTimers.c\
Dummies.c\
flesh.cc\
FortranWrappers.c\
diff --git a/src/util/CactusTimers.c b/src/util/CactusTimers.c
index c50f7256..5ba8d47b 100644
--- a/src/util/CactusTimers.c
+++ b/src/util/CactusTimers.c
@@ -42,18 +42,6 @@ void CactusResetTimer(cTimer *timer)
{
}
-
-typedef struct
-{
- void *(*create)(int);
- void (*destroy)(int, void *);
- void (*start)(int, void *);
- void (*stop)(int, void *);
- void (*reset)(int, void *);
- char *(*get)(int, void *);
- void (*set)(int, void *, const char *);
-} t_TimerFuncs;
-
typedef struct
{
void **data;
@@ -338,7 +326,7 @@ char *CCTK_TimerGet(const char *name)
t_TimerFuncs *funcs;
int this_timer;
int handle;
- char *this_val;
+ char this_val[100];
char *retval;
char *temp;
int retlength;
@@ -355,7 +343,7 @@ char *CCTK_TimerGet(const char *name)
for(handle = 0; handle < n_timertypes; handle++)
{
funcs = (t_TimerFuncs *)Util_GetHandledData(handles, handle);
- this_val = funcs->get(this_timer, timer->data[handle]);
+ sprintf(this_val, "%lf", funcs->get(this_timer, timer->data[handle]));
retlength += 2+strlen(this_val);
temp = realloc(retval, retlength);
if(temp)