Navigation Menu

Skip to content

Commit

Permalink
Adapt processors and pid_max to macOS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Simon Nagl committed Jan 17, 2017
1 parent a90ca80 commit c01bc08
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -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 \
Expand Down
23 changes: 23 additions & 0 deletions src/common.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/macos_sysctl.c
Expand Up @@ -20,13 +20,9 @@
// 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;

Expand Down
4 changes: 4 additions & 0 deletions src/plugin_macos.h
Expand Up @@ -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);
Expand Down

0 comments on commit c01bc08

Please sign in to comment.