]> arthur.barton.de Git - netdata.git/commitdiff
Merge pull request #1575 from simonnagl/feature/macOS
authorCosta Tsaousis <costa@tsaousis.gr>
Wed, 18 Jan 2017 01:21:01 +0000 (03:21 +0200)
committerGitHub <noreply@github.com>
Wed, 18 Jan 2017 01:21:01 +0000 (03:21 +0200)
Adapt processors and pid_max to macOS

1  2 
src/Makefile.am
src/common.c

diff --combined src/Makefile.am
index d7adc7c2d862cc2f12382cbd119d0c959c614a9e,f8feabdff7c78c30032a331ca96681b24e8777ac..b5c83883694632b8b555878eee0aa489cfc42813
@@@ -24,7 -24,9 +24,9 @@@ dist_cache_DATA = .kee
  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 \
@@@ -37,7 -39,6 +39,7 @@@
        eval.c eval.h \
        global_statistics.c global_statistics.h \
        health.c health.h \
 +      inlined.h \
        log.c log.h \
        main.c main.h \
        plugin_checks.c plugin_checks.h \
@@@ -125,7 -126,6 +127,7 @@@ apps_plugin_SOURCES = 
        avl.c avl.h \
        clocks.c clocks.h \
        common.c common.h \
 +      inlined.h \
        log.c log.h \
        procfile.c procfile.h \
        web_buffer.c web_buffer.h \
diff --combined src/common.c
index 28ba72594d47cef1535d0611e2755dbad8ad4d68,609412b5f1eff8e15e8ab37d93bbcac81ab0c672..f6f2ee1a40c761e0a95a4fdcf0a614d7767ee3a7
@@@ -807,7 -807,7 +807,7 @@@ uint32_t simple_hash(const char *name
  }
  */
  
 -
 +/*
  // http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
  uint32_t simple_hash(const char *name) {
      unsigned char *s = (unsigned char *) name;
@@@ -842,7 -842,6 +842,7 @@@ uint32_t simple_uhash(const char *name
      }
      return hval;
  }
 +*/
  
  /*
  // http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
@@@ -1101,6 -1100,18 +1101,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);
  
  
      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);
      procfile_close(ff);
      debug(D_SYSTEM, "System supports %d pids.", pid_max);
      return pid_max;
+     #endif /* __APPLE__ */
  }
  
  unsigned int hz;
@@@ -1166,8 -1188,25 +1189,8 @@@ void get_system_HZ(void) 
      long ticks;
  
      if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
 -        perror("sysconf");
 +        error("Cannot get system clock ticks");
      }
  
      hz = (unsigned int) ticks;
  }
 -
 -int read_single_number_file(const char *filename, unsigned long long *result) {
 -    char buffer[1024 + 1];
 -
 -    int fd = open(filename, O_RDONLY, 0666);
 -    if(unlikely(fd == -1)) return 1;
 -
 -    ssize_t r = read(fd, buffer, 1024);
 -    if(unlikely(r == -1)) {
 -        close(fd);
 -        return 2;
 -    }
 -
 -    close(fd);
 -    *result = strtoull(buffer, NULL, 0);
 -    return 0;
 -}