From c01bc0847f0d9d37cb40ccbb9496bd5a2c48be88 Mon Sep 17 00:00:00 2001 From: Simon Nagl Date: Mon, 16 Jan 2017 12:13:18 +0100 Subject: [PATCH] Adapt processors and pid_max to macOS Number of processors form sysctl hw.logicalcpu pid_max (99999) from bsd/sys/proc_internal.h in XNU sources disable apps.plugin because of compile issues. This was not working either. --- src/Makefile.am | 2 ++ src/common.c | 23 +++++++++++++++++++++++ src/macos_sysctl.c | 4 ---- src/plugin_macos.h | 4 ++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 264e58df..f8feabdf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,9 @@ dist_cache_DATA = .keep dist_varlib_DATA = .keep dist_registry_DATA = .keep dist_log_DATA = .keep +if !MACOS plugins_PROGRAMS = apps.plugin +endif netdata_SOURCES = \ appconfig.c appconfig.h \ diff --git a/src/common.c b/src/common.c index 36fa0c9b..609412b5 100644 --- a/src/common.c +++ b/src/common.c @@ -1100,6 +1100,18 @@ int processors = 1; long get_system_cpus(void) { processors = 1; + #ifdef __APPLE__ + int32_t tmp_processors; + + if (unlikely(GETSYSCTL("hw.logicalcpu", tmp_processors))) { + error("Assuming system has %d processors.", processors); + } else { + processors = tmp_processors; + } + + return processors; + #else + char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix); @@ -1129,10 +1141,19 @@ long get_system_cpus(void) { debug(D_SYSTEM, "System has %d processors.", processors); return processors; + + #endif /* __APPLE__ */ } pid_t pid_max = 32768; pid_t get_system_pid_max(void) { + #ifdef __APPLE__ + // As we currently do not know a solution to query pid_max from the os + // we use the number defined in bsd/sys/proc_internal.h in XNU sources + pid_max = 99999; + return pid_max; + #else + char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix); procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT); @@ -1158,6 +1179,8 @@ pid_t get_system_pid_max(void) { procfile_close(ff); debug(D_SYSTEM, "System supports %d pids.", pid_max); return pid_max; + + #endif /* __APPLE__ */ } unsigned int hz; diff --git a/src/macos_sysctl.c b/src/macos_sysctl.c index 3a8498ef..955b7075 100644 --- a/src/macos_sysctl.c +++ b/src/macos_sysctl.c @@ -20,13 +20,9 @@ // NEEDED BY do_uptime #include -#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) - // MacOS calculates load averages once every 5 seconds #define MIN_LOADAVG_UPDATE_EVERY 5 -int getsysctl(const char *name, void *ptr, size_t len); - int do_macos_sysctl(int update_every, usec_t dt) { (void)dt; diff --git a/src/plugin_macos.h b/src/plugin_macos.h index a6f966a8..a21e5601 100644 --- a/src/plugin_macos.h +++ b/src/plugin_macos.h @@ -3,6 +3,10 @@ void *macos_main(void *ptr); +#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var)) + +extern int getsysctl(const char *name, void *ptr, size_t len); + extern int do_macos_sysctl(int update_every, usec_t dt); extern int do_macos_mach_smi(int update_every, usec_t dt); extern int do_macos_iokit(int update_every, usec_t dt); -- 2.39.2