stat: add mem stat for jemalloc (#1218)

1, add opts arg for mallctl,dumpinfo
2, collect jemalloc.mem info
3, add debug_console cmd: jmem

Co-authored-by: fx <fx@f.x>
This commit is contained in:
fanlix
2020-07-22 19:26:39 +08:00
committed by GitHub
parent 693176efc8
commit f2b1bd7319
4 changed files with 48 additions and 5 deletions

View File

@@ -23,11 +23,42 @@ lblock(lua_State *L) {
static int
ldumpinfo(lua_State *L) {
memory_info_dump();
const char *opts = NULL;
if (lua_isstring(L, 1)) {
opts = luaL_checkstring(L,1);
}
memory_info_dump(opts);
return 0;
}
static int
ljestat(lua_State *L) {
static const char* names[] = {
"stats.allocated",
"stats.resident",
"stats.retained",
"stats.mapped",
"stats.active" };
static size_t flush = 1;
mallctl_int64("epoch", &flush); // refresh je.stats.cache
lua_newtable(L);
int i;
for (i = 0; i < (sizeof(names)/sizeof(names[0])); i++) {
lua_pushstring(L, names[i]);
lua_pushinteger(L, (lua_Integer) mallctl_int64(names[i], NULL));
lua_settable(L, -3);
}
return 1;
}
static int
lmallctl(lua_State *L) {
const char *name = luaL_checkstring(L,1);
lua_pushinteger(L, (lua_Integer) mallctl_int64(name, NULL));
return 1;
}
static int
ldump(lua_State *L) {
dump_c_mem();
@@ -69,6 +100,8 @@ luaopen_skynet_memory(lua_State *L) {
{ "total", ltotal },
{ "block", lblock },
{ "dumpinfo", ldumpinfo },
{ "jestat", ljestat },
{ "mallctl", lmallctl },
{ "dump", ldump },
{ "info", dump_mem_lua },
{ "current", lcurrent },