summaryrefslogtreecommitdiff
path: root/src/util/CactusTimers.c
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-10-22 10:13:14 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>1999-10-22 10:13:14 +0000
commitbe202dad37826c03a9503ca8e801d745d04415fb (patch)
treed660d8dd22f0e39c8a61da8da5a6ea3dfc0aa85c /src/util/CactusTimers.c
parent0bfe852f857e3e134d505fea9f35e74d1dea270f (diff)
More updates to timer stuff.
Now to get info from a timer, one must create a timer info function: info = CCTK_TimerCreateInfo(); Get the data CCTK_TimerGet(timer, info); Query the fields in the info structure, and then either query another timer with the same info structure, or destroy the info structure. CCTK_TimerDestroyInfo(info); The info structure contains the number of values, and an array of these values, along with header info, units, data types and values. I think this is a fairly complete interface, but if a better one can be found, this may change. Tom git-svn-id: http://svn.cactuscode.org/flesh/trunk@1083 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util/CactusTimers.c')
-rw-r--r--src/util/CactusTimers.c122
1 files changed, 83 insertions, 39 deletions
diff --git a/src/util/CactusTimers.c b/src/util/CactusTimers.c
index 308bd355..faf60d3d 100644
--- a/src/util/CactusTimers.c
+++ b/src/util/CactusTimers.c
@@ -26,11 +26,15 @@ static void CCTKi_TimerDestroy(int this_timer, t_Timer *timer);
static void CCTKi_TimerStart(int this_timer, t_Timer *timer);
static void CCTKi_TimerStop(int this_timer, t_Timer *timer);
static void CCTKi_TimerReset(int this_timer, t_Timer *timer);
-static char *CCTKi_TimerGet(int this_timer, t_Timer *timer);
+static void CCTKi_TimerGet(int this_timer, t_Timer *timer, t_TimerInfo *info);
static int n_timertypes = 0;
static cHandledData *handles = NULL;
+/* The total number of timer values. */
+static int n_timer_vals = 0;
+
+
static int n_timers = 0;
static cHandledData *timers = NULL;
@@ -57,6 +61,7 @@ int CCTK_TimerRegister(const char *name, t_TimerFuncs *functions)
if(newfuncs)
{
+ newfuncs->info.n_vals = functions->info.n_vals;
newfuncs->create = functions->create;
newfuncs->destroy = functions->destroy;
newfuncs->start = functions->start;
@@ -68,6 +73,7 @@ int CCTK_TimerRegister(const char *name, t_TimerFuncs *functions)
handle = Util_NewHandle(&handles, name, newfuncs);
n_timertypes++;
+ n_timer_vals += functions->info.n_vals;
return handle;
}
@@ -131,6 +137,32 @@ int CCTK_TimerCreate(const char *name)
}
/*@@
+ @routine CCTK_TimerCreateI
+ @date Fri Oct 22 10:21:14 1999
+ @author Tom Goodale
+ @desc
+ Creates a timer with a unique name.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int CCTK_TimerCreateI(void)
+{
+ int retval;
+ char name[20];
+
+ sprintf(name, "timer_%d", n_timers);
+
+ retval = CCTK_TimerCreate(name);
+
+ return retval;
+}
+
+ /*@@
@routine CCTK_TimerDestroy
@date Wed Sep 1 10:10:20 1999
@author Tom Goodale
@@ -393,79 +425,91 @@ static void CCTKi_TimerReset(int this_timer, t_Timer *timer)
@endhistory
@@*/
-char *CCTK_TimerGet(const char *name)
+void CCTK_TimerGet(const char *name, t_TimerInfo *info)
{
t_Timer *timer;
int this_timer;
- char *retval;
if(this_timer = Util_GetHandle(timers, name, (void **)&timer))
{
- retval = CCTKi_TimerGet(this_timer, timer);
- }
- else
- {
- retval = NULL;
+ CCTKi_TimerGet(this_timer, timer, info);
}
- return retval;
+ return;
}
-char *CCTK_TimerGetI(int this_timer)
+void CCTK_TimerGetI(int this_timer, t_TimerInfo *info)
{
t_Timer *timer;
- char *retval;
if(timer = Util_GetHandledData(timers, this_timer))
{
- retval = CCTKi_TimerGet(this_timer, timer);
- }
- else
- {
- retval = NULL;
+ CCTKi_TimerGet(this_timer, timer, info);
}
-
- return retval;
+
+ return;
}
-static char *CCTKi_TimerGet(int this_timer, t_Timer *timer)
+
+
+
+static void CCTKi_TimerGet(int this_timer, t_Timer *timer, t_TimerInfo *info)
{
t_TimerFuncs *funcs;
int handle;
- char this_val[100];
- char *retval;
- char *temp;
- int retlength;
-
- retlength = 0;
- retval = NULL;
+ int total_vars;
if(timer)
{
if(timer->data)
{
+ total_vars = 0;
/* Start the timer info for this timer */
for(handle = 0; handle < n_timertypes; handle++)
{
funcs = (t_TimerFuncs *)Util_GetHandledData(handles, handle);
- sprintf(this_val, "%lf", funcs->get(this_timer, timer->data[handle]));
- retlength += 2+strlen(this_val);
- temp = realloc(retval, retlength);
- if(temp)
- {
- retval = temp;
-
- /* If this isn't the first one, add a couple of spaces. */
- if(retlength > 2+strlen(this_val)) strcat(retval, " ");
-
- strcat(retval, this_val);
- }
+ funcs->get(this_timer, timer->data[handle], &(info->vals[total_vars]));
+
+ total_vars += funcs->info.n_vals;
}
}
}
- return retval;
}
+t_TimerInfo *CCTK_TimerCreateInfo(void)
+{
+ t_TimerInfo *retval;
+
+ retval = (t_TimerInfo *)malloc(sizeof(t_TimerInfo));
+ if(retval)
+ {
+ retval->n_vals = n_timer_vals;
+
+ retval->vals = (t_TimerVal *)malloc(n_timer_vals*sizeof(t_TimerVal));
+
+ if(! retval->vals)
+ {
+ free(retval);
+ retval = NULL;
+ }
+ }
+
+ return retval;
+}
+
+void CCTK_TimerDestroyInfo(t_TimerInfo *info)
+{
+ if(info)
+ {
+ if(info->vals)
+ {
+ free(info->vals);
+ info->vals = NULL;
+ }
+ free(info);
+ }
+}
+