summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-12-01 16:05:56 (GMT)
committerGitHub <noreply@github.com>2023-12-01 16:05:56 (GMT)
commit05a370abd6cdfe4b54be60b3b911f3a441026bb2 (patch)
tree09caae085de5a3a2f666f89f8d3ceec01faaad82 /Python
parenta9073564ee50bc610e1fd36e45b0a5204618883a (diff)
downloadcpython-05a370abd6cdfe4b54be60b3b911f3a441026bb2.zip
cpython-05a370abd6cdfe4b54be60b3b911f3a441026bb2.tar.gz
cpython-05a370abd6cdfe4b54be60b3b911f3a441026bb2.tar.bz2
gh-112567: Add _Py_GetTicksPerSecond() function (#112587)
* Move _PyRuntimeState.time to _posixstate.ticks_per_second and time_module_state.ticks_per_second. * Add time_module_state.clocks_per_second. * Rename _PyTime_GetClockWithInfo() to py_clock(). * Rename _PyTime_GetProcessTimeWithInfo() to py_process_time(). * Add process_time_times() helper function, called by py_process_time(). * os.times() is now always built: no longer rely on HAVE_TIMES.
Diffstat (limited to 'Python')
-rw-r--r--Python/fileutils.c24
-rw-r--r--Python/pylifecycle.c5
2 files changed, 24 insertions, 5 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 649b188..9d12bc8 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -2943,3 +2943,27 @@ _Py_closerange(int first, int last)
#endif /* USE_FDWALK */
_Py_END_SUPPRESS_IPH
}
+
+
+#ifndef MS_WINDOWS
+// Ticks per second used by clock() and times() functions.
+// See os.times() and time.process_time() implementations.
+int
+_Py_GetTicksPerSecond(long *ticks_per_second)
+{
+#if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
+ long value = sysconf(_SC_CLK_TCK);
+ if (value < 1) {
+ return -1;
+ }
+ *ticks_per_second = value;
+#elif defined(HZ)
+ assert(HZ >= 1);
+ *ticks_per_second = HZ;
+#else
+ // Magic fallback value; may be bogus
+ *ticks_per_second = 60;
+#endif
+ return 0;
+}
+#endif
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index aff67d7..95a72eb 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -528,11 +528,6 @@ pycore_init_runtime(_PyRuntimeState *runtime,
return status;
}
- status = _PyTime_Init();
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
status = _PyImport_Init();
if (_PyStatus_EXCEPTION(status)) {
return status;