2019-04-27 12:53:23 -04:00
|
|
|
module ProcessSpecs
|
|
|
|
def self.clock_constants
|
|
|
|
clocks = []
|
|
|
|
|
|
|
|
platform_is_not :windows, :solaris do
|
|
|
|
clocks += Process.constants.select { |c| c.to_s.start_with?('CLOCK_') }
|
|
|
|
|
|
|
|
# These require CAP_WAKE_ALARM and are not documented in
|
2019-04-28 08:35:17 -04:00
|
|
|
# Process#clock_gettime. They return EINVAL if the permission
|
2019-04-27 12:53:23 -04:00
|
|
|
# is not granted.
|
|
|
|
clocks -= [:CLOCK_BOOTTIME_ALARM, :CLOCK_REALTIME_ALARM]
|
|
|
|
end
|
|
|
|
|
2019-04-28 08:36:03 -04:00
|
|
|
clocks.map { |c|
|
|
|
|
[c, Process.const_get(c)]
|
|
|
|
}
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|
2019-04-28 08:52:55 -04:00
|
|
|
|
|
|
|
def self.clock_constants_for_resolution_checks
|
|
|
|
clocks = clock_constants
|
|
|
|
|
|
|
|
# These clocks in practice on Linux do not seem to match their reported resolution.
|
2019-04-28 08:54:42 -04:00
|
|
|
platform_is :linux do
|
|
|
|
clocks = clocks.reject { |clock, value|
|
|
|
|
[:CLOCK_REALTIME_COARSE, :CLOCK_MONOTONIC_COARSE].include?(clock)
|
|
|
|
}
|
|
|
|
end
|
2019-04-28 08:52:55 -04:00
|
|
|
|
2019-04-28 09:23:12 -04:00
|
|
|
# These clocks in practice on macOS seem to be less precise than advertised by clock_getres
|
|
|
|
platform_is :darwin do
|
|
|
|
clocks = clocks.reject { |clock, value|
|
2019-04-28 17:29:10 -04:00
|
|
|
[:CLOCK_UPTIME_RAW_APPROX, :CLOCK_MONOTONIC_RAW_APPROX].include?(clock)
|
2019-04-28 09:23:12 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-04-28 08:52:55 -04:00
|
|
|
# These clocks in practice on ARM on Linux do not seem to match their reported resolution.
|
|
|
|
platform_is :armv7l, :aarch64 do
|
|
|
|
clocks = clocks.reject { |clock, value|
|
|
|
|
[:CLOCK_PROCESS_CPUTIME_ID, :CLOCK_THREAD_CPUTIME_ID, :CLOCK_MONOTONIC_RAW].include?(clock)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-05-24 08:29:47 -04:00
|
|
|
# These clocks in practice on AIX seem to be more precise than their reported resolution.
|
|
|
|
platform_is :aix do
|
|
|
|
clocks = clocks.reject { |clock, value|
|
|
|
|
[:CLOCK_REALTIME, :CLOCK_MONOTONIC].include?(clock)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-05-20 04:40:34 -04:00
|
|
|
# On a Hyper-V Linux guest machine, these clocks in practice
|
|
|
|
# seem to be less precise than advertised by clock_getres
|
|
|
|
platform_is :linux do
|
|
|
|
clocks = clocks.reject { |clock, value|
|
|
|
|
clock == :CLOCK_MONOTONIC_RAW
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-04-28 08:52:55 -04:00
|
|
|
clocks
|
|
|
|
end
|
2019-04-27 12:53:23 -04:00
|
|
|
end
|