Are there any lua profilers that work with LuaJIT 2.x?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Are there any lua profilers that work with LuaJIT 2.x?

lua.greatwolf
Greetings,

I was wondering if there are any suitable profiling tools for checking
script performance in LuaJIT. I've tried most of the profilers listed in
the lua wiki:

http://lua-users.org/wiki/ProfilingLuaCode

but the main problem I keep running into is that none of them can
properly profile lua C function calls. The main issue seems to be that
LuaJIT doesn't implement the "return" sethook when C functions are
called. What ends up happening is that the final generated report would
end up listing any C function calls as taking up 0 time.

Are there any other alternatives or different approach to consider? How
would one profile lua script performance under LuaJIT when lua C
functions are involve?

Thanks,


Reply | Threaded
Open this post in threaded view
|

Re: Are there any lua profilers that work with LuaJIT 2.x?

Geoff Leyland
On 3/09/2013, at 4:00 PM, [hidden email] wrote:

> Greetings,
>
> I was wondering if there are any suitable profiling tools for checking script performance in LuaJIT. I've tried most of the profilers listed in the lua wiki:
>
> http://lua-users.org/wiki/ProfilingLuaCode
>
> but the main problem I keep running into is that none of them can properly profile lua C function calls. The main issue seems to be that LuaJIT doesn't implement the "return" sethook when C functions are called. What ends up happening is that the final generated report would end up listing any C function calls as taking up 0 time.

I thought I'd got that one right at least, but it's been a while since I worked on or used luatrace I don't really remember.  In any case, tracing both Lua and LuaJIT with the same code is difficult, and hooks don't play well with jit.on.

> Are there any other alternatives or different approach to consider? How would one profile lua script performance under LuaJIT when lua C functions are involve?

Mike mentioned profiling in the LuaJIT list in June:

http://www.freelists.org/post/luajit/RFC-Lowoverhead-profiling-for-LuaJIT-21
Reply | Threaded
Open this post in threaded view
|

Re: Re: Are there any lua profilers that work with LuaJIT 2.x?

lua.greatwolf
In reply to this post by lua.greatwolf
>
> I thought I'd got that one right at least, but it's been a while since
> I worked on or used luatrace I don't really remember.
> In any case, tracing both Lua and LuaJIT with the same code is
> difficult, and hooks don't play well with jit.on.
>

Thanks for the response. I only tried luatrace briefly but it does seem
to track call times for C functions correctly. Unfortunately, it doesn't
seem to be very usable in its current state. For example, there's too
much of a performance hit when tracing is turned on. It also generates a
massive amount of information that isn't really viewable as is. There's
a lot of non-critical data dumped into the trace file that simple isn't
relevant to optimizing the program at hand and weeding all of that out
is a lot of work.

Is there someway to reduce the amount of 'noise' luatrace records or
even better, have some kind of sampling mode that grabs the callstack on
some specified frequency?
>> Are there any other alternatives or different approach to consider?
>> How would one profile lua script performance under LuaJIT when lua C
>> functions are involve?
>
> Mike mentioned profiling in the LuaJIT list in June:
>
> http://www.freelists.org/post/luajit/RFC-Lowoverhead-profiling-for-LuaJIT-21
I did read through that thread and the impression I got was that it's
still under development and it's unclear to me what its current status
is. For example, are the primitive underlying constructs and tools
needed to develop a profiler in place and stable? The thread itself is
way back in June but I haven't found other threads about profiling since
then.


Reply | Threaded
Open this post in threaded view
|

Re: Are there any lua profilers that work with LuaJIT 2.x?

Geoff Leyland
On 4/09/2013, at 3:14 PM, [hidden email] wrote:

>> I thought I'd got that one right at least, but it's been a while since I worked on or used luatrace I don't really remember.
>
> Thanks for the response. I only tried luatrace briefly but it does seem to track call times for C functions correctly. Unfortunately, it doesn't seem to be very usable in its current state. For example, there's too much of a performance hit when tracing is turned on.

Hooks are slow.  Try
time lua -e "for i = 1, 10000000 do end"
and
time lua -e "debug.sethook(function() end, 'crl') for i = 1, 10000000 do end"

C hooks are a little better, but really, anything hook-based is going to be problematic.

> It also generates a massive amount of information that isn't really viewable as is. There's a lot of non-critical data dumped into the trace file that simple isn't relevant to optimizing the program at hand and weeding all of that out is a lot of work.

I don't know what your program is or what data is or isn't relevant to optimising your program.  If it helps you can turn luatrace on or off for sections of your program.

The trace file contains timings for every line that's traced, so I don't see that as irrelevant to general profiling (if you want a line-by-line profiler).  Are you actually looking at the trace file or the annotated source?  You could try lua -luatrace.profile and avoid the intermediate file.

> Is there someway to reduce the amount of 'noise' luatrace records or even better, have some kind of sampling mode that grabs the callstack on some specified frequency?

No.  Luatrace is a line-by-line profiler rather than a sampling profiler.  Sampling profilers are available though (not sure which ones).  One of the problems with a sampling profiler you can't accurately reconstruct a call stack in the presence of tail recursion.  Luatrace does quite a bit of work to (try to) catch tail returns, but to do so, it needs to check every line.  I think you might find sampling profilers won't ever catch any time in C functions either.

>> Mike mentioned profiling in the LuaJIT list in June:
>>
>> http://www.freelists.org/post/luajit/RFC-Lowoverhead-profiling-for-LuaJIT-21
> I did read through that thread and the impression I got was that it's still under development and it's unclear to me what its current status is. For example, are the primitive underlying constructs and tools needed to develop a profiler in place and stable? The thread itself is way back in June but I haven't found other threads about profiling since then.

It's probably best to ask on the LuaJIT list.


Reply | Threaded
Open this post in threaded view
|

Re: Are there any lua profilers that work with LuaJIT 2.x?

Yichun Zhang (agentzh)
In reply to this post by lua.greatwolf
Hello!

On Mon, Sep 2, 2013 at 9:00 PM,  <[hidden email]> wrote:
>
> I was wondering if there are any suitable profiling tools for checking
> script performance in LuaJIT. I've tried most of the profilers listed in the
> lua wiki:
>

We've been using tools based on systemtap to trace our Lua code in
production and have solved tons of bottlenecks in our Lua code and
even in LuaJIT 2.0 itself.

Basically we use the ngx-sample-bt tool to do VM level profiling and
ngx-sample-lua-bt to do Lua language level profiling (both Lua 5.1 and
LuaJIT 2.0 are supported):

    https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-bt
    https://github.com/agentzh/nginx-systemtap-toolkit#ngx-sample-lua-bt

Flame graphs are the visualization method used here.

I've also talked about these tools and shown some production
flamegraphs in these slides:

    http://agentzh.org/misc/slides/yapc-na-2013-flame-graphs.pdf

This approach does not only work for Lua 5.1 or LuaJIT 2.0/2.1, but
also work for Perl 5, Nginx, and other things. The runtime overhead is
quite small even for really busy online systems.

Best regards,
-agentzh