mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
trace bugfix
This commit is contained in:
@@ -407,11 +407,18 @@ lhpc(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_LEVEL 3
|
||||||
|
|
||||||
|
struct source_info {
|
||||||
|
const char * source;
|
||||||
|
int line;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
string tag
|
string tag
|
||||||
string userstring
|
string userstring
|
||||||
thread co (default nil)
|
thread co (default nil)
|
||||||
integer level (default is 3)
|
integer level
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ltrace(lua_State *L) {
|
ltrace(lua_State *L) {
|
||||||
@@ -420,15 +427,41 @@ ltrace(lua_State *L) {
|
|||||||
const char * user = luaL_checkstring(L, 2);
|
const char * user = luaL_checkstring(L, 2);
|
||||||
if (lua_isthread(L, 3)) {
|
if (lua_isthread(L, 3)) {
|
||||||
lua_State * co = lua_tothread (L, 3);
|
lua_State * co = lua_tothread (L, 3);
|
||||||
|
struct source_info si[MAX_LEVEL];
|
||||||
lua_Debug d;
|
lua_Debug d;
|
||||||
int level = luaL_optinteger(L, 4, 3);
|
int level = luaL_checkinteger(L, 4);
|
||||||
|
int index = 0;
|
||||||
do {
|
do {
|
||||||
if (!lua_getstack(co, level, &d))
|
if (!lua_getstack(co, level, &d))
|
||||||
break;
|
break;
|
||||||
lua_getinfo(co, "Sl", &d);
|
lua_getinfo(co, "Sl", &d);
|
||||||
level++;
|
level++;
|
||||||
} while (d.currentline < 0);
|
si[index].source = d.source;
|
||||||
skynet_error(context, "<TRACE %s> %" PRId64 " %s : %s:%d", tag, get_time(), user, d.short_src, d.currentline);
|
si[index].line = d.currentline;
|
||||||
|
if (d.currentline >= 0)
|
||||||
|
++index;
|
||||||
|
} while (index < MAX_LEVEL);
|
||||||
|
switch (index) {
|
||||||
|
case 1:
|
||||||
|
skynet_error(context, "<TRACE %s> %" PRId64 " %s : %s:%d", tag, get_time(), user, si[0].source, si[0].line);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
skynet_error(context, "<TRACE %s> %" PRId64 " %s : %s:%d %s:%d", tag, get_time(), user,
|
||||||
|
si[0].source, si[0].line,
|
||||||
|
si[1].source, si[1].line
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
skynet_error(context, "<TRACE %s> %" PRId64 " %s : %s:%d %s:%d %s:%d", tag, get_time(), user,
|
||||||
|
si[0].source, si[0].line,
|
||||||
|
si[1].source, si[1].line,
|
||||||
|
si[2].source, si[2].line
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
skynet_error(context, "<TRACE %s> %" PRId64 " %s", tag, get_time(), user);
|
||||||
|
break;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
skynet_error(context, "<TRACE %s> %" PRId64 " %s", tag, get_time(), user);
|
skynet_error(context, "<TRACE %s> %" PRId64 " %s", tag, get_time(), user);
|
||||||
|
|||||||
@@ -153,14 +153,14 @@ end
|
|||||||
|
|
||||||
-- suspend is local function
|
-- suspend is local function
|
||||||
function suspend(co, result, command, param, param2)
|
function suspend(co, result, command, param, param2)
|
||||||
local tag = session_coroutine_tracetag[co]
|
|
||||||
if not result then
|
if not result then
|
||||||
local session = session_coroutine_id[co]
|
local session = session_coroutine_id[co]
|
||||||
if session then -- coroutine may fork by others (session is nil)
|
if session then -- coroutine may fork by others (session is nil)
|
||||||
local addr = session_coroutine_address[co]
|
local addr = session_coroutine_address[co]
|
||||||
if session ~= 0 then
|
if session ~= 0 then
|
||||||
-- only call response error
|
-- only call response error
|
||||||
if tag then c.trace(tag, "error", co) end
|
local tag = session_coroutine_tracetag[co]
|
||||||
|
if tag then c.trace(tag, "error") end
|
||||||
c.send(addr, skynet.PTYPE_ERROR, session, "")
|
c.send(addr, skynet.PTYPE_ERROR, session, "")
|
||||||
end
|
end
|
||||||
session_coroutine_id[co] = nil
|
session_coroutine_id[co] = nil
|
||||||
@@ -169,20 +169,25 @@ function suspend(co, result, command, param, param2)
|
|||||||
end
|
end
|
||||||
error(debug.traceback(co,tostring(command)))
|
error(debug.traceback(co,tostring(command)))
|
||||||
end
|
end
|
||||||
if command == "CALL" then
|
if command == "CALLTRACE" then
|
||||||
|
local tag = session_coroutine_tracetag[co]
|
||||||
if tag then
|
if tag then
|
||||||
c.trace(tag, "call", co)
|
c.trace(tag, "call", co, 2)
|
||||||
c.send(param2, skynet.PTYPE_TRACE, 0, tag)
|
c.send(param, skynet.PTYPE_TRACE, 0, tag)
|
||||||
end
|
end
|
||||||
|
return suspend(co, coroutine_resume(co))
|
||||||
|
elseif command == "CALL" then
|
||||||
session_id_coroutine[param] = co
|
session_id_coroutine[param] = co
|
||||||
elseif command == "SLEEP" then
|
elseif command == "SLEEP" then
|
||||||
if tag then c.trace(tag, "sleep", co) end
|
local tag = session_coroutine_tracetag[co]
|
||||||
|
if tag then c.trace(tag, "sleep", co, 2) end
|
||||||
session_id_coroutine[param] = co
|
session_id_coroutine[param] = co
|
||||||
if sleep_session[param2] then
|
if sleep_session[param2] then
|
||||||
error(debug.traceback(co, "token duplicative"))
|
error(debug.traceback(co, "token duplicative"))
|
||||||
end
|
end
|
||||||
sleep_session[param2] = param
|
sleep_session[param2] = param
|
||||||
elseif command == "RETURN" then
|
elseif command == "RETURN" then
|
||||||
|
local tag = session_coroutine_tracetag[co]
|
||||||
if tag then c.trace(tag, "response") end
|
if tag then c.trace(tag, "response") end
|
||||||
local co_session = session_coroutine_id[co]
|
local co_session = session_coroutine_id[co]
|
||||||
session_coroutine_id[co] = nil
|
session_coroutine_id[co] = nil
|
||||||
@@ -416,7 +421,7 @@ skynet.trash = assert(c.trash)
|
|||||||
|
|
||||||
local function yield_call(service, session)
|
local function yield_call(service, session)
|
||||||
watching_session[session] = service
|
watching_session[session] = service
|
||||||
local succ, msg, sz = coroutine_yield("CALL", session, service)
|
local succ, msg, sz = coroutine_yield("CALL", session)
|
||||||
watching_session[session] = nil
|
watching_session[session] = nil
|
||||||
if not succ then
|
if not succ then
|
||||||
error "call failed"
|
error "call failed"
|
||||||
@@ -425,6 +430,7 @@ local function yield_call(service, session)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.call(addr, typename, ...)
|
function skynet.call(addr, typename, ...)
|
||||||
|
coroutine_yield("CALLTRACE", addr)
|
||||||
local p = proto[typename]
|
local p = proto[typename]
|
||||||
local session = c.send(addr, p.id , nil , p.pack(...))
|
local session = c.send(addr, p.id , nil , p.pack(...))
|
||||||
if session == nil then
|
if session == nil then
|
||||||
@@ -434,6 +440,7 @@ function skynet.call(addr, typename, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.rawcall(addr, typename, msg, sz)
|
function skynet.rawcall(addr, typename, msg, sz)
|
||||||
|
coroutine_yield("CALLTRACE", addr)
|
||||||
local p = proto[typename]
|
local p = proto[typename]
|
||||||
local session = assert(c.send(addr, p.id , nil , msg, sz), "call to invalid address")
|
local session = assert(c.send(addr, p.id , nil , msg, sz), "call to invalid address")
|
||||||
return yield_call(addr, session)
|
return yield_call(addr, session)
|
||||||
@@ -525,12 +532,8 @@ local function raw_dispatch_message(prototype, msg, sz, session, source)
|
|||||||
else
|
else
|
||||||
local tag = trace_source[source]
|
local tag = trace_source[source]
|
||||||
if tag then
|
if tag then
|
||||||
if session ~= 0 then
|
c.trace(tag, "request")
|
||||||
c.trace(tag, "request")
|
trace_source[source] = nil
|
||||||
trace_source[source] = nil
|
|
||||||
else
|
|
||||||
tag = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local p = proto[prototype]
|
local p = proto[prototype]
|
||||||
if p == nil then
|
if p == nil then
|
||||||
|
|||||||
Reference in New Issue
Block a user