diff options
author | Michael Neumann <mneumann@ntecs.de> | 2020-10-12 22:41:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 23:41:49 +0300 |
commit | af72911f2fe6b8114564614d2db17a449f8c4af0 (patch) | |
tree | 635ca7516ab91cf2aba2d69e698ab665a8b2ae1f | |
parent | ffe1342eb2faa7d2e7c35b4db2ccf99fab81ec20 (diff) | |
download | google-benchmark-af72911f2fe6b8114564614d2db17a449f8c4af0.tar.gz |
Add support for DragonFly BSD (#1058)
Without this commit, compilation fails on DragonFly with the following message:
```
/home/mneumann/Dev/benchmark.old/src/sysinfo.cc:446:2: error: #warning "HOST_NAME_MAX not defined. using 64" [-Werror=cpp]
^~~~~~~
```
Also note that the sysctl is actually `hw.tsc_frequency` on DragonFly:
```
$ sysctl hw.tsc_frequency
hw.tsc_frequency: 3498984022
```
Tested on:
```
$ uname -a
DragonFly box.localnet 5.9-DEVELOPMENT DragonFly v5.9.0.742.g4b29dd-DEVELOPMENT #5: Tue Aug 18 00:21:31 CEST 2020
```
-rw-r--r-- | src/internal_macros.h | 2 | ||||
-rw-r--r-- | src/sysinfo.cc | 12 | ||||
-rw-r--r-- | src/timers.cc | 3 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/internal_macros.h b/src/internal_macros.h index 6adf00d..889b353 100644 --- a/src/internal_macros.h +++ b/src/internal_macros.h @@ -58,6 +58,8 @@ #define BENCHMARK_OS_NETBSD 1 #elif defined(__OpenBSD__) #define BENCHMARK_OS_OPENBSD 1 +#elif defined(__DragonFly__) + #define BENCHMARK_OS_DRAGONFLY 1 #elif defined(__linux__) #define BENCHMARK_OS_LINUX 1 #elif defined(__native_client__) diff --git a/src/sysinfo.cc b/src/sysinfo.cc index 8bab932..b30b4f8 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -29,7 +29,8 @@ #include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD #include <unistd.h> #if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || \ - defined BENCHMARK_OS_NETBSD || defined BENCHMARK_OS_OPENBSD + defined BENCHMARK_OS_NETBSD || defined BENCHMARK_OS_OPENBSD || \ + defined BENCHMARK_OS_DRAGONFLY #define BENCHMARK_HAS_SYSCTL #include <sys/sysctl.h> #endif @@ -607,6 +608,8 @@ double GetCPUCyclesPerSecond() { "machdep.tsc_freq"; #elif defined BENCHMARK_OS_OPENBSD "hw.cpuspeed"; +#elif defined BENCHMARK_OS_DRAGONFLY + "hw.tsc_frequency"; #else "hw.cpufrequency"; #endif @@ -671,9 +674,10 @@ double GetCPUCyclesPerSecond() { } std::vector<double> GetLoadAvg() { -#if (defined BENCHMARK_OS_FREEBSD || defined(BENCHMARK_OS_LINUX) || \ - defined BENCHMARK_OS_MACOSX || defined BENCHMARK_OS_NETBSD || \ - defined BENCHMARK_OS_OPENBSD) && !defined(__ANDROID__) +#if (defined BENCHMARK_OS_FREEBSD || defined(BENCHMARK_OS_LINUX) || \ + defined BENCHMARK_OS_MACOSX || defined BENCHMARK_OS_NETBSD || \ + defined BENCHMARK_OS_OPENBSD || defined BENCHMARK_OS_DRAGONFLY) && \ + !defined(__ANDROID__) constexpr int kMaxSamples = 3; std::vector<double> res(kMaxSamples, 0.0); const int nelem = getloadavg(res.data(), kMaxSamples); diff --git a/src/timers.cc b/src/timers.cc index 4f76edd..1d3ab9a 100644 --- a/src/timers.cc +++ b/src/timers.cc @@ -28,7 +28,8 @@ #include <sys/time.h> #include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD #include <unistd.h> -#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX +#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_DRAGONFLY || \ + defined BENCHMARK_OS_MACOSX #include <sys/sysctl.h> #endif #if defined(BENCHMARK_OS_MACOSX) |