Skip to content
Browse files

Another attempt to fix issue #4. If we find time attributed to a line…

… that's not in the current function, we guess that LuaJIT forgot to tell us about a return and move up a stack frame. We do this even if the stack frame above doesn't work either. Now, we check if the stack frame above actualy works. If it doesn't, we complain, but we don't move up the extra stack frame.
  • Loading branch information...
1 parent 7540f61 commit 83b5bfe604577d089c30b62ef75a68fd44fa75cc @geoffleyland committed Apr 4, 2013
Showing with 21 additions and 18 deletions.
  1. +21 −18 lua/luatrace/profile.lua
View
39 lua/luatrace/profile.lua
@@ -263,29 +263,32 @@ function profile.record(a, b, c, d)
local top = get_top()
- if top then
- if top.func.line_defined > 0 and
- (line_number < top.func.line_defined or line_number > top.func.last_line_defined) then
- -- luajit sometimes forgets to tell us about returns at all, so guess that
- -- there might have been one and try again
+ if top.func.line_defined > 0 and
+ (line_number < top.func.line_defined or line_number > top.func.last_line_defined) then
+ -- luajit sometimes forgets to tell us about returns at all, so guess that
+ -- there might have been one and try again
+-- do_return()
+-- top = get_top()
+ local above_top = stack[stack.top-1]
+ if not above_top or
+ (above_top.func.line_defined > 0 and
+ (line_number < above_top.func.line_defined or line_number > above_top.func.last_line_defined)) then
+ error_count = error_count + 1
+ io.stderr:write(("ERROR (%4d, line %7d): counted execution of %g microseconds at line %d of a function defined at %s:%d-%d\n"):
+ format(error_count, trace_count, time, line_number, top.func.source_file.filename, top.func.line_defined, top.func.last_line_defined))
+ else
do_return()
top = get_top()
- if top.func.line_defined > 0 and
- (line_number < top.func.line_defined or line_number > top.func.last_line_defined) then
- error_count = error_count + 1
- io.stderr:write(("ERROR (%4d, line %7d): counted execution of %g microseconds at line %d of a function defined at %s:%d-%d\n"):
- format(error_count, trace_count, time, line_number, top.func.source_file.filename, top.func.line_defined, top.func.last_line_defined))
- end
end
+ end
- local line = get_line(line_number)
- if top.current_line ~= line then
- line.hits = line.hits + 1
- end
- line.self_time = line.self_time + time
- top.func.self_time = top.func.self_time + time
- top.current_line = line
+ local line = get_line(line_number)
+ if top.current_line ~= line then
+ line.hits = line.hits + 1
end
+ line.self_time = line.self_time + time
+ top.func.self_time = top.func.self_time + time
+ top.current_line = line
end
end

0 comments on commit 83b5bfe

Please sign in to comment.
Something went wrong with that request. Please try again.