Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加snapshot内存快照debug指令 #848

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

spin6lock
Copy link
Contributor

通过内存快照对比,可以找出可能存在的内存泄漏,详见云风的博客。一般是通过mem和cmem指令找出内存占用异常的服务,然后对服务的可疑接口调用前打一次snapshot,调用后打一次snapshot,比较diff看看残留的内存对象是否正常。

lua-snapshot.c 来源于云风的lua-snapshot,新添加了类型输出。前后两次内存快照对比出来的diff,会尝试用来组成树以方便阅读,深度限制同lua-seri,方便传送到其他服务。

组成树(森林)的大致过程:先将没有任何引用的叶节点放入a,然后将叶节点的上一层节点放入a,对应叶节点移出a。然后循环,直到所有被引用的节点都在数组为止。a_set和b_set相互倒来倒去是希望尽可能少的发生内存分配

@@ -88,6 +88,27 @@ local function init(skynet, export)
skynet.ret()
end

local old_snapshot
local snapshot = require "snapshot"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个 require 放在下面 function dbgcmd.SNAPSHOT() 内部更好。这样不使用的时候就不会占内存。(少一个 table)

@uvtong
Copy link

uvtong commented Jul 23, 2018

赞,好东西啊。。

@xjdrew
Copy link
Contributor

xjdrew commented May 6, 2019

把snapshot_utils提交给https://github.com/cloudwu/lua-snapshot ,实现代码没必要放在skynet里面。然后skynet以3rd的方式引用这个库。简单加个gm指令启用就好了。 @cloudwu

@cloudwu cloudwu force-pushed the master branch 2 times, most recently from 31e0ac2 to 208be03 Compare December 10, 2021 12:56
@hanxi
Copy link
Contributor

hanxi commented Mar 8, 2022

使用 RUN 命令按需注册 dbgcmd 的例子

https://github.com/hanxi/skynet-demo#%E9%9B%86%E6%88%90-lua-snapshot-%E5%B7%A5%E5%85%B7%E6%9F%A5%E7%9C%8B-lua-%E5%86%85%E5%AD%98%E6%95%B0%E6%8D%AE%E5%8F%98%E5%8C%96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants