diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 37cec5155..0c064856d 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -23,6 +23,9 @@ #include #include #endif +#ifdef __FreeBSD__ +#include +#endif #include #include #include @@ -2638,7 +2641,7 @@ class Benchmark { fprintf(stderr, "RocksDB: version %d.%d\n", kMajorVersion, kMinorVersion); -#if defined(__linux) || defined(__APPLE__) +#if defined(__linux) || defined(__APPLE__) || defined(__FreeBSD__) time_t now = time(nullptr); char buf[52]; // Lint complains about ctime() usage, so replace it with ctime_r(). The @@ -2696,6 +2699,19 @@ class Benchmark { fprintf(stderr, "CPU: %d * %s\n", h.max_cpus, cpu_type.c_str()); fprintf(stderr, "CPUCache: %s\n", cache_size.c_str()); } +#elif defined(__FreeBSD__) + int ncpus; + size_t len = sizeof(ncpus); + int mib[2] = {CTL_HW, HW_NCPU}; + if (sysctl(mib, 2, &ncpus, &len, nullptr, 0) == 0) { + char cpu_type[16]; + len = sizeof(cpu_type) - 1; + mib[1] = HW_MACHINE; + if (sysctl(mib, 2, cpu_type, &len, nullptr, 0) == 0) cpu_type[len] = 0; + + fprintf(stderr, "CPU: %d * %s\n", ncpus, cpu_type); + // no programmatic way to get the cache line size except on PPC + } #endif #endif }