blob: 21f5c3313179d10fbf64c43247f6c9b5010cc1fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// file : core/timer.c
// project : Salis-VM
// author : Paul Oliver <contact@pauloliver.dev>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <threads.h>
#include <zlib.h>
#include "arch_spec.h"
#include "compress.h"
#include "salis.h"
#include "timer.h"
void timer_reset(struct Timer *timer) {
assert(timer);
timer->step_start = g_step;
clock_gettime(CLOCK_MONOTONIC_COARSE, &timer->time_start);
timer->steps_per_sec = 0.f;
}
void timer_measure(struct Timer *timer) {
assert(timer);
uint64_t step_end = g_step;
struct timespec time_end;
clock_gettime(CLOCK_MONOTONIC_COARSE, &time_end);
float step_delta = (float)(step_end - timer->step_start);
float time_delta = (float)(time_end.tv_sec - timer->time_start.tv_sec);
time_delta += (float)(time_end.tv_nsec - timer->time_start.tv_nsec) / 1000000000.f;
timer->steps_per_sec = step_delta / time_delta;
}
|