mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
add new debug command trace
This commit is contained in:
@@ -136,8 +136,8 @@ local function co_create(f)
|
|||||||
end
|
end
|
||||||
-- coroutine exit
|
-- coroutine exit
|
||||||
local tag = session_coroutine_tracetag[co]
|
local tag = session_coroutine_tracetag[co]
|
||||||
if tag then
|
if tag ~= nil then
|
||||||
c.trace(tag, "end")
|
if tag then c.trace(tag, "end") end
|
||||||
session_coroutine_tracetag[co] = nil
|
session_coroutine_tracetag[co] = nil
|
||||||
end
|
end
|
||||||
local address = session_coroutine_address[co]
|
local address = session_coroutine_address[co]
|
||||||
@@ -271,6 +271,11 @@ skynet.hpc = c.hpc -- high performance counter
|
|||||||
|
|
||||||
local traceid = 0
|
local traceid = 0
|
||||||
function skynet.trace(info)
|
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
|
traceid = traceid + 1
|
||||||
|
|
||||||
local tag = string.format(":%08x-%d",skynet.self(), traceid)
|
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_id[co] = session
|
||||||
session_coroutine_address[co] = source
|
session_coroutine_address[co] = source
|
||||||
local traceflag = p.trace
|
local traceflag = p.trace
|
||||||
local tag = trace_source[source]
|
if traceflag == false then
|
||||||
if tag then
|
-- force off
|
||||||
trace_source[source] = nil
|
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")
|
c.trace(tag, "request")
|
||||||
session_coroutine_tracetag[co] = tag
|
session_coroutine_tracetag[co] = tag
|
||||||
|
elseif traceflag then
|
||||||
|
-- set running_thread for trace
|
||||||
|
running_thread = co
|
||||||
|
skynet.trace()
|
||||||
end
|
end
|
||||||
elseif traceflag then
|
|
||||||
skynet.trace()
|
|
||||||
end
|
end
|
||||||
suspend(co, coroutine_resume(co, session,source, p.unpack(msg,sz)))
|
suspend(co, coroutine_resume(co, session,source, p.unpack(msg,sz)))
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -78,6 +78,16 @@ local function init(skynet, export)
|
|||||||
skynet.response() -- get response , but not return. raise error when exit
|
skynet.response() -- get response , but not return. raise error when exit
|
||||||
end
|
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
|
return dbgcmd
|
||||||
end -- function init_dbgcmd
|
end -- function init_dbgcmd
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ function COMMAND.help()
|
|||||||
shrtbl = "Show shared short string table info",
|
shrtbl = "Show shared short string table info",
|
||||||
ping = "ping address",
|
ping = "ping address",
|
||||||
call = "call address ...",
|
call = "call address ...",
|
||||||
|
trace = "trace address [proto] [on|off]",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -343,6 +344,22 @@ function COMMAND.ping(address)
|
|||||||
return tostring(ti)
|
return tostring(ti)
|
||||||
end
|
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)
|
function COMMANDX.call(cmd)
|
||||||
local address = adjust_address(cmd[2])
|
local address = adjust_address(cmd[2])
|
||||||
local cmdline = assert(cmd[1]:match("%S+%s+%S+%s(.+)") , "need arguments")
|
local cmdline = assert(cmd[1]:match("%S+%s+%S+%s(.+)") , "need arguments")
|
||||||
|
|||||||
Reference in New Issue
Block a user