From a34e06a196443023c4b5fe2c18579996565e57f1 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Tue, 11 Oct 2016 17:40:01 -0700 Subject: [PATCH] Fix build on Mac OSX Sierra Summary: There are two changes here. The first is to eliminate `detail::DEFAULT_CLOCK_ID` from `Benchmark.[cpp|h]` as Sierra defines `clockid_t` as an enum type, which means that calling `clock_gettime(detail::DEFAULT_CLOCK_ID` would fail, because the enums are incompatible. As this was being used as a default, but is not actually changable anywhere, I just got rid of `detail::DEFAULT_CLOCK_ID` entirely. The second is to move `portability/BitsFunctexcept.cpp` into `libfollybase_la_SOURCES`, because it's needed for generating the fingerprint tables. Reviewed By: yfeldblum Differential Revision: D4004843 fbshipit-source-id: b2a9c33f8e516d8eb3cdc5ab093f4946ac9ed37e --- folly/Benchmark.cpp | 2 +- folly/Benchmark.h | 17 +++++------------ folly/Makefile.am | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp index 2b64c12b..b09faf2e 100644 --- a/folly/Benchmark.cpp +++ b/folly/Benchmark.cpp @@ -241,7 +241,7 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun, static uint64_t resolutionInNs = 0; if (!resolutionInNs) { timespec ts; - CHECK_EQ(0, clock_getres(detail::DEFAULT_CLOCK_ID, &ts)); + CHECK_EQ(0, clock_getres(CLOCK_REALTIME, &ts)); CHECK_EQ(0, ts.tv_sec) << "Clock sucks."; CHECK_LT(0, ts.tv_nsec) << "Clock too fast for its own good."; CHECK_EQ(1, ts.tv_nsec) << "Clock too coarse, upgrade your kernel."; diff --git a/folly/Benchmark.h b/folly/Benchmark.h index 01299798..208bee7b 100644 --- a/folly/Benchmark.h +++ b/folly/Benchmark.h @@ -52,13 +52,6 @@ inline bool runBenchmarksOnFlag() { namespace detail { -/** - * This is the clock ID used for measuring time. On older kernels, the - * resolution of this clock will be very coarse, which will cause the - * benchmarks to fail. - */ -enum Clock { DEFAULT_CLOCK_ID = CLOCK_REALTIME }; - typedef std::pair TimeIterPair; /** @@ -116,7 +109,7 @@ inline uint64_t timespecDiff(timespec end, timespec start, */ struct BenchmarkSuspender { BenchmarkSuspender() { - CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start)); + CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &start)); } BenchmarkSuspender(const BenchmarkSuspender &) = delete; @@ -149,7 +142,7 @@ struct BenchmarkSuspender { void rehire() { assert(start.tv_nsec == 0 || start.tv_sec == 0); - CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start)); + CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &start)); } template @@ -176,7 +169,7 @@ struct BenchmarkSuspender { private: void tally() { timespec end; - CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &end)); + CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &end)); nsSpent += detail::timespecDiff(end, start); start = end; } @@ -203,9 +196,9 @@ addBenchmark(const char* file, const char* name, Lambda&& lambda) { unsigned int niter; // CORE MEASUREMENT STARTS - auto const r1 = clock_gettime(detail::DEFAULT_CLOCK_ID, &start); + auto const r1 = clock_gettime(CLOCK_REALTIME, &start); niter = lambda(times); - auto const r2 = clock_gettime(detail::DEFAULT_CLOCK_ID, &end); + auto const r2 = clock_gettime(CLOCK_REALTIME, &end); // CORE MEASUREMENT ENDS CHECK_EQ(0, r1); diff --git a/folly/Makefile.am b/folly/Makefile.am index 66dc0d2e..bc507a77 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -387,6 +387,7 @@ libfollybase_la_SOURCES = \ Format.cpp \ FormatTables.cpp \ MallctlHelper.cpp \ + portability/BitsFunctexcept.cpp \ StringBase.cpp \ String.cpp \ Unicode.cpp @@ -448,7 +449,6 @@ libfolly_la_SOURCES = \ detail/SocketFastOpen.cpp \ MacAddress.cpp \ MemoryMapping.cpp \ - portability/BitsFunctexcept.cpp \ portability/Dirent.cpp \ portability/Environment.cpp \ portability/Fcntl.cpp \ -- 2.34.1