timing remote call

This commit is contained in:
云风
2014-02-23 17:13:58 +08:00
parent 5944668796
commit c1e6737711
7 changed files with 331 additions and 5 deletions

View File

@@ -46,6 +46,9 @@ local watching_service = {}
local watching_session = {}
local error_queue = {}
-- timing remote call, turn off by default. Use skynet.timing_call() to turn on.
local timing_call = nil
-- suspend is function
local suspend
@@ -384,9 +387,23 @@ function skynet.fork(func,...)
table.insert(fork_queue, co)
end
local function raw_dispatch_message(prototype, msg, sz, session, source, ...)
local function timing(session, source, ti)
local t = timing_call[source]
if t == nil then
t = { n = 1, ti = 0 }
timing_call[source] = t
else
t.n = t.n + 1
end
t.ti = t.ti + ti
end
local function raw_dispatch_message(prototype, msg, sz, session, source, ti)
-- skynet.PTYPE_RESPONSE = 1, read skynet.h
if prototype == 1 then
if ti and timing_call then
timing(session, source, ti)
end
local co = session_id_coroutine[session]
if co == "BREAK" then
session_id_coroutine[session] = nil
@@ -404,7 +421,7 @@ local function raw_dispatch_message(prototype, msg, sz, session, source, ...)
local co = co_create(f)
session_coroutine_id[co] = session
session_coroutine_address[co] = source
suspend(co, coroutine.resume(co, session,source, p.unpack(msg,sz, ...)))
suspend(co, coroutine.resume(co, session,source, p.unpack(msg,sz)))
else
print("Unknown request :" , p.unpack(msg,sz))
error(string.format("Can't dispatch type %s : ", p.name))
@@ -538,6 +555,17 @@ function dbgcmd.INFO()
end
end
function dbgcmd.TIMING()
if timing_call then
skynet.ret(skynet.pack(timing_call))
-- turn off timing
timing_call = nil
else
-- turn on timing
timing_call = {}
end
end
function dbgcmd.RELOAD(...)
local cmd = table.concat({...}, " ")
c.reload(cmd)
@@ -697,4 +725,12 @@ function skynet.mqlen()
return tonumber(c.command "MQLEN")
end
function skynet.timing_call()
timing_call = {}
end
function skynet.timing_session(session)
return c.timing(session)
end
return skynet