LuaJIT 2.1 profiler from C/C++

  • From: rippel tippel <rippeltippel@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 14 Nov 2013 17:09:12 +0000

First of all THANK YOU for providing a profiler : )

Now... I'm trying to invoke it from C++ but it doesn't seem to work:
luaJIT_profile_dumpstack() returns NULL and len is 0. Also , when
stepping with GDB, the profiler functions (dynamically linked) are
just skipped.

So here's what I'm doing in a nutshell...

<pre>

#include <lua.hpp>

void profilerCallback(void *data, lua_State *L, int samples, int vmstate)
{
  // Never gets called
  Log::get().info(ILua::ID(), "[>] state  : %0x", L);
  Log::get().info(ILua::ID(), "[>] samples: %d", samples);
}

void LuaProfiler::start()
{
  luaJIT_profile_start(luaState, "l", &profilerCallback, 0);
}

void LuaProfiler::stop()
{
  luaJIT_profile_stop(luaState);
}

void LuaProfiler::dump(const std::string& fileName)
{
  size_t outputLen = 0;
  lua_State* rawState = _state.getRawState();
  const char* outputString =
  luaJIT_profile_dumpstack(luaState, "F\n", 1, &outputLen);

  if (outputString == nullptr || outputLen <= 0)
  {
    // Error --> This is what I get
    return;
  }

  // Write output to file --> What I'd like to have
}

</pre>

My workflow is start() - dump() - stop() , leaving enough time
(several seconds) between these calls. However
luaJIT_profile_dumpstack() always returns NULL. Am I missing
something?

Many thanks,
Rippel

Other related posts: