mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
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:
@@ -23,11 +23,42 @@ lblock(lua_State *L) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
ldumpinfo(lua_State *L) {
|
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;
|
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
|
static int
|
||||||
ldump(lua_State *L) {
|
ldump(lua_State *L) {
|
||||||
dump_c_mem();
|
dump_c_mem();
|
||||||
@@ -69,6 +100,8 @@ luaopen_skynet_memory(lua_State *L) {
|
|||||||
{ "total", ltotal },
|
{ "total", ltotal },
|
||||||
{ "block", lblock },
|
{ "block", lblock },
|
||||||
{ "dumpinfo", ldumpinfo },
|
{ "dumpinfo", ldumpinfo },
|
||||||
|
{ "jestat", ljestat },
|
||||||
|
{ "mallctl", lmallctl },
|
||||||
{ "dump", ldump },
|
{ "dump", ldump },
|
||||||
{ "info", dump_mem_lua },
|
{ "info", dump_mem_lua },
|
||||||
{ "current", lcurrent },
|
{ "current", lcurrent },
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ function COMMAND.help()
|
|||||||
debug = "debug address : debug a lua service",
|
debug = "debug address : debug a lua service",
|
||||||
signal = "signal address sig",
|
signal = "signal address sig",
|
||||||
cmem = "Show C memory info",
|
cmem = "Show C memory info",
|
||||||
|
jmem = "Show jemalloc mem stats",
|
||||||
ping = "ping address",
|
ping = "ping address",
|
||||||
call = "call address ...",
|
call = "call address ...",
|
||||||
trace = "trace address [proto] [on|off]",
|
trace = "trace address [proto] [on|off]",
|
||||||
@@ -342,6 +343,15 @@ function COMMAND.cmem()
|
|||||||
return tmp
|
return tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function COMMAND.jmem()
|
||||||
|
local info = memory.jestat()
|
||||||
|
local tmp = {}
|
||||||
|
for k,v in pairs(info) do
|
||||||
|
tmp[k] = string.format("%11d %8.2f Mb", v, v/1048576)
|
||||||
|
end
|
||||||
|
return tmp
|
||||||
|
end
|
||||||
|
|
||||||
function COMMAND.ping(address)
|
function COMMAND.ping(address)
|
||||||
address = adjust_address(address)
|
address = adjust_address(address)
|
||||||
local ti = skynet.now()
|
local ti = skynet.now()
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ static void malloc_oom(size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
memory_info_dump(void) {
|
memory_info_dump(const char* opts) {
|
||||||
je_malloc_stats_print(0,0,0);
|
je_malloc_stats_print(0,0, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -241,7 +241,7 @@ skynet_posix_memalign(void **memptr, size_t alignment, size_t size) {
|
|||||||
#define raw_free free
|
#define raw_free free
|
||||||
|
|
||||||
void
|
void
|
||||||
memory_info_dump(void) {
|
memory_info_dump(const char* opts) {
|
||||||
skynet_error(NULL, "No jemalloc");
|
skynet_error(NULL, "No jemalloc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
extern size_t malloc_used_memory(void);
|
extern size_t malloc_used_memory(void);
|
||||||
extern size_t malloc_memory_block(void);
|
extern size_t malloc_memory_block(void);
|
||||||
extern void memory_info_dump(void);
|
extern void memory_info_dump(const char *opts);
|
||||||
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 bool mallctl_bool(const char* name, bool* newval);
|
||||||
|
|||||||
Reference in New Issue
Block a user