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
|
|
|
|
|
|
|
Value *clockTimeMonotonic()
|
|
|
|
{
|
|
|
|
return clockTimeUtc();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *clockTimeUtc()
|
|
|
|
{
|
2021-06-03 12:44:42 +03:00
|
|
|
return (Value *)makeBits64(time(NULL) * NSEC_PER_SEC);
|
2021-05-17 16:06:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Value *clockTimeProcess()
|
|
|
|
{
|
|
|
|
uint64_t time_ns = clock() / CLOCKS_PER_NSEC;
|
2021-06-03 12:44:42 +03:00
|
|
|
return (Value *)makeBits64(time_ns);
|
2021-05-17 16:06:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Value *clockTimeThread()
|
|
|
|
{
|
|
|
|
return clockTimeProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *clockTimeGcCpu()
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *clockTimeGcReal()
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clockValid(Value *clock)
|
|
|
|
{
|
|
|
|
return clock != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t clockSecond(Value *clock)
|
|
|
|
{
|
2021-06-03 12:44:42 +03:00
|
|
|
uint64_t totalNano = ((Value_Bits64 *)clock)->ui64;
|
2021-05-17 16:06:12 +03:00
|
|
|
return totalNano / NSEC_PER_SEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t clockNanosecond(Value *clock)
|
|
|
|
{
|
2021-06-03 12:44:42 +03:00
|
|
|
uint64_t totalNano = ((Value_Bits64 *)clock)->ui64;
|
2021-05-17 16:06:12 +03:00
|
|
|
return totalNano % NSEC_PER_SEC;
|
|
|
|
}
|