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.
Simon Nagl committed
Jan 16, 2017 at 12:13 UTC
c01bc0847f0d9d37cb40ccbb9496bd5a2c48be88
4 files changed
+29
-4
src/Makefile.am
+2
@@ -24,7 +24,9 @@ dist_cache_DATA = .keep
24
dist_varlib_DATA = .keep
25
dist_registry_DATA = .keep
26
dist_log_DATA = .keep
27
+if !MACOS
28
plugins_PROGRAMS = apps.plugin
29
+endif
30
31
netdata_SOURCES = \
32
appconfig.c appconfig.h \
src/common.c
+23
@@ -1100,6 +1100,18 @@ int processors = 1;
1100
long get_system_cpus(void) {
1101
processors = 1;
1102
1103
+ #ifdef __APPLE__
1104
+ int32_t tmp_processors;
1105
+
1106
+ if (unlikely(GETSYSCTL("hw.logicalcpu", tmp_processors))) {
1107
+ error("Assuming system has %d processors.", processors);
1108
+ } else {
1109
+ processors = tmp_processors;
1110
+ }
1111
+
1112
+ return processors;
1113
+ #else
1114
+
1115
char filename[FILENAME_MAX + 1];
1116
snprintfz(filename, FILENAME_MAX, "%s/proc/stat", global_host_prefix);
1117
@@ -1129,10 +1141,19 @@ long get_system_cpus(void) {
1141
1142
debug(D_SYSTEM, "System has %d processors.", processors);
1143
return processors;
1144
+
1145
+ #endif /* __APPLE__ */
1146
}
1147
1148
pid_t pid_max = 32768;
1149
pid_t get_system_pid_max(void) {
1150
+ #ifdef __APPLE__
1151
+ // As we currently do not know a solution to query pid_max from the os
1152
+ // we use the number defined in bsd/sys/proc_internal.h in XNU sources
1153
+ pid_max = 99999;
1154
+ return pid_max;
1155
+ #else
1156
+
1157
char filename[FILENAME_MAX + 1];
1158
snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", global_host_prefix);
1159
procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
@@ -1158,6 +1179,8 @@ pid_t get_system_pid_max(void) {
1179
procfile_close(ff);
1180
debug(D_SYSTEM, "System supports %d pids.", pid_max);
1181
return pid_max;
1182
+
1183
+ #endif /* __APPLE__ */
1184
}
1185
1186
unsigned int hz;
src/macos_sysctl.c
-4
@@ -20,13 +20,9 @@
20
// NEEDED BY do_uptime
21
#include <time.h>
22
23
-#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
24
-
23
// MacOS calculates load averages once every 5 seconds
24
#define MIN_LOADAVG_UPDATE_EVERY 5
25
28
-int getsysctl(const char *name, void *ptr, size_t len);
29
-
26
int do_macos_sysctl(int update_every, usec_t dt) {
27
(void)dt;
28
src/plugin_macos.h
+4
@@ -3,6 +3,10 @@
3
4
void *macos_main(void *ptr);
5
6
+#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
7
+
8
+extern int getsysctl(const char *name, void *ptr, size_t len);
9
+
10
extern int do_macos_sysctl(int update_every, usec_t dt);
11
extern int do_macos_mach_smi(int update_every, usec_t dt);
12
extern int do_macos_iokit(int update_every, usec_t dt);