Commit a34e06a1 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

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
parent 74ea0a31
...@@ -241,7 +241,7 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun, ...@@ -241,7 +241,7 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun,
static uint64_t resolutionInNs = 0; static uint64_t resolutionInNs = 0;
if (!resolutionInNs) { if (!resolutionInNs) {
timespec ts; 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_EQ(0, ts.tv_sec) << "Clock sucks.";
CHECK_LT(0, ts.tv_nsec) << "Clock too fast for its own good."; 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."; CHECK_EQ(1, ts.tv_nsec) << "Clock too coarse, upgrade your kernel.";
......
...@@ -52,13 +52,6 @@ inline bool runBenchmarksOnFlag() { ...@@ -52,13 +52,6 @@ inline bool runBenchmarksOnFlag() {
namespace detail { 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; typedef std::pair<uint64_t, unsigned int> TimeIterPair;
/** /**
...@@ -116,7 +109,7 @@ inline uint64_t timespecDiff(timespec end, timespec start, ...@@ -116,7 +109,7 @@ inline uint64_t timespecDiff(timespec end, timespec start,
*/ */
struct BenchmarkSuspender { struct BenchmarkSuspender {
BenchmarkSuspender() { BenchmarkSuspender() {
CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start)); CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &start));
} }
BenchmarkSuspender(const BenchmarkSuspender &) = delete; BenchmarkSuspender(const BenchmarkSuspender &) = delete;
...@@ -149,7 +142,7 @@ struct BenchmarkSuspender { ...@@ -149,7 +142,7 @@ struct BenchmarkSuspender {
void rehire() { void rehire() {
assert(start.tv_nsec == 0 || start.tv_sec == 0); 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> template <class F>
...@@ -176,7 +169,7 @@ struct BenchmarkSuspender { ...@@ -176,7 +169,7 @@ struct BenchmarkSuspender {
private: private:
void tally() { void tally() {
timespec end; 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); nsSpent += detail::timespecDiff(end, start);
start = end; start = end;
} }
...@@ -203,9 +196,9 @@ addBenchmark(const char* file, const char* name, Lambda&& lambda) { ...@@ -203,9 +196,9 @@ addBenchmark(const char* file, const char* name, Lambda&& lambda) {
unsigned int niter; unsigned int niter;
// CORE MEASUREMENT STARTS // CORE MEASUREMENT STARTS
auto const r1 = clock_gettime(detail::DEFAULT_CLOCK_ID, &start); auto const r1 = clock_gettime(CLOCK_REALTIME, &start);
niter = lambda(times); niter = lambda(times);
auto const r2 = clock_gettime(detail::DEFAULT_CLOCK_ID, &end); auto const r2 = clock_gettime(CLOCK_REALTIME, &end);
// CORE MEASUREMENT ENDS // CORE MEASUREMENT ENDS
CHECK_EQ(0, r1); CHECK_EQ(0, r1);
......
...@@ -387,6 +387,7 @@ libfollybase_la_SOURCES = \ ...@@ -387,6 +387,7 @@ libfollybase_la_SOURCES = \
Format.cpp \ Format.cpp \
FormatTables.cpp \ FormatTables.cpp \
MallctlHelper.cpp \ MallctlHelper.cpp \
portability/BitsFunctexcept.cpp \
StringBase.cpp \ StringBase.cpp \
String.cpp \ String.cpp \
Unicode.cpp Unicode.cpp
...@@ -448,7 +449,6 @@ libfolly_la_SOURCES = \ ...@@ -448,7 +449,6 @@ libfolly_la_SOURCES = \
detail/SocketFastOpen.cpp \ detail/SocketFastOpen.cpp \
MacAddress.cpp \ MacAddress.cpp \
MemoryMapping.cpp \ MemoryMapping.cpp \
portability/BitsFunctexcept.cpp \
portability/Dirent.cpp \ portability/Dirent.cpp \
portability/Environment.cpp \ portability/Environment.cpp \
portability/Fcntl.cpp \ portability/Fcntl.cpp \
......
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