add new debug command trace

This commit is contained in:
Cloud Wu
2018-06-08 11:24:27 +08:00
parent 4b5fbab129
commit 3a1556e1fd
3 changed files with 45 additions and 7 deletions

View File

@@ -136,8 +136,8 @@ local function co_create(f)
end
-- coroutine exit
local tag = session_coroutine_tracetag[co]
if tag then
c.trace(tag, "end")
if tag ~= nil then
if tag then c.trace(tag, "end") end
session_coroutine_tracetag[co] = nil
end
local address = session_coroutine_address[co]
@@ -271,6 +271,11 @@ skynet.hpc = c.hpc -- high performance counter
local traceid = 0
function skynet.trace(info)
skynet.error("TRACE", session_coroutine_tracetag[running_thread])
if session_coroutine_tracetag[running_thread] == false then
-- force off trace log
return
end
traceid = traceid + 1
local tag = string.format(":%08x-%d",skynet.self(), traceid)
@@ -584,15 +589,21 @@ local function raw_dispatch_message(prototype, msg, sz, session, source)
session_coroutine_id[co] = session
session_coroutine_address[co] = source
local traceflag = p.trace
local tag = trace_source[source]
if tag then
if traceflag == false then
-- force off
trace_source[source] = nil
if traceflag ~= false then
session_coroutine_tracetag[co] = false
else
local tag = trace_source[source]
if tag then
trace_source[source] = nil
c.trace(tag, "request")
session_coroutine_tracetag[co] = tag
elseif traceflag then
-- set running_thread for trace
running_thread = co
skynet.trace()
end
elseif traceflag then
skynet.trace()
end
suspend(co, coroutine_resume(co, session,source, p.unpack(msg,sz)))
else

View File

@@ -78,6 +78,16 @@ local function init(skynet, export)
skynet.response() -- get response , but not return. raise error when exit
end
function dbgcmd.TRACELOG(proto, flag)
if type(proto) ~= "string" then
flag = proto
proto = "lua"
end
skynet.error(string.format("Turn trace log %s for %s", flag, proto))
skynet.traceproto(proto, flag)
skynet.ret()
end
return dbgcmd
end -- function init_dbgcmd

View File

@@ -158,6 +158,7 @@ function COMMAND.help()
shrtbl = "Show shared short string table info",
ping = "ping address",
call = "call address ...",
trace = "trace address [proto] [on|off]",
}
end
@@ -343,6 +344,22 @@ function COMMAND.ping(address)
return tostring(ti)
end
local function toboolean(x)
return x and (x == "true" or x == "on")
end
function COMMAND.trace(address, proto, flag)
address = adjust_address(address)
if flag == nil then
if proto == "on" or proto == "off" then
proto = toboolean(proto)
end
else
flag = toboolean(flag)
end
skynet.call(address, "debug", "TRACELOG", proto, flag)
end
function COMMANDX.call(cmd)
local address = adjust_address(cmd[2])
local cmdline = assert(cmd[1]:match("%S+%s+%S+%s(.+)") , "need arguments")