malloc hook for jemalloc and c memory info dump

This commit is contained in:
Cloud Wu
2014-04-18 17:38:18 +08:00
parent 5b68dc6a17
commit ac1a0a4c99
8 changed files with 318 additions and 8 deletions

51
lualib-src/lua-memory.c Normal file
View File

@@ -0,0 +1,51 @@
#include <lua.h>
#include <lauxlib.h>
#include "malloc_hook.h"
static int
ltotal(lua_State *L) {
size_t t = malloc_used_memory();
lua_pushunsigned(L, t);
return 1;
}
static int
lblock(lua_State *L) {
size_t t = malloc_memory_block();
lua_pushunsigned(L, t);
return 1;
}
static int
ldumpinfo(lua_State *L) {
memory_info_dump();
return 0;
}
static int
ldump(lua_State *L) {
dump_c_mem();
return 0;
}
int
luaopen_memory(lua_State *L) {
luaL_checkversion(L);
luaL_Reg l[] = {
{ "total", ltotal },
{ "block", lblock },
{ "dumpinfo", ldumpinfo },
{ "dump", ldump },
{ NULL, NULL },
};
luaL_newlib(L,l);
return 1;
}