Discussion:
Profiler stack details
Alexey Bruevich
2014-08-25 16:11:01 UTC
Permalink
Hi, I have successfully implement LuJIT profiler in our project,  but encountered with next difficulties:
Consider next code:

cont={}
function sleep(n)
    os.execute("sleep " .. tonumber(n))
end
function cont.a()
    sleep(0.01)
    return 1
end
function cont.b()
    sleep(0.02)
    return 2
end
function cont.c()
    sleep(0.03) 
    return 3
end
function t()
    for c = 1,50 do
         for i,fn in pairs(cont) do
               print ( 3, fn ,fn() )
         end
    end
end
t()

I run profiler with option luajit-2.1.0-alpha -jp=s5  my_file.lua, and have next output: 
100% sleep
<- 100% fn < t < file.lua:0:30 < @0x00404a10

In source code I've noticed that function names are deduced from callers (lj_debug_funcname), that's why (I think) we don't have any mention of  cont.{a,b,c} in stack - they are the same (fn) for profiler . Am i right? So if i'm right is there any opportunity to dump (function names) cont.{a,b,c} in stack?

Thank you!
Best regards, Alexey!
Mike Pall
2014-08-26 11:53:13 UTC
Permalink
Post by Alexey Bruevich
In source code I've noticed that function names are deduced from
callers (lj_debug_funcname), that's why (I think) we don't have
any mention of cont.{a,b,c} in stack - they are the same (fn)
for profiler . Am i right?
Lua functions don't have names. Their names can only be inferred
from their callers debug info, i.e. under what variable name or
constant field name they are being called.
Post by Alexey Bruevich
So if i'm right is there any opportunity to dump (function
names) cont.{a,b,c} in stack?
The function names cannot be deduced from the call stack. But you
could profile in line mode (-jp=ls5), which allows you to
differentiate the different functions.

Also, the profiler measures CPU time. A sleep function doesn't use
any CPU time, so you won't get useful results. Try a dummy loop in
the sleep() function, e.g.: for i=1,n*1e9 do end

--Mike
Alexey Bruevich
2014-08-26 13:40:33 UTC
Permalink
Mike, thank you for quick response!
Post by Mike Pall
The function names cannot be deduced from the call stack. But you
could profile in line mode (-jp=ls5), which allows you to
differentiate the different functions.
I've already implemented this approach, but just want to be sure that there is no chance to deduce "original function name".  

Thank you again!

Best regards, Alexey.

Continue reading on narkive:
Loading...