diff --git a/CMakeLists.txt b/CMakeLists.txt index fb6e17c5a674f2cab0a29773d5525be30cfac26f..5a129577ed73f8c1c1e01c793bca86551ae6f361 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ find_program(LYNX lynx) find_program(CAT cat) find_program(GIT git) find_program(LD ld) +find_program(CTAGS ctags) # Define PACKAGE macro in tarantool/config.h set (PACKAGE "Tarantool") @@ -88,6 +89,10 @@ check_function_exists(fmemopen HAVE_FMEMOPEN) check_function_exists(funopen HAVE_FUNOPEN) check_function_exists(fopencookie HAVE_FOPENCOOKIE) check_function_exists(uuidgen HAVE_UUIDGEN) +# +# clock_gettime() is not defined on Mac OS X, +# or own (slow) implementation is in third_party/clock_gettime.c +# check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) # Checks for libev @@ -106,8 +111,9 @@ check_library_exists("" __libc_stack_end "" HAVE_LIBC_STACK_END) # # Enable 'make tags' target. # -add_custom_target(tags COMMAND ctags -R -f tags +add_custom_target(tags COMMAND ${CTAGS} -R -f tags WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +add_custom_target(ctags DEPENDS tags) # # Define PACKAGE_VERSION -- a string constant with tarantool version. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d330b1b0093bc2566e1d8878f3e2c297bfc7e438..e2443e352b6eb2cf30822b562914938be37dbe54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,7 +30,7 @@ lua_source(lua_sources lua/tap.lua) lua_source(lua_sources lua/fio.lua) lua_source(lua_sources lua/csv.lua) lua_source(lua_sources lua/strict.lua) -lua_source(lua_sources lua/time.lua) +lua_source(lua_sources lua/clock.lua) lua_source(lua_sources ../third_party/luafun/fun.lua) # LuaJIT jit.* library lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bc.lua") diff --git a/src/lua/clock.lua b/src/lua/clock.lua new file mode 100644 index 0000000000000000000000000000000000000000..60c78663caca653f3391236034a65af52efa4ddb --- /dev/null +++ b/src/lua/clock.lua @@ -0,0 +1,40 @@ +-- clock.lua -- internal file +local clock = {} +local ffi = require('ffi') + +ffi.cdef[[ + double clock_realtime(void); + double clock_monotonic(void); + double clock_process(void); + double clock_thread(void); + uint64_t clock_realtime64(void); + uint64_t clock_monotonic64(void); + uint64_t clock_process64(void); + uint64_t clock_thread64(void); +]] + +local C = ffi.C + +clock.realtime = C.clock_realtime +clock.monotonic = C.clock_monotonic +clock.proc = C.clock_process +clock.thread = C.clock_thread + +clock.realtime64 = C.clock_realtime64 +clock.monotonic64 = C.clock_monotonic64 +clock.proc64 = C.clock_process64 +clock.thread64 = C.clock_thread64 + +clock.time = clock.realtime +clock.time64 = clock.realtime64 + +clock.bench = function(fun, ...) + local overhead = clock.proc() + overhead = clock.proc() - overhead + local start_time = clock.proc() + local res = {0, fun(...)} + res[1] = clock.proc() - start_time - overhead, res + return res +end + +return clock diff --git a/src/lua/init.cc b/src/lua/init.cc index 70328eb172bdd7716a78bbc0c6d0ccfae37af5c0..032ad8e9a88a933de132789a8e13b2a42bd2f05f 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -98,7 +98,7 @@ extern char strict_lua[], dump_lua[], csv_lua[], v_lua[], - time_lua[]; + clock_lua[]; #if LUAJIT_VERSION_NUM >= 20100 /* LuaJIT 2.1+ */ extern char p_lua[], zone_lua[]; @@ -118,7 +118,7 @@ static const char *lua_modules[] = { "uri", uri_lua, "fio", fio_lua, "csv", csv_lua, - "time", time_lua, + "clock", clock_lua, "socket", bsdsocket_lua, "console", console_lua, "tap", tap_lua, diff --git a/src/lua/time.lua b/src/lua/time.lua deleted file mode 100644 index 35f6afee6d1802ae44aeac35dde1acfc67c934ee..0000000000000000000000000000000000000000 --- a/src/lua/time.lua +++ /dev/null @@ -1,49 +0,0 @@ --- init.lua -- internal file -local time = {} -local ffi = require('ffi') - -ffi.cdef[[ - double clock_realtime(void); - double clock_monotonic(void); - double clock_process(void); - double clock_thread(void); - uint64_t clock_realtime64(void); - uint64_t clock_monotonic64(void); - uint64_t clock_process64(void); - uint64_t clock_thread64(void); -]] - -local C = ffi.C - -time.realtime = C.clock_realtime -time.monotonic = C.clock_monotonic -time.proc = C.clock_process -time.thread = C.clock_thread - -time.realtime64 = C.clock_realtime64 -time.monotonic64 = C.clock_monotonic64 -time.proc64 = C.clock_process64 -time.thread64 = C.clock_thread64 - -time.time = time.realtime -time.time64 = time.realtime64 - -time.bench = function(fun, ...) - local overhead = time.proc() - overhead = time.proc() - overhead - local start_time = time.proc() - local res = {0, fun(...)} - res[1] = time.proc() - start_time - overhead, res - return res -end - -time.bench64 = function(fun, ...) - local overhead = time.proc64() - overhead = time.proc64() - overhead - local start_time = time.proc64() - local res = {0, fun(...)} - res[1] = time.proc64() - start_time - overhead, res - return res -end - -return time diff --git a/test/app/time.result b/test/app/clock.result similarity index 83% rename from test/app/time.result rename to test/app/clock.result index ab0357af1aed176268be36b8d895a48cf906e99f..bc3cba192bae9e98b6c2f3a1de90922aace00cdf 100644 --- a/test/app/time.result +++ b/test/app/clock.result @@ -9,4 +9,4 @@ ok - thread64 ok - monotonic64 ok - proc64 ok - time is monotonic -ok - time.realtime ~ os.time +ok - clock.realtime ~ os.time diff --git a/test/app/clock.test.lua b/test/app/clock.test.lua new file mode 100755 index 0000000000000000000000000000000000000000..dbfaddd79dbe2683660a429e3166dce7210bc55e --- /dev/null +++ b/test/app/clock.test.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env tarantool + +clock = require("clock") +test = require("tap").test("csv") +test:plan(9) +test:ok(clock.realtime() > 0, "realtime") +test:ok(clock.thread() > 0, "thread") +test:ok(clock.monotonic() > 0, "monotonic") +test:ok(clock.proc() > 0, "proc") +test:ok(clock.realtime64() > 0, "realtime64") +test:ok(clock.thread64() > 0, "thread64") +test:ok(clock.monotonic64() > 0, "monotonic64") +test:ok(clock.proc64() > 0, "proc64") + +test:ok(clock.monotonic() < clock.monotonic(), "time is monotonic") +test:ok(math.abs(clock.realtime() - os.time()) < 2, "clock.realtime ~ os.time") diff --git a/test/app/time.test.lua b/test/app/time.test.lua deleted file mode 100755 index 9c172d13d70b1daaa0ecdd919a196c9074582d64..0000000000000000000000000000000000000000 --- a/test/app/time.test.lua +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env tarantool - -time = require("time") -test = require("tap").test("csv") -test:plan(9) -test:ok(time.realtime() > 0, "realtime") -test:ok(time.thread() > 0, "thread") -test:ok(time.monotonic() > 0, "monotonic") -test:ok(time.proc() > 0, "proc") -test:ok(time.realtime64() > 0, "realtime64") -test:ok(time.thread64() > 0, "thread64") -test:ok(time.monotonic64() > 0, "monotonic64") -test:ok(time.proc64() > 0, "proc64") - -test:ok(time.monotonic() < time.monotonic(), "time is monotonic") -test:ok(math.abs(time.realtime() - os.time()) < 2, "time.realtime ~ os.time")