From 60c6caad9caa8eb9e4848c95efb7de2aaebbc11c Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 30 Jul 2020 18:09:08 -0700 Subject: [PATCH] little less python --- messaging/messaging_pyx.pyx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/messaging/messaging_pyx.pyx b/messaging/messaging_pyx.pyx index f166bb6..642ea2e 100644 --- a/messaging/messaging_pyx.pyx +++ b/messaging/messaging_pyx.pyx @@ -18,12 +18,21 @@ import capnp from cereal import log from cereal.services import service_list -try: - from common.realtime import sec_since_boot -except ImportError: - import time - sec_since_boot = time.time - print("Warning, using python time.time() instead of faster sec_since_boot") +from posix.time cimport clock_gettime, timespec, CLOCK_MONOTONIC_RAW, clockid_t +IF UNAME_SYSNAME == "Darwin": + # Darwin doesn't have a CLOCK_BOOTTIME + CLOCK_BOOTTIME = CLOCK_MONOTONIC_RAW +ELSE: + from posix.time cimport CLOCK_BOOTTIME + +cdef double sec_since_boot(): + cdef timespec ts + cdef double current + + clock_gettime(CLOCK_BOOTTIME, &ts) + current = ts.tv_sec + (ts.tv_nsec / 1000000000.) + return current + class MessagingError(Exception): pass