From 0b8c73478268e2ae2fd8888b0bad0abe2d5a7296 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Thu, 16 Oct 2025 18:30:11 +0200 Subject: [PATCH] added converter to bsread timestamps --- dap/utils/__init__.py | 1 + dap/utils/timestamp.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 dap/utils/timestamp.py diff --git a/dap/utils/__init__.py b/dap/utils/__init__.py index 26acf15..cb78642 100644 --- a/dap/utils/__init__.py +++ b/dap/utils/__init__.py @@ -5,5 +5,6 @@ from .bufjson import BufferedJSON from .filehandler import FileHandler from .randskip import randskip from .sorter import Sorter +from .timestamp import make_bsread_timestamp diff --git a/dap/utils/timestamp.py b/dap/utils/timestamp.py new file mode 100644 index 0000000..1e860fa --- /dev/null +++ b/dap/utils/timestamp.py @@ -0,0 +1,15 @@ + +NANOS_PER_S = 10**9 +NANOS_PER_MILLIS = 10**6 + + +def make_bsread_timestamp(ts, pid): + """ + ts is assumed to be from time.time_ns() and NOT from time.time() + """ + secs, nanosecs = divmod(ts, NANOS_PER_S) + nanosecs = (nanosecs // NANOS_PER_MILLIS) * NANOS_PER_MILLIS + (pid % NANOS_PER_MILLIS) + return secs, nanosecs + + +