Discussion:
luajit profiling using C/C++ API
Alexey Bruevich
2014-08-07 11:25:05 UTC
Permalink
Hi,
I'm trying to use luajit profiler to investigate bottlenecks of lua code in our project and have been stuck.

In a few words I describe our architecture: 
Our C++ program, call wrappers to execute different Lua scripts 

Problem: It seems that our lua scripts have bottlenecks we want to investigate.

Based on previous discussion ( http://www.freelists.org/post/luajit/LuaJIT-21-profiler-from-CC ) I have tried to enable profiler in our project, but have no luck. 
( It seems, that callback function, that passed to luaJIT_profile_start is never called. Here (  http://www.freelists.org/post/luajit/LuaJIT-21-profiler-from-CC,1 ) you wrote that  callback gets called when lua code is executing - I've checked Lua code is executing.) While investigation I noticed that "lj_dispatch_profile" function is never called. This function is important, because in it body "callback function" is calling.
I was searching for answer in Internet but there are pure information about this topic. So If it possible could you create a simple example (tutorial) how to build-in luajit profiler in C++ project. 

Thank you.
Best regards,  Alexey 
Mike Pall
2014-08-08 13:17:17 UTC
Permalink
Post by Alexey Bruevich
While investigation I noticed that "lj_dispatch_profile" function is never called.
Maybe you're blocking SIGPROF or replacing its handler or
resetting ITIMER_PROF. Check that profile_signal() is invoked.
Post by Alexey Bruevich
I was searching for answer in Internet but there are pure information about this topic. So If it possible could you create a simple example (tutorial) how to build-in luajit profiler in C++ project. 
IMHO the info in doc/ext_profiler.html#ll_c_api is all you really
need. Call luaJIT_profile_start() and then you should get
callbacks where you can call luaJIT_profile_dumpstack(). Try it
with a simple isolated C program first.

OTOH, it would be much easier to just install the jit.* Lua
modules and do the equivalent of -jp from Lua code:
require("jit.p").start(...)

--Mike
Alexey Bruevich
2014-08-08 14:41:11 UTC
Permalink
Mike, thank you for your answer! 
Post by Mike Pall
Maybe you're blocking SIGPROF or replacing its handler or
resetting ITIMER_PROF. Check that profile_signal() is invoked.
I'll check this.
Post by Mike Pall
OTOH, it would be much easier to just install the jit.* Lua
require("jit.p").start(...)
It will be the next step, if I have no success with C API. ( We have some difficulties with changing lua code.)

Thank you!
Best regards, Alexey.
Post by Mike Pall
Post by Alexey Bruevich
While investigation I noticed that "lj_dispatch_profile" function is never called.
Maybe you're blocking SIGPROF or replacing its handler or
resetting ITIMER_PROF. Check that profile_signal() is invoked.
Post by Alexey Bruevich
I was searching for answer in Internet but there are pure information about this topic. So If it possible could you create a simple example (tutorial) how to build-in luajit profiler in C++ project. 
IMHO the info in doc/ext_profiler.html#ll_c_api is all you really
need. Call luaJIT_profile_start() and then you should get
callbacks where you can call luaJIT_profile_dumpstack(). Try it
with a simple isolated C program first.
OTOH, it would be much easier to just install the jit.* Lua
  require("jit.p").start(...)
--Mike
Loading...