2021-05-17 16:06:12 +03:00
|
|
|
#include "clock.h"
|
|
|
|
|
|
|
|
#define NSEC_PER_SEC 1000000000
|
2021-05-29 18:35:40 +03:00
|
|
|
#define CLOCKS_PER_NSEC ((float)CLOCKS_PER_SEC / NSEC_PER_SEC)
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
Value *clockTimeMonotonic() { return clockTimeUtc(); }
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
Value *clockTimeUtc() { return (Value *)makeBits64(time(NULL) * NSEC_PER_SEC); }
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
Value *clockTimeProcess() {
|
|
|
|
uint64_t time_ns = clock() / CLOCKS_PER_NSEC;
|
|
|
|
return (Value *)makeBits64(time_ns);
|
2021-05-17 16:06:12 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
Value *clockTimeThread() { return clockTimeProcess(); }
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
Value *clockTimeGcCpu() { return NULL; }
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
Value *clockTimeGcReal() { return NULL; }
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
int clockValid(Value *clock) { return clock != NULL; }
|
2021-05-17 16:06:12 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
uint64_t clockSecond(Value *clock) {
|
|
|
|
uint64_t totalNano = ((Value_Bits64 *)clock)->ui64;
|
|
|
|
return totalNano / NSEC_PER_SEC;
|
2021-05-17 16:06:12 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
uint64_t clockNanosecond(Value *clock) {
|
|
|
|
uint64_t totalNano = ((Value_Bits64 *)clock)->ui64;
|
|
|
|
return totalNano % NSEC_PER_SEC;
|
2021-05-17 16:06:12 +03:00
|
|
|
}
|