mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-09-12 03:03:41 +08:00
46e0ee7750
old-commit-hash: 6f46f988d9d89b5bd18e38c5e5509b5c252ae2c1
42 lines
918 B
C
42 lines
918 B
C
#ifndef COMMON_TIMING_H
|
|
#define COMMON_TIMING_H
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#ifdef __APPLE__
|
|
#define CLOCK_BOOTTIME CLOCK_REALTIME
|
|
#endif
|
|
|
|
static inline uint64_t nanos_since_boot() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_BOOTTIME, &t);
|
|
return t.tv_sec * 1000000000ULL + t.tv_nsec;
|
|
}
|
|
|
|
static inline double millis_since_boot() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_BOOTTIME, &t);
|
|
return t.tv_sec * 1000.0 + t.tv_nsec * 1e-6;
|
|
}
|
|
|
|
static inline double seconds_since_boot() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_BOOTTIME, &t);
|
|
return (double)t.tv_sec + t.tv_nsec * 1e-9;;
|
|
}
|
|
|
|
static inline uint64_t nanos_since_epoch() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_REALTIME, &t);
|
|
return t.tv_sec * 1000000000ULL + t.tv_nsec;
|
|
}
|
|
|
|
static inline double seconds_since_epoch() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_REALTIME, &t);
|
|
return (double)t.tv_sec + t.tv_nsec * 1e-9;
|
|
}
|
|
|
|
#endif
|