Skip to content

Commit a34e06a

Browse files
OrvidFacebook Github Bot
authored andcommitted
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
1 parent 74ea0a3 commit a34e06a

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

folly/Benchmark.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static double runBenchmarkGetNSPerIteration(const BenchmarkFun& fun,
241241
static uint64_t resolutionInNs = 0;
242242
if (!resolutionInNs) {
243243
timespec ts;
244-
CHECK_EQ(0, clock_getres(detail::DEFAULT_CLOCK_ID, &ts));
244+
CHECK_EQ(0, clock_getres(CLOCK_REALTIME, &ts));
245245
CHECK_EQ(0, ts.tv_sec) << "Clock sucks.";
246246
CHECK_LT(0, ts.tv_nsec) << "Clock too fast for its own good.";
247247
CHECK_EQ(1, ts.tv_nsec) << "Clock too coarse, upgrade your kernel.";

folly/Benchmark.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ inline bool runBenchmarksOnFlag() {
5252

5353
namespace detail {
5454

55-
/**
56-
* This is the clock ID used for measuring time. On older kernels, the
57-
* resolution of this clock will be very coarse, which will cause the
58-
* benchmarks to fail.
59-
*/
60-
enum Clock { DEFAULT_CLOCK_ID = CLOCK_REALTIME };
61-
6255
typedef std::pair<uint64_t, unsigned int> TimeIterPair;
6356

6457
/**
@@ -116,7 +109,7 @@ inline uint64_t timespecDiff(timespec end, timespec start,
116109
*/
117110
struct BenchmarkSuspender {
118111
BenchmarkSuspender() {
119-
CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start));
112+
CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &start));
120113
}
121114

122115
BenchmarkSuspender(const BenchmarkSuspender &) = delete;
@@ -149,7 +142,7 @@ struct BenchmarkSuspender {
149142

150143
void rehire() {
151144
assert(start.tv_nsec == 0 || start.tv_sec == 0);
152-
CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &start));
145+
CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &start));
153146
}
154147

155148
template <class F>
@@ -176,7 +169,7 @@ struct BenchmarkSuspender {
176169
private:
177170
void tally() {
178171
timespec end;
179-
CHECK_EQ(0, clock_gettime(detail::DEFAULT_CLOCK_ID, &end));
172+
CHECK_EQ(0, clock_gettime(CLOCK_REALTIME, &end));
180173
nsSpent += detail::timespecDiff(end, start);
181174
start = end;
182175
}
@@ -203,9 +196,9 @@ addBenchmark(const char* file, const char* name, Lambda&& lambda) {
203196
unsigned int niter;
204197

205198
// CORE MEASUREMENT STARTS
206-
auto const r1 = clock_gettime(detail::DEFAULT_CLOCK_ID, &start);
199+
auto const r1 = clock_gettime(CLOCK_REALTIME, &start);
207200
niter = lambda(times);
208-
auto const r2 = clock_gettime(detail::DEFAULT_CLOCK_ID, &end);
201+
auto const r2 = clock_gettime(CLOCK_REALTIME, &end);
209202
// CORE MEASUREMENT ENDS
210203

211204
CHECK_EQ(0, r1);

folly/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ libfollybase_la_SOURCES = \
387387
Format.cpp \
388388
FormatTables.cpp \
389389
MallctlHelper.cpp \
390+
portability/BitsFunctexcept.cpp \
390391
StringBase.cpp \
391392
String.cpp \
392393
Unicode.cpp
@@ -448,7 +449,6 @@ libfolly_la_SOURCES = \
448449
detail/SocketFastOpen.cpp \
449450
MacAddress.cpp \
450451
MemoryMapping.cpp \
451-
portability/BitsFunctexcept.cpp \
452452
portability/Dirent.cpp \
453453
portability/Environment.cpp \
454454
portability/Fcntl.cpp \

0 commit comments

Comments
 (0)