Commit 3fe5b493 authored by Niclas Rosenvik's avatar Niclas Rosenvik

Add NetBSD support

Add support for NetBSD.
In order to get uuid from root disk
gpt can be used but using it to get
this require root privileges so use
random uuid for now.
NetBSD has cxxabi.h with __cxa_demangle.
Add process metrics for NetBSD.
parent 12bcfbc7
......@@ -191,6 +191,8 @@
# endif
#elif defined(__FreeBSD__)
# define CAF_BSD
#elif defined(__NetBSD__)
# define CAF_NETBSD
#elif defined(__OpenBSD__)
# define CAF_BSD
#elif defined(__CYGWIN__)
......@@ -201,7 +203,7 @@
# error Platform and/or compiler not supported
#endif
#if defined(CAF_MACOS) || defined(CAF_LINUX) || defined(CAF_BSD) \
|| defined(CAF_CYGWIN)
|| defined(CAF_CYGWIN) || defined(CAF_NETBSD)
# define CAF_POSIX
#endif
......
......@@ -7,7 +7,8 @@
#include "caf/config.hpp"
#include "caf/detail/scope_guard.hpp"
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS)
#if defined(CAF_MACOS) || defined(CAF_BSD) || defined(CAF_IOS) \
|| defined(CAF_NETBSD)
# include <arpa/inet.h>
# include <cerrno>
......
......@@ -192,7 +192,7 @@ std::string get_root_uuid() {
} // namespace detail
} // namespace caf
#elif defined(CAF_IOS) || defined(CAF_ANDROID)
#elif defined(CAF_IOS) || defined(CAF_ANDROID) || defined(CAF_NETBSD)
// return a randomly-generated UUID on mobile devices
......
......@@ -6,7 +6,7 @@
#include "caf/config.hpp"
#if defined(CAF_LINUX) || defined(CAF_MACOS)
#if defined(CAF_LINUX) || defined(CAF_MACOS) || defined(CAF_NETBSD)
# include <cxxabi.h>
# include <sys/types.h>
# include <unistd.h>
......@@ -43,7 +43,7 @@ void prettify_type_name(std::string& class_name) {
}
void prettify_type_name(std::string& class_name, const char* c_class_name) {
#if defined(CAF_LINUX) || defined(CAF_MACOS)
#if defined(CAF_LINUX) || defined(CAF_MACOS) || defined(CAF_NETBSD)
int stat = 0;
std::unique_ptr<char, decltype(free)*> real_class_name{nullptr, free};
auto tmp = abi::__cxa_demangle(c_class_name, nullptr, nullptr, &stat);
......
......@@ -34,6 +34,8 @@ void set_thread_name(const char* name) {
prctl(PR_SET_NAME, name, 0, 0, 0);
# elif defined(CAF_BSD)
pthread_set_name_np(pthread_self(), name);
# elif defined(CAF_NETBSD)
pthread_setname_np(pthread_self(), name, NULL);
# endif // defined(...)
#endif // CAF_WINDOWS
}
......
......@@ -10,7 +10,7 @@
// -- detect supported platforms -----------------------------------------------
#if defined(CAF_MACOS) || defined(CAF_LINUX)
#if defined(CAF_MACOS) || defined(CAF_LINUX) || defined(CAF_NETBSD)
# define CAF_HAS_PROCESS_METRICS
#endif
......@@ -212,6 +212,51 @@ sys_stats read_sys_stats() {
#endif // CAF_LINUX
#if defined(CAF_NETBSD)
#include <sys/sysctl.h>
#include <unistd.h>
namespace {
sys_stats read_sys_stats() {
sys_stats result{0, 0, 0};
int mib[6];
struct kinfo_proc2 kip2;
size_t kip2_size = sizeof(kip2);
mib[0] = CTL_KERN;
mib[1] = KERN_PROC2;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
mib[4] = kip2_size;
mib[5] = 1;
auto page_size = sysconf(_SC_PAGE_SIZE);
if (page_size == -1) {
CAF_LOG_ERROR(
"getting _SC_PAGE_SIZE from sysconf failed in read_sys_stats");
return result;
}
if (sysctl(mib, 6, &kip2, &kip2_size, NULL, (size_t)0)) {
CAF_LOG_ERROR("sysctl failed in read_sys_stats");
return result;
}
result.rss = static_cast<int64_t>(kip2.p_vm_rssize) * page_size;
result.vms = static_cast<int64_t>(kip2.p_vm_vsize) * page_size;
result.cpu_time = kip2.p_rtime_sec;
result.cpu_time += static_cast<double>(kip2.p_rtime_usec) / 1000000;
return result;
}
} // namepace
#endif // CAF_NETBSD
namespace caf::telemetry::importer {
process::process(metric_registry& reg) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment