2019-12-01 01:02:08 -07:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "time_func.h"
|
|
|
|
|
2019-12-07 13:07:59 -07:00
|
|
|
static TIMESTAMP start_timestamp = 0; /* time since epoch at start of run */
|
2019-12-01 01:02:08 -07:00
|
|
|
|
2019-12-01 15:43:05 -07:00
|
|
|
TIMESTAMP Time_since_epoch(void)
|
2019-12-01 01:02:08 -07:00
|
|
|
{
|
|
|
|
TIMESTAMP rc;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
rc = (tv.tv_sec * (TIMESTAMP)1000) + (tv.tv_usec / (TIMESTAMP)1000);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-12-01 15:43:05 -07:00
|
|
|
TIMESTAMP Time_since_start(void)
|
2019-12-01 01:02:08 -07:00
|
|
|
{
|
2019-12-01 15:45:46 -07:00
|
|
|
return Time_since_epoch() - start_timestamp;
|
2019-12-01 01:02:08 -07:00
|
|
|
}
|
|
|
|
|
2019-12-01 15:43:05 -07:00
|
|
|
void Time_init(void)
|
2019-12-01 01:02:08 -07:00
|
|
|
{
|
2019-12-01 15:45:46 -07:00
|
|
|
start_timestamp = Time_since_epoch();
|
2019-12-01 01:02:08 -07:00
|
|
|
}
|