mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 19:43:09 +00:00
dbg for debug
This commit is contained in:
@@ -15,10 +15,7 @@ local function split_package()
|
||||
while true do
|
||||
local cmd = readline "\n"
|
||||
if cmd ~= "" then
|
||||
local handle = skynet.launch("snlua", cmd)
|
||||
if handle == nil then
|
||||
print("Launch error:",cmd)
|
||||
end
|
||||
skynet.send(skynet.self(), "text", cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -39,5 +36,11 @@ skynet.register_protocol {
|
||||
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("text", function (session, address, cmd)
|
||||
local handle = skynet.newservice(cmd)
|
||||
if handle == nil then
|
||||
print("Launch error:",cmd)
|
||||
end
|
||||
end)
|
||||
socket.stdin()
|
||||
end)
|
||||
|
||||
11
service/dbg.lua
Normal file
11
service/dbg.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
local cmd = { ... }
|
||||
|
||||
skynet.start(function()
|
||||
local list = skynet.call(".launcher","lua", unpack(cmd))
|
||||
for k,v in pairs(list) do
|
||||
print(k,v)
|
||||
end
|
||||
skynet.exit()
|
||||
end)
|
||||
@@ -1,13 +1,51 @@
|
||||
local skynet = require "skynet"
|
||||
local string = string
|
||||
|
||||
local services = {}
|
||||
|
||||
local command = {}
|
||||
|
||||
function command.LIST()
|
||||
local list = {}
|
||||
for k,v in pairs(services) do
|
||||
list[skynet.address(k)] = v
|
||||
end
|
||||
skynet.ret(skynet.pack(list))
|
||||
end
|
||||
|
||||
function command.KILL(handle)
|
||||
skynet.kill(handle)
|
||||
skynet.ret( skynet.pack({ [handle] = tostring(services[handle]) }))
|
||||
services[handle] = nil
|
||||
end
|
||||
|
||||
function command.MEM()
|
||||
local list = {}
|
||||
for k,v in pairs(services) do
|
||||
local kb, bytes = skynet.call(k,"debug","MEM")
|
||||
list[skynet.address(k)] = string.format("%d Kb (%s)",kb,v)
|
||||
end
|
||||
skynet.ret(skynet.pack(list))
|
||||
end
|
||||
|
||||
function command.GC()
|
||||
for k,v in pairs(services) do
|
||||
skynet.send(k,"debug","GC")
|
||||
end
|
||||
command.MEM()
|
||||
end
|
||||
|
||||
function command.REMOVE(handle)
|
||||
services[handle] = nil
|
||||
end
|
||||
|
||||
local instance = {}
|
||||
|
||||
skynet.register(".launcher")
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua" , function(session, address , service, ...)
|
||||
if service == nil then
|
||||
skynet.dispatch("text" , function(session, address , cmd)
|
||||
if cmd == "" then
|
||||
-- init notice
|
||||
local reply = instance[address]
|
||||
if reply then
|
||||
@@ -16,13 +54,18 @@ skynet.start(function()
|
||||
end
|
||||
else
|
||||
-- launch request
|
||||
local param = table.concat({...}, " ")
|
||||
local service, param = string.match(cmd,"([^ ]+) (.*)")
|
||||
local inst = skynet.launch(service, param)
|
||||
if inst then
|
||||
services[inst] = cmd
|
||||
instance[inst] = { session = session, address = address }
|
||||
else
|
||||
skynet.ret(skynet.pack(nil))
|
||||
end
|
||||
end
|
||||
end)
|
||||
skynet.dispatch("lua", function(session, address, cmd , ...)
|
||||
cmd = string.upper(cmd)
|
||||
command[cmd](...)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user