1 # Copyright (c) 2009, 2010 Nicira, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 class timespec(ctypes.Structure):
24 ('tv_sec', ctypes.c_long),
25 ('tv_nsec', ctypes.c_long),
29 librt = ctypes.CDLL(LIBRT)
30 clock_gettime = librt.clock_gettime
31 clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
33 # Librt shared library could not be loaded
41 if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(t)) == 0:
42 return t.tv_sec + t.tv_nsec * 1e-9
43 # Kernel does not support CLOCK_MONOTONIC
46 # Use time.monotonic() if Python version >= 3.3
47 if not hasattr(time, 'monotonic'):
48 time.monotonic = monotonic
51 """Returns the current time, as the amount of time since the epoch, in
52 milliseconds, as a float."""
53 return time.monotonic() * 1000.0