12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
22
clock_gettime_name = 'clock_gettime'
24
if sys.platform.startswith("linux"):
26
time_t = ctypes.c_long
27
elif sys.platform.startswith("netbsd"):
28
# NetBSD uses function renaming for ABI versioning. While the proper
29
# way to get the appropriate version is of course "#include <time.h>",
30
# it is difficult with ctypes. The following is appropriate for
31
# recent versions of NetBSD, including NetBSD-6.
33
clock_gettime_name = '__clock_gettime50'
35
time_t = ctypes.c_int64
36
elif sys.platform.startswith("freebsd"):
38
time_t = ctypes.c_int64
42
class timespec(ctypes.Structure):
45
('tv_nsec', ctypes.c_long),
48
librt = ctypes.CDLL(LIBRT)
49
clock_gettime = getattr(librt, clock_gettime_name)
50
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
52
# Librt shared library could not be loaded
60
if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(t)) == 0:
61
return t.tv_sec + t.tv_nsec * 1e-9
62
# Kernel does not support CLOCK_MONOTONIC
65
# Use time.monotonic() if Python version >= 3.3
66
if not hasattr(time, 'monotonic'):
67
time.monotonic = monotonic
19
"""Returns the current time, as the amount of time since the epoch, in
20
milliseconds, as a float."""
21
return time.time() * 1000.0
70
""" Returns the system's monotonic time if possible, otherwise returns the
71
current time as the amount of time since the epoch, in milliseconds, as a
73
return time.monotonic() * 1000.0