Fix build on Mac OSX Sierra
authorChristopher Dykes <cdykes@fb.com>
Wed, 12 Oct 2016 00:40:01 +0000 (17:40 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 12 Oct 2016 00:53:42 +0000 (17:53 -0700)
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
folly/Benchmark.h
folly/Makefile.am

index 2b64c12bbafca2fa31cd0837b4e5c994fcbef333..b09faf2eec011697634d3fb4e2d6a34a12d77635 100644 (file)
@@ -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.";
index 0129979856132a98e21d62e70ffe21b102d3c3ee..208bee7b22f01022633734975853f7335a4141fc 100644 (file)
@@ -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<uint64_t, unsigned int> 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 <class F>
@@ -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);
index 66dc0d2e5c31a927b08c548ffd6161d41fbef2b2..bc507a77e352ba32908985a690060d6b9928b8e5 100644 (file)
@@ -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 \