mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-23 19:53:56 +08:00
* cleanup include path
* continue
* format includes
* fix testraw.cc
* remove include path from SConstruct
* regroup
* rebase master
* almost done
* apply review
* rename FileReader.xx to filereader.xx
* rename Unlogger.x->unlogger.x
* rename FrameReader.xx -> framereader.xx
* apply reviews
* ui.h
* continue
* fix framebuffer.cc build error:mv util.h up
* full path to msm_media_info
* fix qcom2 camerad
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 7222d0f20d
52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#ifdef __APPLE__
|
|
#define CLOCK_BOOTTIME CLOCK_MONOTONIC
|
|
#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;
|
|
}
|
|
|
|
// you probably should use nanos_since_boot instead
|
|
static inline uint64_t nanos_monotonic() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_MONOTONIC, &t);
|
|
return t.tv_sec * 1000000000ULL + t.tv_nsec;
|
|
}
|
|
|
|
static inline uint64_t nanos_monotonic_raw() {
|
|
struct timespec t;
|
|
clock_gettime(CLOCK_MONOTONIC_RAW, &t);
|
|
return t.tv_sec * 1000000000ULL + t.tv_nsec;
|
|
}
|