skynet-debug console指令集整理
在skynet中,nc调试台是一个用于在运行中的skynet服务和调试器之间建立交互的工具。通过命令行与运行在skynet环境中的服务进行交互和调试,
PS: 这里的nc调试台和linux系统中的netcat工具是不同的概念
进入调试台
nc 127.0.0.1 设置的debug端口
Welcome to skynet console
help
作用:查看nc命令集
示例:
call call address ...
clearcache clear lua code cache
cmem Show C memory info
dbgcmd run address debug command
debug debug address : debug a lua service
dumpheap dumpheap : dump heap profilling
exit exit address : kill a lua service
gc gc : force every lua service do garbage collect
help This help message
info info address : get service infomation
inject inject address luascript.lua
jmem Show jemalloc mem stats
kill kill address : kill service
killtask killtask address threadname : threadname listed by task
list List all the service
log launch a new lua service with log
logoff logoff address
logon logon address
mem mem : show memory status
netstat netstat : show netstat
ping ping address
profactive profactive [on|off] : active/deactive jemalloc heap profilling
service List unique service
signal signal address sig
snax lanuch a new snax service
start lanuch a new lua service
stat Dump all stats
task task address : show service task detail
trace trace address [proto] [on|off]
uniqtask task address : show service unique task detail
针对所有skynet服务的常用指令
list
作用:列出所有服务地址,已经对应的服务启动参数
示例:
:00000004 snlua cdummy
:00000006 snlua datacenterd
:00000007 snlua service_mgr
:00000009 snlua clusterd
:0000000a snlua gate
:0000000b snlua base constloader 1 constloader
:0000000c snlua service_provider
:0000000d snlua service_cell sharetable
:0000000e snlua logd
:0000000f snlua base dbproxy 1 dbproxy
mem
作用:列出所有lua服务当前自己占用的内存
示例:
:00000004 64.12 Kb (snlua cdummy)
:00000006 62.28 Kb (snlua datacenterd)
:00000007 73.36 Kb (snlua service_mgr)
:00000009 66.46 Kb (snlua clusterd)
:0000000a 70.83 Kb (snlua gate)
:0000000b 2486.26 Kb (snlua base constloader 1 constloader)
:0000000c 68.18 Kb (snlua service_provider)
:0000000d 526.96 Kb (snlua service_cell sharetable)
:0000000e 82.35 Kb (snlua logd)
:0000000f 275.37 Kb (snlua base dbproxy 1 dbproxy)
cmem
作用: 列出所有c服务当前自己占用的内存(单位字节)
示例:
:00000001 352
:00000002 335568
:00000003 1148824
:00000004 75040
:00000005 96
:00000006 15360
:00000007 75696
:00000008 139456
:00000009 34280
jmem
作用:jemalloc是一个用户空间的内存分配器,用于替代C标准库中的malloc和free等函数。jmem命令用于显示jemalloc分配器的内存分配和使用的详细信息,可以更深入地了解系统的内存分配情况,帮助进行性能优化、内存调试和问题排查
- stats.active: 表示当前活动的内存大小,即正在使用的内存大小
- stats.allocated: 表示已经分配的内存大小
- stats.mapped: 表示映射到内存的文件或设备的大小
- stats.resident: 表示当前驻留在物理内存中的内存大小
- stats.retained: 表示由应用程序保留的内存大小,即应用程序当前正在使用但尚未释放的内存
示例:
stats.active 337596416 321.96 Mb
stats.allocated 313798808 299.26 Mb
stats.mapped 362762240 345.96 Mb
stats.resident 345567232 329.56 Mb
stats.retained 27308032 26.04 Mb
stat
作用:用于查看当前服务的状态信息。可以显示服务的一些关键指标和统计数据
- cpu:显示服务的CPU时间
- message:显示服务处理的消息数量(包括已处理的消息数量、消息丢失数量)
- mqlen:消息队列中正在等待处理的消息数量
- task:表示当前活动的任务数。任务可以是异步操作、定时器任务等
示例:
:00000004 cpu:0.000553 message:6 mqlen:0 task:0
:00000006 cpu:0.0004 message:4 mqlen:0 task:0
:00000007 cpu:0.006321 message:871 mqlen:0 task:0
:00000009 cpu:0.000552 message:8 mqlen:0 task:0
:0000000a cpu:0.00074 message:7 mqlen:0 task:0
:0000000b cpu:0.193445 message:2357 mqlen:0 task:0
:0000000c cpu:0.00257 message:461 mqlen:0 task:0
:0000000d cpu:0.793029 message:27580 mqlen:0 task:0
:0000000e cpu:0.710588 message:11329 mqlen:0 task:1
:0000000f cpu:0.708292 message:3985 mqlen:0 task:7
service
作用:列出skynet中所有的唯一服务
示例:
base :0000000b
clusterd :00000009
debug_console :00000224
logd :0000000e
service_provider :0000000c
netstat
作用:用于监控节点的网络连接状态,可以展示每个连接的读写情况、连接的时间等信息
- id: 连接的ID,用于标识每个连接
- address: 连接的本地地址
- peer: 连接的远程地址
- read: 从连接接收到的数据量
- reading: 表示是否正在读取数据
- rtime: 表示从开始读取到现在的时间
- type: 连接的类型,(当前是TCP)
- write: 发送到连接的数据量
- writing: 表示是否正在写入数据
- wtime: 表示从开始写入到现在的时间
示例:
1 address::00000224 id:47 peer:127.0.0.1:39941 read:73 reading:true rtime:0.02s type:TCP write:106.8408203125K writing:false wtime:2:22s
10 address::00000014 id:37 peer:127.0.0.1:6381 read:6.2900390625K reading:true rtime:1:45s type:TCP write:6.923828125K writing:false wtime:1:45s
11 address::00000013 id:36 peer:127.0.0.1:27017 read:1.7763671875K reading:true rtime:16:21:33s type:TCP write:1.7138671875K writing:false wtime:16:21:37s
12 address::00000013 id:35 peer:127.0.0.1:27017 read:627 reading:true rtime:16:21:47s type:TCP write:513 writing:false wtime:16:21:47s
13 address::00000013 id:34 peer:127.0.0.1:27017 read:627 reading:true rtime:16:21:47s type:TCP write:513 writing:false wtime:16:21:47s
14 address::00000013 id:33 peer:127.0.0.1:27017 read:847 reading:true rtime:10:12:7.9s type:TCP write:943 writing:false wtime:10:12:7.9s
15 address::00000013 id:32 peer:127.0.0.1:27017 read:627 reading:true rtime:16:21:47s type:TCP write:513 writing:false wtime:16:21:47s
gc
作用:强制让所有服务都执行一次垃圾回收,并汇报回收后的内存
示例:
:00000004 64.86 Kb (snlua cdummy)
:00000006 63.44 Kb (snlua datacenterd)
:00000007 70.10 Kb (snlua service_mgr)
:00000009 66.91 Kb (snlua clusterd)
:0000000a 69.47 Kb (snlua gate)
:0000000b 330.80 Kb (snlua base constloader 1 constloader)
:0000000c 64.82 Kb (snlua service_provider)
:0000000d 490.66 Kb (snlua service_cell sharetable)
:0000000e 72.05 Kb (snlua logd)
:0000000f 220.21 Kb (snlua base dbproxy 1 dbproxy)
针对单个skynet服务的常用指令
info address
作用:获取指定服务的内部信息
示例:info 0000000d //sharetable服务
...
vip.C2S_GET_INFO current:userdata: 0x7fbc67881600 size:21142
vip.S2C_RIGHT_CHANGE current:userdata: 0x7fbc67891f40 size:21142
vip.S2C_GET_FREEEVERYDAY_AWARD current:userdata: 0x7fbc678aa780 size:21142
vip.S2C_GET_INFO current:userdata: 0x7fbc6788aac0 history:userdata: 0x7fbc6788aac0 [21142]: (:00000039) size:21142
vip.VipRight current:userdata: 0x7fbc67bab0c0 size:21142
...
kill address
作用:kill指定服务
示例:kill 00000223
:00000223 snlua base race 13 race
exit address
作用:退出指定服务
示例:kill 00000222
#执行上述2条命令后的服务状态:
:00000220 snlua base race 10 race
:00000221 snlua base race 11 race
:00000224 snlua debug_console 7040
call address
作用:调用指定服务的lua类型接口,格式为:call address “foo”,arg1,… (接口名和string类型参数需加引号,且以逗号隔开,address也可以替换为服务名)
示例:参考GM列表大全
debug address
作用:针对指定服务的单步调试器
示例:参考http://blog.codingnow.com/2015/02/skynet_debugger.html
task address
作用:显示指定服务中被挂起的请求的调用栈
示例:
thread: 0x7fbc6499ec28 session: 61 stack traceback:
[C]: in function 'coroutine.yield'
/workshop/home/XXX/lua/skynet/lualib/skynet.lua:494: in upvalue 'suspend_sleep'
/workshop/home/XXX/lua/skynet/lualib/skynet.lua:520: in function 'skynet.manager.wait'
/workshop/home/XXX/lua/skynet/lualib/skynet/socket.lua:53: in upvalue 'suspend'
/workshop/home/XXX/lua/skynet/lualib/skynet/socket.lua:339: in function 'socket.read'
...op/home/XXX/lua/skynet/lualib/skynet/socketchannel.lua:558: in method 'read'
/workshop/home/XXX/lua/skynet/lualib/skynet/db/mongo.lua:77: in function </workshop/home/XXX/lua/skynet/lualib/skynet/db/mongo.lua:76>
[C]: in function 'pcall'
...op/home/XXX/lua/skynet/lualib/skynet/socketchannel.lua:96: in function <...op/home/XXX/lua/skynet/lualib/skynet/socketchannel.lua:92>
[C]: in function 'pcall'
...op/home/XXX/lua/skynet/lualib/skynet/socketchannel.lua:336: in upvalue 'f'
/workshop/home/XXX/lua/skynet/lualib/skynet.lua:384: in function </workshop/home/XXX/lua/skynet/lualib/skynet.lua:356>
inject address luascript.lua
作用:将指定script名字的脚本文件插入到指定服务中运行(通用用于热更补丁)