]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
processes plugin: Use `sysconf(_SC_CLK_TCK)` instead of `CONFIG_HZ`.
authorFlorian Forster <octo@collectd.org>
Fri, 19 Jan 2024 08:36:53 +0000 (09:36 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 24 Feb 2024 22:21:29 +0000 (23:21 +0100)
configure.ac
src/processes.c

index d67199e8a5f37c133ae851c947abc56149e9433d..f7b30be091d88ebe88d20092e21513858fcbd2a1 100644 (file)
@@ -588,9 +588,8 @@ AC_CHECK_HEADERS([sys/swap.h vm/anon.h],
 )
 
 # For load module
-# For the processes plugin
 # For users module
-AC_CHECK_HEADERS([sys/loadavg.h linux/config.h utmp.h utmpx.h])
+AC_CHECK_HEADERS([sys/loadavg.h utmp.h utmpx.h])
 
 # For quota module
 AC_CHECK_HEADERS([sys/ucred.h], [], [],
index 0a9bc94889fab682d832d51e173e23e85ebf20ed..d25e7969b46f9e383246bf8c2d5c2525fd2a76fb 100644 (file)
 /* #endif HAVE_THREAD_INFO */
 
 #elif KERNEL_LINUX
-#if HAVE_LINUX_CONFIG_H
-#include <linux/config.h>
-#endif
-#ifndef CONFIG_HZ
-#define CONFIG_HZ 100
-#endif
+/* no-op */
 /* #endif KERNEL_LINUX */
 
 #elif HAVE_LIBKVM_GETPROCS &&                                                  \
@@ -894,7 +889,6 @@ static int ps_init(void) {
 
 #elif KERNEL_LINUX
   pagesize_g = sysconf(_SC_PAGESIZE);
-  DEBUG("pagesize_g = %li; CONFIG_HZ = %i;", pagesize_g, CONFIG_HZ);
 
 #if HAVE_LIBTASKSTATS
   if (taskstats_handle == NULL) {
@@ -1653,9 +1647,11 @@ static int ps_read_process(long pid, process_entry_t *ps, char *state) {
                                            : stack_ptr - stack_start;
   }
 
-  /* Convert jiffies to useconds */
-  cpu_user_counter = cpu_user_counter * 1000000 / CONFIG_HZ;
-  cpu_system_counter = cpu_system_counter * 1000000 / CONFIG_HZ;
+  derive_t clock_ticks = (derive_t)sysconf(_SC_CLK_TCK);
+
+  /* Convert to microseconds */
+  cpu_user_counter = cpu_user_counter * 1000000 / clock_ticks;
+  cpu_system_counter = cpu_system_counter * 1000000 / clock_ticks;
   vmem_rss = vmem_rss * pagesize_g;
 
   ps->cpu_user_counter = cpu_user_counter;