mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
add debug command inject
This commit is contained in:
@@ -11,6 +11,7 @@ Dev version
|
|||||||
* add skynet.harbor.queryname to query globalname
|
* add skynet.harbor.queryname to query globalname
|
||||||
* add cluster.proxy
|
* add cluster.proxy
|
||||||
* add DEBUG command exit (send a message to lua service by DEBUG)
|
* add DEBUG command exit (send a message to lua service by DEBUG)
|
||||||
|
* add DEBUG command run (debug_console command inject)
|
||||||
|
|
||||||
v0.5.2 (2014-8-11)
|
v0.5.2 (2014-8-11)
|
||||||
-----------
|
-----------
|
||||||
|
|||||||
@@ -701,6 +701,6 @@ end
|
|||||||
|
|
||||||
-- Inject internal debug framework
|
-- Inject internal debug framework
|
||||||
local debug = require "skynet.debug"
|
local debug = require "skynet.debug"
|
||||||
debug(skynet)
|
debug(skynet, dispatch_message)
|
||||||
|
|
||||||
return skynet
|
return skynet
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
return function (skynet)
|
local io = io
|
||||||
|
local table = table
|
||||||
|
local debug = debug
|
||||||
|
|
||||||
|
return function (skynet, dispatch_func)
|
||||||
|
|
||||||
local internal_info_func
|
local internal_info_func
|
||||||
|
|
||||||
@@ -43,6 +47,62 @@ function dbgcmd.EXIT()
|
|||||||
skynet.exit()
|
skynet.exit()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function getupvaluetable(u, func, unique)
|
||||||
|
i = 1
|
||||||
|
while true do
|
||||||
|
local name, value = debug.getupvalue(func, i)
|
||||||
|
if name == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local t = type(value)
|
||||||
|
if t == "table" then
|
||||||
|
u[name] = value
|
||||||
|
elseif t == "function" then
|
||||||
|
if not unique[value] then
|
||||||
|
unique[value] = true
|
||||||
|
getupvaluetable(u, value, unique)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
i=i+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function dbgcmd.RUN(source, filename)
|
||||||
|
if filename then
|
||||||
|
filename = "@" .. filename
|
||||||
|
else
|
||||||
|
filename = "=(load)"
|
||||||
|
end
|
||||||
|
local output = {}
|
||||||
|
do
|
||||||
|
local function print(...)
|
||||||
|
local value = { ... }
|
||||||
|
for k,v in ipairs(value) do
|
||||||
|
value[k] = tostring(v)
|
||||||
|
end
|
||||||
|
table.insert(output, table.concat(value, "\t"))
|
||||||
|
end
|
||||||
|
local u = {}
|
||||||
|
local unique = {}
|
||||||
|
getupvaluetable(u, dispatch_func, unique)
|
||||||
|
getupvaluetable(u, skynet.register_protocol, unique)
|
||||||
|
local env = setmetatable( { print = print , _U = u }, { __index = _ENV })
|
||||||
|
local func, err = load(source, filename, "bt", env)
|
||||||
|
if not func then
|
||||||
|
skynet.ret(skynet.pack(err))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ok, err = pcall(func)
|
||||||
|
if not ok then
|
||||||
|
table.insert(output, err)
|
||||||
|
end
|
||||||
|
|
||||||
|
source, filename = nil
|
||||||
|
end
|
||||||
|
collectgarbage "collect"
|
||||||
|
skynet.ret(skynet.pack(table.concat(output, "\n")))
|
||||||
|
end
|
||||||
|
|
||||||
local function _debug_dispatch(session, address, cmd, ...)
|
local function _debug_dispatch(session, address, cmd, ...)
|
||||||
local f = dbgcmd[cmd]
|
local f = dbgcmd[cmd]
|
||||||
assert(f, cmd)
|
assert(f, cmd)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ local function dump_list(print, list)
|
|||||||
for _,v in ipairs(index) do
|
for _,v in ipairs(index) do
|
||||||
dump_line(print, v, list[v])
|
dump_line(print, v, list[v])
|
||||||
end
|
end
|
||||||
|
print("OK")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function split_cmdline(cmdline)
|
local function split_cmdline(cmdline)
|
||||||
@@ -92,6 +93,9 @@ skynet.start(function()
|
|||||||
socket.start(listen_socket , function(id, addr)
|
socket.start(listen_socket , function(id, addr)
|
||||||
local function print(...)
|
local function print(...)
|
||||||
local t = { ... }
|
local t = { ... }
|
||||||
|
for k,v in ipairs(t) do
|
||||||
|
t[k] = tostring(v)
|
||||||
|
end
|
||||||
socket.write(id, table.concat(t,"\t"))
|
socket.write(id, table.concat(t,"\t"))
|
||||||
socket.write(id, "\n")
|
socket.write(id, "\n")
|
||||||
end
|
end
|
||||||
@@ -115,6 +119,7 @@ function COMMAND.help()
|
|||||||
clearcache = "clear lua code cache",
|
clearcache = "clear lua code cache",
|
||||||
service = "List unique service",
|
service = "List unique service",
|
||||||
task = "task address : show service task detail",
|
task = "task address : show service task detail",
|
||||||
|
inject = "inject address luascript.lua",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -144,3 +149,35 @@ end
|
|||||||
function COMMAND.service()
|
function COMMAND.service()
|
||||||
return skynet.call("SERVICE", "lua", "LIST")
|
return skynet.call("SERVICE", "lua", "LIST")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function adjust_address(address)
|
||||||
|
if address:sub(1,1) ~= ":" then
|
||||||
|
address = bit32.replace( tonumber("0x" .. address), skynet.harbor(skynet.self()), 24, 8)
|
||||||
|
end
|
||||||
|
return address
|
||||||
|
end
|
||||||
|
|
||||||
|
function COMMAND.exit(address)
|
||||||
|
skynet.send(adjust_address(address), "debug", "EXIT")
|
||||||
|
end
|
||||||
|
|
||||||
|
function COMMAND.inject(address, filename)
|
||||||
|
address = adjust_address(address)
|
||||||
|
local f = io.open(filename, "rb")
|
||||||
|
if not f then
|
||||||
|
return "Can't open " .. filename
|
||||||
|
end
|
||||||
|
local source = f:read "*a"
|
||||||
|
f:close()
|
||||||
|
return skynet.call(address, "debug", "RUN", source, filename)
|
||||||
|
end
|
||||||
|
|
||||||
|
function COMMAND.task(address)
|
||||||
|
address = adjust_address(address)
|
||||||
|
return skynet.call(address,"debug","TASK")
|
||||||
|
end
|
||||||
|
|
||||||
|
function COMMAND.info(address)
|
||||||
|
address = adjust_address(address)
|
||||||
|
return skynet.call(address,"debug","INFO")
|
||||||
|
end
|
||||||
|
|||||||
@@ -28,26 +28,6 @@ function command.STAT()
|
|||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
function command.INFO(_, handle)
|
|
||||||
handle = handle_to_address(handle)
|
|
||||||
if services[handle] == nil then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
local result = skynet.call(handle,"debug","INFO")
|
|
||||||
return result
|
|
||||||
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)
|
function command.KILL(_, handle)
|
||||||
handle = handle_to_address(handle)
|
handle = handle_to_address(handle)
|
||||||
skynet.kill(handle)
|
skynet.kill(handle)
|
||||||
@@ -56,11 +36,6 @@ function command.KILL(_, handle)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
function command.EXIT(_, handle)
|
|
||||||
handle = handle_to_address(handle)
|
|
||||||
skynet.send(handle, "debug", "EXIT")
|
|
||||||
end
|
|
||||||
|
|
||||||
function command.MEM()
|
function command.MEM()
|
||||||
local list = {}
|
local list = {}
|
||||||
for k,v in pairs(services) do
|
for k,v in pairs(services) do
|
||||||
|
|||||||
Reference in New Issue
Block a user