#ifndef PROTOTYPE1_SRC_L2_MARGARET_TIME_H
#define PROTOTYPE1_SRC_L2_MARGARET_TIME_H

#include <time.h>
#include "../../l1/core/util.h"

typedef struct timespec margaret_ns_time;

margaret_ns_time margaret_clock_gettime_monotonic_raw() {
    margaret_ns_time res;
    int ret = clock_gettime(CLOCK_MONOTONIC_RAW, &res);
    if (ret < 0)
        abortf("clock_gettime");
    return res;
}

int64_t margaret_ns_time_ns_diff(margaret_ns_time from, margaret_ns_time to) {
    return (to.tv_sec - from.tv_sec) * 1000000000 + (to.tv_nsec - from.tv_nsec);
}

float margaret_ns_time_sec_diff(margaret_ns_time from, margaret_ns_time to) {
    return (float)margaret_ns_time_ns_diff(from, to) / 1e9f;
}

float margaret_clock_monotonic_raw_diff(margaret_ns_time start) {
    return (float)margaret_ns_time_ns_diff(start, margaret_clock_gettime_monotonic_raw()) / 1e9f;
}


#endif