Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from ctypes import *
- #The accuracy of various system calls that set timeouts, (e.g., select(2), sigtimedwait(2)) and measure CPU time (e.g., getrusage(2)) is limited by the resolution of the software clock, a clock maintained by the kernel which measures time in jiffies. The size of a jiffy is determined by the value of the kernel constant HZ.
- #The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respec‐ tively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the com‐ mon video frame rates (PAL, 25 HZ; NTSC, 30 HZ).
- #The times(2) system call is a special case. It reports times with a granularity defined by the kernel constant USER_HZ. Userspace applica‐ tions can determine the value of this constant using sysconf(_SC_CLK_TCK).
- rt = CDLL('librt.so.1')
- CLOCK_REALTIME = 0
- class timespec(Structure):
- _fields_ = [("tv_sec", c_long), ("tv_nsec", c_long)]
- res = timespec()
- rt.clock_getres(CLOCK_REALTIME, byref(res))
- print res.tv_sec, res.tv_nsec
- SYSTEM_HZ = round(1/(res.tv_sec + (res.tv_nsec/10.0**9)))
- print SYSTEM_HZ
- print os.sysconf_names['SC_CLK_TCK']
- print os.sysconf(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement