Created
March 14, 2016 10:05
-
-
Save elvinio/953cae294a6320b67d40 to your computer and use it in GitHub Desktop.
Return clock_gettime in python by invoking librt system call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import ctypes, os | |
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 realtime(): | |
t = timespec() | |
if clock_gettime(0, ctypes.pointer(t)) != 0: | |
errno_ = ctypes.get_errno() | |
raise OSError(errno_, os.strerror(errno_)) | |
print t.tv_nsec | |
#return str(t.tv_sec) + "." + str(t.tv_nsec) | |
if __name__ == "__main__": | |
for i in range(0, 100): | |
realtime() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment