mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
Add jemalloc heap profilling in debug console
This commit is contained in:
@@ -49,6 +49,26 @@ lcurrent(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ldumpheap(lua_State *L) {
|
||||||
|
mallctl_cmd("prof.dump");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
lprofactive(lua_State *L) {
|
||||||
|
bool *pval, active;
|
||||||
|
if (lua_isnone(L, 1)) {
|
||||||
|
pval = NULL;
|
||||||
|
} else {
|
||||||
|
active = lua_toboolean(L, 1) ? true : false;
|
||||||
|
pval = &active;
|
||||||
|
}
|
||||||
|
bool ret = mallctl_bool("prof.active", pval);
|
||||||
|
lua_pushboolean(L, ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
LUAMOD_API int
|
LUAMOD_API int
|
||||||
luaopen_skynet_memory(lua_State *L) {
|
luaopen_skynet_memory(lua_State *L) {
|
||||||
luaL_checkversion(L);
|
luaL_checkversion(L);
|
||||||
@@ -62,6 +82,8 @@ luaopen_skynet_memory(lua_State *L) {
|
|||||||
{ "ssinfo", luaS_shrinfo },
|
{ "ssinfo", luaS_shrinfo },
|
||||||
{ "ssexpand", lexpandshrtbl },
|
{ "ssexpand", lexpandshrtbl },
|
||||||
{ "current", lcurrent },
|
{ "current", lcurrent },
|
||||||
|
{ "dumpheap", ldumpheap },
|
||||||
|
{ "profactive", lprofactive },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -160,6 +160,8 @@ function COMMAND.help()
|
|||||||
call = "call address ...",
|
call = "call address ...",
|
||||||
trace = "trace address [proto] [on|off]",
|
trace = "trace address [proto] [on|off]",
|
||||||
netstat = "netstat : show netstat",
|
netstat = "netstat : show netstat",
|
||||||
|
profactive = "profactive [on|off] : active/deactive jemalloc heap profilling",
|
||||||
|
dumpheap = "dumpheap : dump heap profilling",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -422,3 +424,18 @@ function COMMAND.netstat()
|
|||||||
end
|
end
|
||||||
return stat
|
return stat
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function COMMAND.dumpheap()
|
||||||
|
memory.dumpheap()
|
||||||
|
end
|
||||||
|
|
||||||
|
function COMMAND.profactive(flag)
|
||||||
|
if flag ~= nil then
|
||||||
|
if flag == "on" or flag == "off" then
|
||||||
|
flag = toboolean(flag)
|
||||||
|
end
|
||||||
|
memory.profactive(flag)
|
||||||
|
end
|
||||||
|
local active = memory.profactive()
|
||||||
|
return "heap profilling is ".. (active and "active" or "deactive")
|
||||||
|
end
|
||||||
|
|||||||
@@ -131,6 +131,23 @@ memory_info_dump(void) {
|
|||||||
je_malloc_stats_print(0,0,0);
|
je_malloc_stats_print(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
mallctl_bool(const char* name, bool* newval) {
|
||||||
|
bool v = 0;
|
||||||
|
size_t len = sizeof(v);
|
||||||
|
if(newval) {
|
||||||
|
je_mallctl(name, &v, &len, newval, sizeof(bool));
|
||||||
|
} else {
|
||||||
|
je_mallctl(name, &v, &len, NULL, 0);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mallctl_cmd(const char* name) {
|
||||||
|
return je_mallctl(name, NULL, NULL, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
mallctl_int64(const char* name, size_t* newval) {
|
mallctl_int64(const char* name, size_t* newval) {
|
||||||
size_t v = 0;
|
size_t v = 0;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define SKYNET_MALLOC_HOOK_H
|
#define SKYNET_MALLOC_HOOK_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
|
|
||||||
extern size_t malloc_used_memory(void);
|
extern size_t malloc_used_memory(void);
|
||||||
@@ -9,6 +10,8 @@ extern size_t malloc_memory_block(void);
|
|||||||
extern void memory_info_dump(void);
|
extern void memory_info_dump(void);
|
||||||
extern size_t mallctl_int64(const char* name, size_t* newval);
|
extern size_t mallctl_int64(const char* name, size_t* newval);
|
||||||
extern int mallctl_opt(const char* name, int* newval);
|
extern int mallctl_opt(const char* name, int* newval);
|
||||||
|
extern bool mallctl_bool(const char* name, bool* newval);
|
||||||
|
extern int mallctl_cmd(const char* name);
|
||||||
extern void dump_c_mem(void);
|
extern void dump_c_mem(void);
|
||||||
extern int dump_mem_lua(lua_State *L);
|
extern int dump_mem_lua(lua_State *L);
|
||||||
extern size_t malloc_current_memory(void);
|
extern size_t malloc_current_memory(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user