Lua Tools - yszheda/wiki GitHub Wiki

Profiler

Memory Usage

Memory Leak Checker

snapshot

  1. copy snapshot source code to: frameworks/cocos2d-x/external/lua/lua-snapshot

  2. frameworks/cocos2d-x/cocos/scripting/lua-bindings/manual/lua-snapshot/lua_extensions.c:

#include "lua_extensions.h"

#if __cplusplus
extern "C" {
#endif

// snapshot
#include "lua-snapshot/snapshot.h"

static luaL_Reg luax_exts[] = {
    {"snapshot", luaopen_snapshot},
    {NULL, NULL}
};

void luaopen_lua_extensions(lua_State *L)
{
    // load extensions
    luaL_Reg* lib = luax_exts;
    lua_getglobal(L, "package");
    lua_getfield(L, -1, "preload");
    for (; lib->func; lib++)
    {
        lua_pushcfunction(L, lib->func);
        lua_setfield(L, -2, lib->name);
    }
    lua_pop(L, 2);
}

#if __cplusplus
} // extern "C"
#endif

c++ leak

dmalloc_debug_setup("log-stats,log-non-free,check-fence,log=logfile");

dmalloc_log_stats();
dmalloc_log_unfreed();
  1. gdb txos pid -batch -x "gdb cmd file"

参考资料

valgrind --leak-check=yes --show-reachable=yes --tool=memcheck --num-callers=30 your_prog_and_arg

GC

others