summaryrefslogtreecommitdiffstats
path: root/scripts/remote/missing.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/remote/missing.py')
-rw-r--r--scripts/remote/missing.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/remote/missing.py b/scripts/remote/missing.py
new file mode 100644
index 0000000000..67c2dfa8c0
--- /dev/null
+++ b/scripts/remote/missing.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import ctypes
+import os
+
+CLOCK_MONOTONIC_RAW = 4 # from <linux/time.h>
+
+
+class timespec(ctypes.Structure):
+ _fields_ = [
+ ('tv_sec', ctypes.c_long),
+ ('tv_nsec', ctypes.c_long)
+ ]
+
+librt = ctypes.CDLL('librt.so.1', use_errno=True)
+clock_gettime = librt.clock_gettime
+clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
+
+
+def monotonic():
+ t = timespec()
+ if clock_gettime(CLOCK_MONOTONIC_RAW, ctypes.pointer(t)) != 0:
+ errno_ = ctypes.get_errno()
+ raise OSError(errno_, os.strerror(errno_))
+ return t.tv_sec + t.tv_nsec * 1e-9
+
+if __name__ == "__main__":
+ print monotonic()