summaryrefslogtreecommitdiff
path: root/src/main/DefaultTimers.c
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-10-20 19:39:12 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-10-20 19:39:12 +0000
commitb4ed5b40f710a65cded827bcb4664e4e11061356 (patch)
treeaf95f98fa35bafb250a5c13429216fd4cc179d31 /src/main/DefaultTimers.c
parent78328da62d78e81be8e7147fa26e6f30545cce2a (diff)
Some new timer stuff. Compiles and links under linux and NT, but
untested as yet. Still need to put in MPI time and the windows time stuff, as well as hardware counters, and still need to wrap schedule stuff with timers. Tom git-svn-id: http://svn.cactuscode.org/flesh/trunk@1074 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/DefaultTimers.c')
-rw-r--r--src/main/DefaultTimers.c491
1 files changed, 491 insertions, 0 deletions
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 */