Parcourir la source

[2040] DHCP benchmarks now compile on Mac OS

Tomek Mrugalski il y a 12 ans
Parent
commit
272d9f6f5b

+ 12 - 2
tests/tools/dhcp-ubench/Makefile

@@ -1,11 +1,21 @@
+# Linux switches
 CFLAGS=-g -O0 -Wall -pedantic -Wextra
+
+# Mac OS: We don't use pedantic as Mac OS version of MySQL (5.5.24) does use long long (not part of ISO C++)
+#CFLAGS=-g -O0 -Wall -Wextra -I/opt/local/include
+
+# Mac OS does not require -lrt
+# Linux requires -lrt
 LDFLAGS=-lrt
 
 MEMFILE_CFLAGS=
 MEMFILE_LDFLAGS=
 
-MYSQL_CFLAGS=`mysql_config --cflags`
-MYSQL_LDFLAGS=`mysql_config --libs`
+# It is mysql_config on most Linux systems and mysql_config5 on Mac OS
+MYSQL_CONFIG=mysql_config
+
+MYSQL_CFLAGS=`$(MYSQL_CONFIG) --cflags`
+MYSQL_LDFLAGS=`$(MYSQL_CONFIG) --libs`
 
 SQLITE_CFLAGS=`pkg-config sqlite3 --cflags`
 SQLITE_LDFLAGS=`pkg-config sqlite3 --libs`

+ 32 - 5
tests/tools/dhcp-ubench/benchmark.cc

@@ -18,6 +18,15 @@
 #include <boost/lexical_cast.hpp>
 #include "benchmark.h"
 
+// The following headers are for getting precise time (clock_gettime on Linux or that mac os thingie)
+#include <time.h>
+#include <sys/time.h>
+#ifdef __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
+
+
 using namespace std;
 
 uBenchmark::uBenchmark(uint32_t iterations, const std::string& dbname,
@@ -140,19 +149,19 @@ int uBenchmark::run() {
     try {
         connect();
 
-        clock_gettime(CLOCK_REALTIME, &ts_[0]);
+        ts_[0] = get_time();
 
         createLease4Test();
-        clock_gettime(CLOCK_REALTIME, &ts_[1]);
+        ts_[1] = get_time();
 
         searchLease4Test();
-        clock_gettime(CLOCK_REALTIME, &ts_[2]);
+        ts_[2] = get_time();
 
         updateLease4Test();
-        clock_gettime(CLOCK_REALTIME, &ts_[3]);
+        ts_[3] = get_time();
 
         deleteLease4Test();
-        clock_gettime(CLOCK_REALTIME, &ts_[4]);
+        ts_[4] = get_time();
 
         disconnect();
 
@@ -168,3 +177,21 @@ int uBenchmark::run() {
 
     return (0);
 }
+
+struct timespec uBenchmark::get_time() {
+    struct timespec ts;
+
+#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+    clock_serv_t cclock;
+    mach_timespec_t mts;
+    host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+    clock_get_time(cclock, &mts);
+    mach_port_deallocate(mach_task_self(), cclock);
+    ts.tv_sec = mts.tv_sec;
+    ts.tv_nsec = mts.tv_nsec;
+#else
+    clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+
+    return ts;
+}

+ 5 - 3
tests/tools/dhcp-ubench/benchmark.h

@@ -172,6 +172,9 @@ protected:
     /// @brief prints out command-line help (list of parameters + version)
     void usage();
 
+    /// @brief a wrapper around OS-specific method for getting time
+    struct timespec get_time();
+
     /// Number of operations (e.g. insert lease num times)
     uint32_t num_;
 
@@ -189,9 +192,8 @@ protected:
 
     /// @brief hit ratio for search test (must be between 0.0 and 1.0)
     ///
-    /// This parameter is used in seatch. The formula causes the search
-    /// to find something a lease in 90% cases of hit ratio is 0.9.
-    ///
+    /// This parameter is used in search benchmark. The formula causes the
+    /// search to find something a lease in 90% cases of hit ratio is 0.9.
     float hitratio_;
 
     /// benchmarks must generate the leases starting from 1.0.0.0 address

+ 1 - 1
tests/tools/dhcp-ubench/mysql_ubench.cc

@@ -18,7 +18,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
-#include <mysql/mysql.h>
+#include <mysql.h>
 
 #include "benchmark.h"
 #include "mysql_ubench.h"