Skip to content

Commit

Permalink
Add function to get elapsed time
Browse files Browse the repository at this point in the history
  • Loading branch information
capehill committed Oct 6, 2022
1 parent 2f92268 commit 9829365
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 20 additions & 2 deletions timer.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#include "timer.h"
#include "logger.h"
#include "profiling.h"

#include <proto/exec.h>
#include <proto/timer.h>
#include <dos/dos.h>

#include <stdio.h>

static MyClock start;
static ULONG frequency = 0;
static int users = 0;

TimerContext triggerTimer;

static void read_frequency(void)
{
struct EClockVal clockVal;
frequency = ITimer->ReadEClock(&clockVal);
frequency = ITimer->ReadEClock(&start.clockVal);

logLine("Timer frequency %lu ticks / second", frequency);
}
Expand Down Expand Up @@ -217,3 +218,20 @@ double timer_ticks_to_us(const uint64 ticks)
{
return 1000000.0 * timer_ticks_to_s(ticks);
}

double timer_get_elapsed_seconds()
{
double time = 0.0;

if (ITimer) {
struct MyClock now;

ITimer->ReadEClock(&now.clockVal);

const uint64 elapsed = now.ticks - start.ticks;
time = timer_ticks_to_s(elapsed);
}

return time;
}

2 changes: 2 additions & 0 deletions timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ double timer_ticks_to_s(const uint64 ticks);
double timer_ticks_to_ms(const uint64 ticks);
double timer_ticks_to_us(const uint64 ticks);

double timer_get_elapsed_seconds();

#endif

0 comments on commit 9829365

Please sign in to comment.