diff --git a/.gitmodules b/.gitmodules index 4d6e3fdcb..c9e57a63f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "3rd/jemalloc"] path = 3rd/jemalloc url = https://github.com/jemalloc/jemalloc.git +[submodule "3rd/lua-snapshot"] + path = 3rd/lua-snapshot + url = https://github.com/cloudwu/lua-snapshot.git diff --git a/3rd/lua-snapshot b/3rd/lua-snapshot new file mode 160000 index 000000000..5fdc88aaa --- /dev/null +++ b/3rd/lua-snapshot @@ -0,0 +1 @@ +Subproject commit 5fdc88aaa5335b3e7137f1ed01d76517f3d129c9 diff --git a/Makefile b/Makefile index 4f8b17a78..81e46de69 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,7 @@ LUA_CLIB_SKYNET = \ lua-mysqlaux.c \ lua-debugchannel.c \ lua-datasheet.c \ + lua-snapshot.c \ \ SKYNET_SRC = skynet_main.c skynet_handle.c skynet_module.c skynet_mq.c \ diff --git a/lualib/skynet/debug.lua b/lualib/skynet/debug.lua index 802548ee7..6838f3204 100644 --- a/lualib/skynet/debug.lua +++ b/lualib/skynet/debug.lua @@ -88,6 +88,27 @@ local function init(skynet, export) skynet.ret() end + local old_snapshot + function dbgcmd.SNAPSHOT() + local snapshot = require "snapshot" + local construct_indentation = (require "skynet.snapshot_utils").construct_indentation + collectgarbage "collect" + local new_snapshot = snapshot() + if not old_snapshot then + old_snapshot = new_snapshot + return skynet.ret(skynet.pack({})) + end + local diff = {} + for k,v in pairs(new_snapshot) do + if not old_snapshot[k] then + diff[k] = v + end + end + old_snapshot = new_snapshot + local ret = construct_indentation(diff) + skynet.ret(skynet.pack(ret)) + end + return dbgcmd end -- function init_dbgcmd