Skip to content

Commit 6ec58a5

Browse files
committed
fix gettime on linux
1 parent 6a0e2df commit 6ec58a5

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

test/helpers/get_time.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local has_ffi, ffi = pcall(require, "ffi")
33

44
if not has_ffi then return os.clock end
55

6-
if ffi.os == "OSX" then
6+
if ffi.os == "OSX" and false then
77
ffi.cdef([[
88
uint64_t clock_gettime_nsec_np(int clock_id);
99
]])

test/helpers/line_profiler.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ elseif ffi.os == "Windows" then
4242
end
4343
else
4444
ffi.cdef([[
45-
struct timespec { long tv_sec; long tv_nsec; };
46-
int clock_gettime(int clock_id, struct timespec *tp);
45+
int clock_gettime(int clock_id, void *tp);
4746
]])
48-
local CLOCK_MONOTONIC = 1
49-
local ts = ffi.new("struct timespec")
47+
local ts = ffi.new("struct { long int tv_sec; long int tv_nsec; }[1]")
5048
get_time_raw = function()
51-
ffi.C.clock_gettime(CLOCK_MONOTONIC, ts)
52-
return ts.tv_sec * 1000000000ULL + ts.tv_nsec
49+
ffi.C.clock_gettime(1, ts)
50+
return ts[0].tv_sec + ts[0].tv_nsec
5351
end
5452
get_time_seconds = function(raw_time)
55-
return tonumber(raw_time) / 1000000000.0
53+
return tonumber(raw_time) * 0.000000001
5654
end
5755
end
5856

0 commit comments

Comments
 (0)