Skip to content

Commit

Permalink
- Added System.timer functions to bootstrapped OMC
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8393 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 29, 2011
1 parent 45d5b24 commit d4a7efb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 37 deletions.
34 changes: 34 additions & 0 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -531,4 +531,38 @@ extern char* System_getCurrentTimeStr()
MMC_THROW();
}

void System_resetTimer()
{
/* reset the timer */
timerIntervalTime = 0;
timerCummulatedTime = 0;
timerTime = 0;
timerStackIdx = 0;
}

void System_startTimer()
{
/* start the timer if not already started */
if (!timerStackIdx)
{
rt_tick(RT_CLOCK_SPECIAL_STOPWATCH);
}
pushTimerStack();
}

void System_stopTimer()
{
popTimerStack();
}

double System_getTimerIntervalTime()
{
return timerIntervalTime;
}

double System_getTimerCummulatedTime()
{
return timerCummulatedTime;
}

}
37 changes: 0 additions & 37 deletions Compiler/runtime/System_rml.c
Expand Up @@ -1679,13 +1679,6 @@ RML_BEGIN_LABEL(System__realtimeTock)
}
RML_END_LABEL

#define TIMER_MAX_STACK 1000
double timerIntervalTime = 0;
double timerCummulatedTime = 0;
double timerTime = 0;
long int timerStackIdx = 0;
double timerStack[TIMER_MAX_STACK] = {0};

RML_BEGIN_LABEL(System__resetTimer)
{
/* reset the timer */
Expand All @@ -1697,36 +1690,6 @@ RML_BEGIN_LABEL(System__resetTimer)
}
RML_END_LABEL

void pushTimerStack()
{
if (timerStackIdx < TIMER_MAX_STACK)
{
timerStack[timerStackIdx] = rt_tock(RT_CLOCK_SPECIAL_STOPWATCH);
/* increase the stack */
timerStackIdx++;
}
else
{
fprintf(stderr, "System.pushStartTime -> timerStack overflow %ld\n", timerStackIdx);
}
}

double popTimerStack()
{
if (timerStackIdx >= 1)
{
/* how much time passed since we last called startTime? */
timerIntervalTime = rt_tock(RT_CLOCK_SPECIAL_STOPWATCH) - timerStack[timerStackIdx-1];
timerCummulatedTime += timerIntervalTime;
/* decrease the stack */
timerStackIdx--;
}
else
{
fprintf(stderr, "System.popStartTime -> timerStack underflow %ld\n", timerStackIdx);
}
}

RML_BEGIN_LABEL(System__startTimer)
{
/* start the timer if not already started */
Expand Down
37 changes: 37 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -1150,6 +1150,43 @@ char* SystemImpl__unquoteIdentifier(const char* str)
return res;
}

#define TIMER_MAX_STACK 1000
static double timerIntervalTime = 0;
static double timerCummulatedTime = 0;
static double timerTime = 0;
static long int timerStackIdx = 0;
static double timerStack[TIMER_MAX_STACK] = {0};

static void pushTimerStack()
{
if (timerStackIdx < TIMER_MAX_STACK)
{
timerStack[timerStackIdx] = rt_tock(RT_CLOCK_SPECIAL_STOPWATCH);
/* increase the stack */
timerStackIdx++;
}
else
{
fprintf(stderr, "System.pushStartTime -> timerStack overflow %ld\n", timerStackIdx);
}
}

static double popTimerStack()
{
if (timerStackIdx >= 1)
{
/* how much time passed since we last called startTime? */
timerIntervalTime = rt_tock(RT_CLOCK_SPECIAL_STOPWATCH) - timerStack[timerStackIdx-1];
timerCummulatedTime += timerIntervalTime;
/* decrease the stack */
timerStackIdx--;
}
else
{
fprintf(stderr, "System.popStartTime -> timerStack underflow %ld\n", timerStackIdx);
}
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit d4a7efb

Please sign in to comment.