diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 7719d2ae..7e5115cb 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -583,6 +583,17 @@ function skynet.mqlen() return tonumber(c.command "MQLEN") end +function skynet.task(f) + local t = 0 + for _,co in pairs(session_id_coroutine) do + if f then + f(debug.traceback(co)) + end + t = t + 1 + end + return t +end + -- Inject internal debug framework local debug = require "skynet.debug" debug(skynet) diff --git a/lualib/skynet/debug.lua b/lualib/skynet/debug.lua index 807ee2ae..bb5877fe 100644 --- a/lualib/skynet/debug.lua +++ b/lualib/skynet/debug.lua @@ -21,9 +21,16 @@ end function dbgcmd.STAT() local stat = {} stat.mqlen = skynet.mqlen() + stat.task = skynet.task() skynet.ret(skynet.pack(stat)) end +function dbgcmd.TASK() + local task = {} + skynet.task(function(info) table.insert(task, info) end) + skynet.ret(skynet.pack(task)) +end + function dbgcmd.INFO() if internal_info_func then skynet.ret(skynet.pack(internal_info_func())) diff --git a/service/debug_console.lua b/service/debug_console.lua index b15c3889..a587f69d 100644 --- a/service/debug_console.lua +++ b/service/debug_console.lua @@ -113,6 +113,7 @@ function COMMAND.help() snax = "lanuch a new snax service", clearcache = "clear lua code cache", service = "List unique service", + task = "task address : show service task detail", } end diff --git a/service/launcher.lua b/service/launcher.lua index b80eadc9..5c1c1a8b 100644 --- a/service/launcher.lua +++ b/service/launcher.lua @@ -38,6 +38,16 @@ function command.INFO(_, _, handle) end end +function command.TASK(_, _, handle) + handle = handle_to_address(handle) + if services[handle] == nil then + return + else + local result = skynet.call(handle,"debug","TASK") + return result + end +end + function command.KILL(_, _, handle) handle = handle_to_address(handle) skynet.kill(handle)