]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/util: port collect_sys_info() to osx
authorKefu Chai <kchai@redhat.com>
Sat, 9 Sep 2017 16:15:18 +0000 (00:15 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 16 Sep 2017 02:43:32 +0000 (10:43 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/util.cc

index 25578cb5d5a4be22d6f836a19c8d1e87b802e6aa..97b476c3e996ce6cd321d56196d615ada22db4df 100644 (file)
 #if defined(__APPLE__) || defined(__FreeBSD__)
 #include <sys/param.h>
 #include <sys/mount.h>
+#if defined(__APPLE__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
 #endif
 
 #include <string>
@@ -203,7 +207,35 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
     (*m)["hostname"] = u.nodename;
     (*m)["arch"] = u.machine;
   }
-
+#ifdef __APPLE__
+  // memory
+  {
+    uint64_t size;
+    size_t len = sizeof(size);
+    r = sysctlbyname("hw.memsize", &size, &len, NULL, 0);
+    if (r == 0) {
+      (*m)["mem_total_kb"] = std::to_string(size);
+    }
+  }
+  {
+    xsw_usage vmusage;
+    size_t len = sizeof(vmusage);
+    r = sysctlbyname("vm.swapusage", &vmusage, &len, NULL, 0);
+    if (r == 0) {
+      (*m)["mem_swap_kb"] = std::to_string(vmusage.xsu_total);
+    }
+  }
+  // processor
+  {
+    char buf[100];
+    size_t len = sizeof(buf);
+    r = sysctlbyname("machdep.cpu.brand_string", buf, &len, NULL, 0);
+    if (r == 0) {
+      buf[len - 1] = '\0';
+      (*m)["cpu"] = buf;
+    }
+  }
+#else
   // memory
   FILE *f = fopen(PROCPREFIX "/proc/meminfo", "r");
   if (f) {
@@ -248,7 +280,7 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
     }
     fclose(f);
   }
-
+#endif
   // distro info
   distro_detect(m, cct);
 }