]> arthur.barton.de Git - netdata.git/commitdiff
Adapt processors and pid_max to macOS
authorSimon Nagl <simonnagl@aim.com>
Mon, 16 Jan 2017 11:13:18 +0000 (12:13 +0100)
committerSimon Nagl <simonnagl@aim.com>
Tue, 17 Jan 2017 19:47:46 +0000 (20:47 +0100)
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
src/common.c
src/macos_sysctl.c
src/plugin_macos.h

index 264e58dfb1485a13a8b2ec8a755268919f94d327..f8feabdff7c78c30032a331ca96681b24e8777ac 100644 (file)
@@ -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 \
index 36fa0c9be53468ff5cea44affbf86149da8b4422..609412b5f1eff8e15e8ab37d93bbcac81ab0c672 100644 (file)
@@ -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;
index 3a8498efa96a3d7a65b25a4ee43e8a485aaf2f47..955b70757eb02c87ddb4ecaa7be9ad1abdbd8681 100644 (file)
 // NEEDED BY do_uptime
 #include <time.h>
 
-#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;
 
index a6f966a87e0e7271b526ffd44bfffbc6618a83f6..a21e5601de13faed21661b7ca51d76f2283640ba 100644 (file)
@@ -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);